class Sequel::IBMDB::Database

  1. lib/sequel/adapters/ibmdb.rb
Superclass: Sequel::Database

Included modules

  1. Sequel::DB2::DatabaseMethods

Attributes

conversion_procs [R]

Hash of connection procs for converting

convert_smallint_to_bool [RW]

Whether to convert smallint values to bool for this Database instance

Public Instance methods

connect(server)

Create a new connection object for the given server.

[show source]
    # File lib/sequel/adapters/ibmdb.rb
188 def connect(server)
189   opts = server_opts(server)
190 
191   connection_params = if opts[:host].nil? && opts[:port].nil? && opts[:database]
192     # use a cataloged connection
193     opts.values_at(:database, :user, :password)
194   else
195     # use uncataloged connection so that host and port can be supported
196     'Driver={IBM DB2 ODBC DRIVER};' \
197     "Database=#{opts[:database]};" \
198     "Hostname=#{opts[:host]};" \
199     "Port=#{opts[:port] || 50000};" \
200     'Protocol=TCPIP;' \
201     "Uid=#{opts[:user]};" \
202     "Pwd=#{opts[:password]};" \
203   end 
204 
205   Connection.new(connection_params)
206 end
execute(sql, opts=OPTS, &block)
[show source]
    # File lib/sequel/adapters/ibmdb.rb
208 def execute(sql, opts=OPTS, &block)
209   if sql.is_a?(Symbol)
210     execute_prepared_statement(sql, opts, &block)
211   else
212     synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)}
213   end
214 rescue Connection::Error => e
215   raise_error(e)
216 end
execute_insert(sql, opts=OPTS)
[show source]
    # File lib/sequel/adapters/ibmdb.rb
218 def execute_insert(sql, opts=OPTS)
219   synchronize(opts[:server]) do |c|
220     if sql.is_a?(Symbol)
221       execute_prepared_statement(sql, opts)
222     else
223       _execute(c, sql, opts)
224     end
225     _execute(c, "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1", opts){|stmt| i = stmt.fetch_array.first.to_i; i}
226   end
227 rescue Connection::Error => e
228   raise_error(e)
229 end
execute_prepared_statement(ps_name, opts)

Execute a prepared statement named by name on the database.

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