Wraps an underlying connection to DB2 using IBM_DB.
A hash with prepared statement name symbol keys, where each value is a two element array with an sql string and cached Statement value.
Create the underlying IBM_DB connection.
# File lib/sequel/adapters/ibmdb.rb, line 41 def initialize(connection_string) @conn = IBM_DB.connect(connection_string, '', '') self.autocommit = true @prepared_statements = {} end
Check whether the connection is in autocommit state or not.
# File lib/sequel/adapters/ibmdb.rb, line 48 def autocommit IBM_DB.autocommit(@conn) == 1 end
Turn autocommit on or off for the connection.
# File lib/sequel/adapters/ibmdb.rb, line 53 def autocommit=(value) IBM_DB.autocommit(@conn, value ? IBM_DB::SQL_AUTOCOMMIT_ON : IBM_DB::SQL_AUTOCOMMIT_OFF) end
Close the connection, disconnecting from DB2.
# File lib/sequel/adapters/ibmdb.rb, line 58 def close IBM_DB.close(@conn) end
Commit the currently outstanding transaction on this connection.
# File lib/sequel/adapters/ibmdb.rb, line 63 def commit IBM_DB.commit(@conn) end
Return the related error message for the connection.
# File lib/sequel/adapters/ibmdb.rb, line 68 def error_msg IBM_DB.getErrormsg(@conn, IBM_DB::DB_CONN) end
Execute the related prepared statement on the database with the given arguments.
# File lib/sequel/adapters/ibmdb.rb, line 82 def execute_prepared(ps_name, *values) stmt = @prepared_statements[ps_name].last res = stmt.execute(*values) unless res raise Error, "Error executing statement #{ps_name}: #{error_msg}" end stmt end
Prepare a statement with the given sql
on the database, and
cache the prepared statement value by name.
# File lib/sequel/adapters/ibmdb.rb, line 93 def prepare(sql, ps_name) if stmt = IBM_DB.prepare(@conn, sql) ps_name = ps_name.to_sym stmt = Statement.new(stmt) @prepared_statements[ps_name] = [sql, stmt] else err = error_msg err = "Error preparing #{ps_name} with SQL: #{sql}" if error_msg.nil? || error_msg.empty? raise Error, err end end
Rollback the currently outstanding transaction on this connection.
# File lib/sequel/adapters/ibmdb.rb, line 106 def rollback IBM_DB.rollback(@conn) end