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

Wraps an underlying connection to DB2 using IBM_DB.

Methods

Classes and Modules

Class Sequel::IBMDB::Connection::Error

Attributes

prepared_statements  [RW]  A hash with prepared statement name symbol keys, where each value is a two element array with an sql string and cached Statement value.

Public Class methods

Create the underlying IBM_DB connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 46
46:       def initialize(connection_param)
47:         @conn = if connection_param.class == String
48:           IBM_DB.connect(connection_param, '', '')
49:         else  # connect using catalog 
50:           IBM_DB.connect(*connection_param)
51:         end
52: 
53:         self.autocommit = true
54:         @prepared_statements = {}
55:       end

Public Instance methods

Check whether the connection is in autocommit state or not.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 58
58:       def autocommit
59:         IBM_DB.autocommit(@conn) == 1
60:       end

Turn autocommit on or off for the connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 63
63:       def autocommit=(value)
64:         IBM_DB.autocommit(@conn, value ? IBM_DB::SQL_AUTOCOMMIT_ON : IBM_DB::SQL_AUTOCOMMIT_OFF)
65:       end

Close the connection, disconnecting from DB2.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 68
68:       def close
69:         IBM_DB.close(@conn)
70:       end

Commit the currently outstanding transaction on this connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 73
73:       def commit
74:         IBM_DB.commit(@conn)
75:       end

Return the related error message for the connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 78
78:       def error_msg
79:         IBM_DB.getErrormsg(@conn, IBM_DB::DB_CONN)
80:       end

Return the related error message for the connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 83
83:       def error_sqlstate
84:         IBM_DB.getErrorstate(@conn, IBM_DB::DB_CONN)
85:       end

Execute the given SQL on the database, and return a Statement instance holding the results.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 89
89:       def execute(sql)
90:         stmt = IBM_DB.exec(@conn, sql)
91:         raise Error.new(error_msg, error_sqlstate) unless stmt
92:         Statement.new(stmt)
93:       end

Execute the related prepared statement on the database with the given arguments.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 97
 97:       def execute_prepared(ps_name, *values)
 98:         stmt = @prepared_statements[ps_name].last
 99:         res = stmt.execute(*values)
100:         unless res
101:           raise Error.new("Error executing statement #{ps_name}: #{error_msg}", error_sqlstate)
102:         end
103:         stmt
104:       end

Prepare a statement with the given sql on the database, and cache the prepared statement value by name.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 108
108:       def prepare(sql, ps_name)
109:         if stmt = IBM_DB.prepare(@conn, sql)
110:           ps_name = ps_name.to_sym
111:           stmt = Statement.new(stmt)
112:           @prepared_statements[ps_name] = [sql, stmt]
113:         else
114:           err = error_msg
115:           err = "Error preparing #{ps_name} with SQL: #{sql}" if error_msg.nil? || error_msg.empty?
116:           raise Error.new(err, error_sqlstate)
117:         end
118:       end

Rollback the currently outstanding transaction on this connection.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 121
121:       def rollback
122:         IBM_DB.rollback(@conn)
123:       end

[Validate]