Class: Sequel::DB2::Dataset
- Inherits:
-
Sequel::Dataset
- Object
- Sequel::Dataset
- Sequel::DB2::Dataset
- Defined in:
- lib/sequel/adapters/db2.rb
Constant Summary collapse
- MAX_COL_SIZE =
256
Constants inherited from Sequel::Dataset
Sequel::Dataset::NOTIMPL_MSG, Sequel::Dataset::STOCK_TRANSFORMS
Constants included from Sequel::Dataset::Convenience
Sequel::Dataset::Convenience::COMMA_SEPARATOR, Sequel::Dataset::Convenience::MAGIC_METHODS, Sequel::Dataset::Convenience::MUTATION_RE, Sequel::Dataset::Convenience::NAKED_HASH
Constants included from Sequel::Dataset::SQL
Sequel::Dataset::SQL::ALIASED_REGEXP, Sequel::Dataset::SQL::AND_SEPARATOR, Sequel::Dataset::SQL::COMMA_SEPARATOR, Sequel::Dataset::SQL::DATE_FORMAT, Sequel::Dataset::SQL::FALSE, Sequel::Dataset::SQL::JOIN_TYPES, Sequel::Dataset::SQL::NULL, Sequel::Dataset::SQL::QUALIFIED_REGEXP, Sequel::Dataset::SQL::QUESTION_MARK, Sequel::Dataset::SQL::STOCK_COUNT_OPTS, Sequel::Dataset::SQL::TIMESTAMP_FORMAT, Sequel::Dataset::SQL::TRUE, Sequel::Dataset::SQL::WILDCARD
Constants included from Sequel::Dataset::Sequelizer
Sequel::Dataset::Sequelizer::JOIN_AND, Sequel::Dataset::Sequelizer::JOIN_COMMA
Instance Attribute Summary
Attributes inherited from Sequel::Dataset
Attributes included from Sequel::Dataset::Convenience
#current_page, #page_count, #page_size, #pagination_record_count
Instance Method Summary collapse
- #convert_type(v) ⇒ Object
- #delete(opts = nil) ⇒ Object
- #fetch_rows(sql, &block) ⇒ Object
- #get_column_info(sth) ⇒ Object
- #hash_row(sth) ⇒ Object
- #insert(*values) ⇒ Object
- #literal(v) ⇒ Object
- #update(*args, &block) ⇒ Object
Methods inherited from Sequel::Dataset
#<<, #clone_merge, #columns, dataset_classes, #each, #extend_with_destroy, inherited, #initialize, #model_classes, #naked, #polymorphic_key, #remove_row_proc, #set, #set_model, #set_options, #set_row_proc, #transform, #transform_load, #transform_save, #update_each_method
Methods included from Sequel::Dataset::Convenience
#[], #[]=, #avg, #create_or_replace_view, #create_view, #current_page_record_count, #current_page_record_range, #each_hash, #empty?, #first, #group_and_count, #interval, #last, #magic_method_missing, #map, #max, #method_missing, #min, #multi_insert, #next_page, #page_range, #paginate, #prev_page, #print, #query, #range, #set_pagination_info, #single_record, #single_value, #sum, #to_csv, #to_hash
Methods included from Sequel::Dataset::SQL
#and, #column_list, #count, #delete_sql, #except, #exclude, #exists, #expression_list, #filter, #from, #full_outer_join, #group, #having, #inner_join, #insert_multiple, #insert_sql, #intersect, #invert_order, #join_expr, #join_table, #left_outer_join, #limit, #or, #order, #qualified_column_name, #quote_column_ref, #reverse_order, #right_outer_join, #select, #select_sql, #source_list, #to_table_reference, #union, #uniq, #update_sql, #where
Methods included from Sequel::Dataset::Sequelizer
#call_expr, #compare_expr, #eval_expr, #ext_expr, #fcall_expr, #iter_expr, #match_expr, #proc_to_sql, #pt_expr, #replace_dvars, #unfold_each_expr, #value_to_parse_tree, #vcall_expr
Methods included from Enumerable
Constructor Details
This class inherits a constructor from Sequel::Dataset
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sequel::Dataset::Convenience
Instance Method Details
#convert_type(v) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/sequel/adapters/db2.rb', line 129 def convert_type(v) case v when DB2CLI::Date DBI::Date.new(v.year, v.month, v.day) when DB2CLI::Time DBI::Time.new(v.hour, v.minute, v.second) when DB2CLI::Timestamp DBI::Timestamp.new(v.year, v.month, v.day, v.hour, v.minute, v.second, v.fraction) when DB2CLI::Null nil else v end end |
#delete(opts = nil) ⇒ Object
153 154 155 |
# File 'lib/sequel/adapters/db2.rb', line 153 def delete(opts = nil) @db.do delete_sql(opts) end |
#fetch_rows(sql, &block) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sequel/adapters/db2.rb', line 90 def fetch_rows(sql, &block) @db.synchronize do @db.execute(sql) do |sth| @column_info = get_column_info(sth) @columns = @column_info.map {|c| c[:name]} while (rc = SQLFetch(@handle)) != SQL_NO_DATA_FOUND @db.check_error(rc, "Could not fetch row") yield hash_row(sth) end end end self end |
#get_column_info(sth) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sequel/adapters/db2.rb', line 106 def get_column_info(sth) rc, column_count = SQLNumResultCols(sth) @db.check_error(rc, "Could not get number of result columns") (1..column_count).map do |i| rc, name, buflen, datatype, size, digits, nullable = SQLDescribeCol(sth, i, MAX_COL_SIZE) @b.check_error(rc, "Could not describe column") {:name => name, :db2_type => datatype, :precision => size} end end |
#hash_row(sth) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/sequel/adapters/db2.rb', line 118 def hash_row(sth) row = {} @column_info.each_with_index do |c, i| rc, v = SQLGetData(sth, i+1, c[:db2_type], c[:precision]) @db.check_error(rc, "Could not get data") @row[c[:name]] = convert_type(v) end row end |
#insert(*values) ⇒ Object
145 146 147 |
# File 'lib/sequel/adapters/db2.rb', line 145 def insert(*values) @db.do insert_sql(*values) end |
#literal(v) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/sequel/adapters/db2.rb', line 81 def literal(v) case v when Time literal(v.iso8601) else super end end |
#update(*args, &block) ⇒ Object
149 150 151 |
# File 'lib/sequel/adapters/db2.rb', line 149 def update(*args, &block) @db.do update_sql(*args, &block) end |