class Sequel::DB2::Dataset
Constants
- MAX_COL_SIZE
Attributes
convert_smallint_to_bool[W]
Override the default Sequel::DB2.convert_smallint_to_bool setting for this dataset.
Public Instance Methods
convert_smallint_to_bool()
click to toggle source
Whether to convert smallint to boolean arguments for this dataset. Defaults to the DB2 module setting.
# File lib/sequel/adapters/db2.rb, line 173 def convert_smallint_to_bool defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = DB2.convert_smallint_to_bool) end
fetch_rows(sql) { |row| ... }
click to toggle source
# File lib/sequel/adapters/db2.rb, line 180 def fetch_rows(sql) execute(sql) do |sth| db = @db column_info = get_column_info(sth) cols = column_info.map{|c| c.at(1)} @columns = cols errors = [DB2CLI::SQL_NO_DATA_FOUND, DB2CLI::SQL_ERROR] until errors.include?(rc = DB2CLI.SQLFetch(sth)) db.check_error(rc, "Could not fetch row") row = {} column_info.each do |i, c, t, s, pr| v, _ = db.checked_error("Could not get data"){DB2CLI.SQLGetData(sth, i, t, s)} row[c] = if v == DB2CLI::Null nil elsif pr pr.call(v) else v end end yield row end end self end
Private Instance Methods
get_column_info(sth)
click to toggle source
# File lib/sequel/adapters/db2.rb, line 208 def get_column_info(sth) db = @db column_count = db.checked_error("Could not get number of result columns"){DB2CLI.SQLNumResultCols(sth)} convert = convert_smallint_to_bool cps = db.conversion_procs (1..column_count).map do |i| name, _, datatype, size, digits, _ = db.checked_error("Could not describe column"){DB2CLI.SQLDescribeCol(sth, i, MAX_COL_SIZE)} pr = if datatype == DB2CLI::SQL_SMALLINT && convert && size <= 5 && digits <= 1 cps[:boolean] elsif datatype == DB2CLI::SQL_CLOB && Sequel::DB2.use_clob_as_blob cps[DB2CLI::SQL_BLOB] else cps[datatype] end [i, output_identifier(name), datatype, size, pr] end end