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

Create a new connection object for the given server.

[Source]

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

Execute the given SQL on the database.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 213
213:       def execute(sql, opts=OPTS, &block)
214:         if sql.is_a?(Symbol)
215:           execute_prepared_statement(sql, opts, &block)
216:         else
217:           synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)}
218:         end
219:       rescue Connection::Error => e
220:         raise_error(e)
221:       end

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

[Source]

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

Execute a prepared statement named by name on the database.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 239
239:       def execute_prepared_statement(ps_name, opts)
240:         args = opts[:arguments]
241:         ps = prepared_statement(ps_name)
242:         sql = ps.prepared_sql
243:         synchronize(opts[:server]) do |conn|
244:           unless conn.prepared_statements.fetch(ps_name, []).first == sql
245:             log_connection_yield("PREPARE #{ps_name}: #{sql}", conn){conn.prepare(sql, ps_name)}
246:           end
247:           args = args.map{|v| v.nil? ? nil : prepared_statement_arg(v)}
248:           log_sql = "EXECUTE #{ps_name}"
249:           if ps.log_sql
250:             log_sql += " ("
251:             log_sql << sql
252:             log_sql << ")"
253:           end
254:           begin
255:             stmt = log_connection_yield(log_sql, conn, args){conn.execute_prepared(ps_name, *args)}
256:             if block_given?
257:               yield(stmt)
258:             else  
259:               stmt.affected
260:             end
261:           ensure
262:             stmt.free_result if stmt
263:           end
264:         end
265:       end

[Validate]