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 41
41:       def initialize(connection_string)
42:         @conn = IBM_DB.connect(connection_string, '', '')
43:         self.autocommit = true
44:         @prepared_statements = {}
45:       end

Public Instance methods

Check whether the connection is in autocommit state or not.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 48
48:       def autocommit
49:         IBM_DB.autocommit(@conn) == 1
50:       end

Turn autocommit on or off for the connection.

[Source]

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

Close the connection, disconnecting from DB2.

[Source]

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

Commit the currently outstanding transaction on this connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 63
63:       def commit
64:         IBM_DB.commit(@conn)
65:       end

Return the related error message for the connection.

[Source]

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

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

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 74
74:       def execute(sql)
75:         stmt = IBM_DB.exec(@conn, sql)
76:         raise Error, error_msg unless stmt
77:         Statement.new(stmt)
78:       end

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

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 82
82:       def execute_prepared(ps_name, *values)
83:         stmt = @prepared_statements[ps_name].last
84:         res = stmt.execute(*values)
85:         unless res
86:           raise Error, "Error executing statement #{ps_name}: #{error_msg}"
87:         end
88:         stmt
89:       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 93
 93:       def prepare(sql, ps_name)
 94:         if stmt = IBM_DB.prepare(@conn, sql)
 95:           ps_name = ps_name.to_sym
 96:           stmt = Statement.new(stmt)
 97:           @prepared_statements[ps_name] = [sql, stmt]
 98:         else
 99:           err = error_msg
100:           err = "Error preparing #{ps_name} with SQL: #{sql}" if error_msg.nil? || error_msg.empty?
101:           raise Error, err
102:         end
103:       end

Rollback the currently outstanding transaction on this connection.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 106
106:       def rollback
107:         IBM_DB.rollback(@conn)
108:       end

[Validate]