Class | Sequel::IBMDB::Database |
In: |
lib/sequel/adapters/ibmdb.rb
|
Parent: | Sequel::Database |
conversion_procs | [R] | Hash of connection procs for converting |
# File lib/sequel/adapters/ibmdb.rb, line 168 168: def initialize(opts={}) 169: super 170: @conversion_procs = DB2_TYPES.dup 171: @conversion_procs[:timestamp] = method(:to_application_timestamp) 172: end
REORG the related table whenever it is altered. This is not always required, but it is necessary for compatibilty with other Sequel code in many cases.
# File lib/sequel/adapters/ibmdb.rb, line 177 177: def alter_table(name, generator=nil) 178: res = super 179: reorg(name) 180: res 181: end
Create a new connection object for the given server.
# File lib/sequel/adapters/ibmdb.rb, line 184 184: def connect(server) 185: opts = server_opts(server) 186: 187: # use uncataloged connection so that host and port can be supported 188: connection_string = ( \ 189: 'Driver={IBM DB2 ODBC DRIVER};' \ 190: "Database=#{opts[:database]};" \ 191: "Hostname=#{opts[:host]};" \ 192: "Port=#{opts[:port] || 50000};" \ 193: 'Protocol=TCPIP;' \ 194: "Uid=#{opts[:user]};" \ 195: "Pwd=#{opts[:password]};" \ 196: ) 197: 198: Connection.new(connection_string) 199: end
Execute the given SQL on the database.
# File lib/sequel/adapters/ibmdb.rb, line 202 202: def execute(sql, opts={}, &block) 203: if sql.is_a?(Symbol) 204: execute_prepared_statement(sql, opts, &block) 205: else 206: synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)} 207: end 208: rescue Connection::Error => e 209: raise_error(e) 210: end
Execute the given SQL on the database, returning the last inserted identity value.
# File lib/sequel/adapters/ibmdb.rb, line 214 214: def execute_insert(sql, opts={}) 215: synchronize(opts[:server]) do |c| 216: if sql.is_a?(Symbol) 217: execute_prepared_statement(sql, opts) 218: else 219: _execute(c, sql, opts) 220: end 221: _execute(c, "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1", opts){|stmt| i = stmt.fetch_array.first.to_i; stmt.free; i} 222: end 223: rescue Connection::Error => e 224: raise_error(e) 225: end
Execute a prepared statement named by name on the database.
# File lib/sequel/adapters/ibmdb.rb, line 228 228: def execute_prepared_statement(ps_name, opts) 229: args = opts[:arguments] 230: ps = prepared_statement(ps_name) 231: sql = ps.prepared_sql 232: synchronize(opts[:server]) do |conn| 233: unless conn.prepared_statements.fetch(ps_name, []).first == sql 234: log_yield("PREPARE #{ps_name}: #{sql}"){conn.prepare(sql, ps_name)} 235: end 236: args = args.map{|v| v.nil? ? nil : prepared_statement_arg(v)} 237: log_sql = "EXECUTE #{ps_name}" 238: if ps.log_sql 239: log_sql << " (" 240: log_sql << sql 241: log_sql << ")" 242: end 243: stmt = log_yield(log_sql, args){conn.execute_prepared(ps_name, *args)} 244: if block_given? 245: begin 246: yield(stmt) 247: ensure 248: stmt.free 249: end 250: else 251: stmt.affected 252: end 253: end 254: end
Convert smallint type to boolean if convert_smallint_to_bool is true
# File lib/sequel/adapters/ibmdb.rb, line 257 257: def schema_column_type(db_type) 258: if Sequel::IBMDB.convert_smallint_to_bool && db_type =~ /smallint/i 259: :boolean 260: else 261: super 262: end 263: end
On DB2, a table might need to be REORGed if you are testing existence of it. This REORGs automatically if the database raises a specific error that indicates it should be REORGed.
# File lib/sequel/adapters/ibmdb.rb, line 268 268: def table_exists?(name) 269: v ||= false # only retry once 270: sch, table_name = schema_and_table(name) 271: name = SQL::QualifiedIdentifier.new(sch, table_name) if sch 272: from(name).first 273: true 274: rescue DatabaseError => e 275: if e.to_s =~ /Operation not allowed for reason code "7" on table/ && v == false 276: # table probably needs reorg 277: reorg(name) 278: v = true 279: retry 280: end 281: false 282: end