Included Modules

Class Index [+]

Quicksearch

Sequel::IBMDB::Database

Attributes

conversion_procs[R]

Hash of connection procs for converting

Public Class Methods

new(opts={}) click to toggle source
     # 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

Public Instance Methods

alter_table(name, generator=nil) click to toggle source

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
connect(server) click to toggle source

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 = (              'Driver={IBM DB2 ODBC DRIVER};'              "Database=#{opts[:database]};"              "Hostname=#{opts[:host]};"              "Port=#{opts[:port] || 50000};"              'Protocol=TCPIP;'              "Uid=#{opts[:user]};"              "Pwd=#{opts[:password]};"          )
189: 
190:         Connection.new(connection_string)
191:       end
execute(sql, opts={}, &block) click to toggle source

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_insert(sql, opts={}) click to toggle source

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_prepared_statement(ps_name, opts) click to toggle source

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
schema_column_type(db_type) click to toggle source

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/ 
259:           :boolean
260:         else
261:           super
262:         end
263:       end
table_exists?(name) click to toggle source

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

Private Instance Methods

_execute(conn, sql, opts) click to toggle source

Execute the given SQL on the database.

     # File lib/sequel/adapters/ibmdb.rb, line 287
287:       def _execute(conn, sql, opts)
288:         stmt = log_yield(sql){conn.execute(sql)}
289:         if block_given?
290:           begin
291:             yield(stmt)
292:           ensure
293:             stmt.free
294:           end
295:         else  
296:           stmt.affected
297:         end
298:       end
begin_transaction(conn, opts={}) click to toggle source

IBM_DB uses an autocommit setting instead of sending SQL queries. So starting a transaction just turns autocommit off.

     # File lib/sequel/adapters/ibmdb.rb, line 302
302:       def begin_transaction(conn, opts={})
303:         log_yield(TRANSACTION_BEGIN){conn.autocommit = false}
304:       end
commit_transaction(conn, opts={}) click to toggle source

This commits transaction in progress on the connection and sets autocommit back on.

     # File lib/sequel/adapters/ibmdb.rb, line 308
308:       def commit_transaction(conn, opts={})
309:         log_yield(TRANSACTION_COMMIT){conn.commit}
310:       end
disconnect_connection(conn) click to toggle source

Close the given connection.

     # File lib/sequel/adapters/ibmdb.rb, line 313
313:       def disconnect_connection(conn)
314:         conn.close
315:       end
metadata_dataset() click to toggle source

Don’t convert smallint to boolean for the metadata dataset, since the DB2 metadata does not use boolean columns, and some smallint columns are accidently treated as booleans.

     # File lib/sequel/adapters/ibmdb.rb, line 321
321:       def metadata_dataset
322:         ds = super
323:         ds.convert_smallint_to_bool = false
324:         ds
325:       end
prepared_statement_arg(v) click to toggle source

Format Numeric, Date, and Time types specially for use as IBM_DB prepared statements argument vlaues.

     # File lib/sequel/adapters/ibmdb.rb, line 329
329:       def prepared_statement_arg(v)
330:         case v
331:         when Numeric
332:           v.to_s
333:         when Date, Time
334:           literal(v).gsub("'", '')
335:         else
336:           v
337:         end
338:       end
remove_transaction(conn, committed) click to toggle source

Set autocommit back on

     # File lib/sequel/adapters/ibmdb.rb, line 341
341:       def remove_transaction(conn, committed)
342:         conn.autocommit = true
343:       ensure
344:         super
345:       end
rollback_transaction(conn, opts={}) click to toggle source

This rolls back the transaction in progress on the connection and sets autocommit back on.

     # File lib/sequel/adapters/ibmdb.rb, line 349
349:       def rollback_transaction(conn, opts={})
350:         log_yield(TRANSACTION_ROLLBACK){conn.rollback}
351:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.