Class Sequel::IBMDB::Database
In: lib/sequel/adapters/ibmdb.rb
Parent: Sequel::Database

Methods

Included Modules

Sequel::DB2::DatabaseMethods

Attributes

conversion_procs  [R]  Hash of connection procs for converting

Public Instance methods

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.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 192
192:       def alter_table(name, generator=nil)
193:         res = super
194:         reorg(name)
195:         res
196:       end

Create a new connection object for the given server.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 199
199:       def connect(server)
200:         opts = server_opts(server)
201: 
202:         connection_params = if opts[:host].nil? && opts[:port].nil? && opts[:database]
203:           # use a cataloged connection
204:           opts.values_at(:database, :user, :password)
205:         else
206:           # use uncataloged connection so that host and port can be supported
207:           'Driver={IBM DB2 ODBC DRIVER};' \
208:           "Database=#{opts[:database]};" \
209:           "Hostname=#{opts[:host]};" \
210:           "Port=#{opts[:port] || 50000};" \
211:           'Protocol=TCPIP;' \
212:           "Uid=#{opts[:user]};" \
213:           "Pwd=#{opts[:password]};" \
214:         end 
215: 
216:         Connection.new(connection_params)
217:       end

Execute the given SQL on the database.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 220
220:       def execute(sql, opts=OPTS, &block)
221:         if sql.is_a?(Symbol)
222:           execute_prepared_statement(sql, opts, &block)
223:         else
224:           synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)}
225:         end
226:       rescue Connection::Error => e
227:         raise_error(e)
228:       end

Execute the given SQL on the database, returning the last inserted identity value.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 232
232:       def execute_insert(sql, opts=OPTS)
233:         synchronize(opts[:server]) do |c|
234:           if sql.is_a?(Symbol)
235:             execute_prepared_statement(sql, opts)
236:           else
237:             _execute(c, sql, opts)
238:           end
239:           _execute(c, "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1", opts){|stmt| i = stmt.fetch_array.first.to_i; i}
240:         end
241:       rescue Connection::Error => e
242:         raise_error(e)
243:       end

Execute a prepared statement named by name on the database.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 246
246:       def execute_prepared_statement(ps_name, opts)
247:         args = opts[:arguments]
248:         ps = prepared_statement(ps_name)
249:         sql = ps.prepared_sql
250:         synchronize(opts[:server]) do |conn|
251:           unless conn.prepared_statements.fetch(ps_name, []).first == sql
252:             log_yield("PREPARE #{ps_name}: #{sql}"){conn.prepare(sql, ps_name)}
253:           end
254:           args = args.map{|v| v.nil? ? nil : prepared_statement_arg(v)}
255:           log_sql = "EXECUTE #{ps_name}"
256:           if ps.log_sql
257:             log_sql << " ("
258:             log_sql << sql
259:             log_sql << ")"
260:           end
261:           begin
262:             stmt = log_yield(log_sql, args){conn.execute_prepared(ps_name, *args)}
263:             if block_given?
264:               yield(stmt)
265:             else  
266:               stmt.affected
267:             end
268:           ensure
269:             stmt.free_result if stmt
270:           end
271:         end
272:       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.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 277
277:       def table_exists?(name)
278:         v ||= false # only retry once
279:         sch, table_name = schema_and_table(name)
280:         name = SQL::QualifiedIdentifier.new(sch, table_name) if sch
281:         from(name).first
282:         true
283:       rescue DatabaseError => e
284:         if e.to_s =~ /Operation not allowed for reason code "7" on table/ && v == false
285:           # table probably needs reorg
286:           reorg(name)
287:           v = true
288:           retry 
289:         end
290:         false
291:       end

[Validate]