class Sequel::JDBC::Dataset
def convert_type_proc(v)
class to a ruby object. If no callable object can handle v's
Return a callable object that will convert any value of v's
def convert_type_proc(v) case v when JAVA_BIG_DECIMAL DECIMAL_METHOD when JAVA_SQL_TIMESTAMP method(:convert_type_timestamp) when JAVA_SQL_TIME TIME_METHOD when JAVA_SQL_DATE DATE_METHOD when JAVA_BUFFERED_READER BUFFERED_READER_METHOD when JAVA_BYTE_ARRAY BYTE_ARRAY_METHOD when JAVA_SQL_BLOB BLOB_METHOD when JAVA_SQL_CLOB CLOB_METHOD else false end end
def convert_type_timestamp(v)
def convert_type_timestamp(v) db.to_application_timestamp([v.getYear + 1900, v.getMonth + 1, v.getDate, v.getHours, v.getMinutes, v.getSeconds, v.getNanos]) end
def fetch_rows(sql, &block)
def fetch_rows(sql, &block) execute(sql){|result| process_result_set(result, &block)} self end
def prepare(type, name=nil, *values)
Create a named prepared statement that is stored in the
def prepare(type, name=nil, *values) ps = to_prepared_statement(type, values) ps.extend(PreparedStatementMethods) if name ps.prepared_statement_name = name db.prepared_statements[name] = ps end ps end
def prepare_extend_sproc(ds)
def prepare_extend_sproc(ds) ds.extend(StoredProcedureMethods) end
def process_result_set(result, &block)
Split out from fetch rows to allow processing of JDBC result sets
def process_result_set(result, &block) # get column names meta = result.getMetaData cols = [] i = 0 meta.getColumnCount.times{cols << [output_identifier(meta.getColumnLabel(i+=1)), i]} columns = cols.map{|c| c.at(0)} if opts[:offset] && offset_returns_row_number_column? rn = row_number_column columns.delete(rn) end @columns = columns ct = @convert_types if (ct.nil? ? db.convert_types : ct) cols.each{|c| c << nil} process_result_set_convert(cols, result, rn, &block) else process_result_set_no_convert(cols, result, rn, &block) end ensure result.close end
def process_result_set_convert(cols, result, rn)
later processing. If the conversion proc exists, call it
the result of as the column's conversion proc to speed up
call convert_type_proc to get the conversion method. Cache
* if a conversion proc hasn't been looked up yet (nil value),
exist (false value), return object.
* if a conversion proc has already been looked up and doesn't
and return the result.
* if a conversion proc is not false/nil, call it with the object
the column when parsing the column metadata.
since unlike other adapters, Sequel doesn't get the type of
the column. All columns start with a nil conversion proc,
* otherwise, see if a conversion method exists for
* if not truthy, return object
* check if the value is truthy (not false/nil)
is roughly, for each column value in each row:
from the database. This has been optimized, the algorithm it uses
Use conversion procs to convert data retrieved
def process_result_set_convert(cols, result, rn) while result.next row = {} cols.each do |n, i, p| v = result.getObject(i) row[n] = if v if p p.call(v) elsif p.nil? cols[i-1][2] = p = convert_type_proc(v) if p p.call(v) else v end else v end else v end end row.delete(rn) if rn yield row end end
def process_result_set_no_convert(cols, result, rn)
Yield rows without calling any conversion procs. This
def process_result_set_no_convert(cols, result, rn) while result.next row = {} cols.each{|n, i| row[n] = result.getObject(i)} row.delete(rn) if rn yield row end end