Wraps an underlying connection to DB2
using IBM_DB, to provide a more rubyish API.
Methods
Public Class
Public Instance
Classes and Modules
Attributes
prepared_statements | [R] |
A hash with prepared statement name symbol keys, where each value is a two element array with an sql string and cached |
Public Class methods
Create the underlying IBM_DB connection.
# File lib/sequel/adapters/ibmdb.rb 41 def initialize(connection_param) 42 @conn = if connection_param.class == String 43 IBM_DB.connect(connection_param, '', '') 44 else # connect using catalog 45 IBM_DB.connect(*connection_param) 46 end 47 48 self.autocommit = true 49 @prepared_statements = {} 50 end
Public Instance methods
Check whether the connection is in autocommit state or not.
# File lib/sequel/adapters/ibmdb.rb 53 def autocommit 54 IBM_DB.autocommit(@conn) == 1 55 end
Turn autocommit on or off for the connection.
# File lib/sequel/adapters/ibmdb.rb 58 def autocommit=(value) 59 IBM_DB.autocommit(@conn, value ? IBM_DB::SQL_AUTOCOMMIT_ON : IBM_DB::SQL_AUTOCOMMIT_OFF) 60 end
Close the connection, disconnecting from DB2
.
# File lib/sequel/adapters/ibmdb.rb 63 def close 64 IBM_DB.close(@conn) 65 end
Commit the currently outstanding transaction on this connection.
# File lib/sequel/adapters/ibmdb.rb 68 def commit 69 IBM_DB.commit(@conn) 70 end
Return the related error message for the connection.
# File lib/sequel/adapters/ibmdb.rb 73 def error_msg 74 IBM_DB.getErrormsg(@conn, IBM_DB::DB_CONN) 75 end
Return the related error message for the connection.
# File lib/sequel/adapters/ibmdb.rb 78 def error_sqlstate 79 IBM_DB.getErrorstate(@conn, IBM_DB::DB_CONN) 80 end
Execute the given SQL on the database, and return a Statement
instance holding the results.
# File lib/sequel/adapters/ibmdb.rb 84 def execute(sql) 85 stmt = IBM_DB.exec(@conn, sql) 86 raise Error.new(error_msg, error_sqlstate) unless stmt 87 Statement.new(stmt) 88 end
Execute the related prepared statement on the database with the given arguments.
# File lib/sequel/adapters/ibmdb.rb 92 def execute_prepared(ps_name, *values) 93 stmt = @prepared_statements[ps_name].last 94 res = stmt.execute(*values) 95 unless res 96 raise Error.new("Error executing statement #{ps_name}: #{error_msg}", error_sqlstate) 97 end 98 stmt 99 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 103 def prepare(sql, ps_name) 104 if stmt = IBM_DB.prepare(@conn, sql) 105 ps_name = ps_name.to_sym 106 stmt = Statement.new(stmt) 107 @prepared_statements[ps_name] = [sql, stmt] 108 else 109 err = error_msg 110 err = "Error preparing #{ps_name} with SQL: #{sql}" if error_msg.nil? || error_msg.empty? 111 raise Error.new(err, error_sqlstate) 112 end 113 end
Rollback the currently outstanding transaction on this connection.
# File lib/sequel/adapters/ibmdb.rb 116 def rollback 117 IBM_DB.rollback(@conn) 118 end