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 47
47:       def initialize(connection_string)
48:         @conn = IBM_DB.connect(connection_string, '', '')
49:         self.autocommit = true
50:         @prepared_statements = {}
51:       end

Public Instance methods

Check whether the connection is in autocommit state or not.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 54
54:       def autocommit
55:         IBM_DB.autocommit(@conn) == 1
56:       end

Turn autocommit on or off for the connection.

[Source]

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

Close the connection, disconnecting from DB2.

[Source]

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

Commit the currently outstanding transaction on this connection.

[Source]

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

Return the related error message for the connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 74
74:       def error_msg
75:         IBM_DB.getErrormsg(@conn, IBM_DB::DB_CONN)
76:       end

Return the related error message for the connection.

[Source]

    # File lib/sequel/adapters/ibmdb.rb, line 79
79:       def error_sqlstate
80:         IBM_DB.getErrorstate(@conn, IBM_DB::DB_CONN)
81:       end

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

[Source]

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

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

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 93
 93:       def execute_prepared(ps_name, *values)
 94:         stmt = @prepared_statements[ps_name].last
 95:         res = stmt.execute(*values)
 96:         unless res
 97:           raise Error.new("Error executing statement #{ps_name}: #{error_msg}", error_sqlstate)
 98:         end
 99:         stmt
100:       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 104
104:       def prepare(sql, ps_name)
105:         if stmt = IBM_DB.prepare(@conn, sql)
106:           ps_name = ps_name.to_sym
107:           stmt = Statement.new(stmt)
108:           @prepared_statements[ps_name] = [sql, stmt]
109:         else
110:           err = error_msg
111:           err = "Error preparing #{ps_name} with SQL: #{sql}" if error_msg.nil? || error_msg.empty?
112:           raise Error.new(err, error_sqlstate)
113:         end
114:       end

Rollback the currently outstanding transaction on this connection.

[Source]

     # File lib/sequel/adapters/ibmdb.rb, line 117
117:       def rollback
118:         IBM_DB.rollback(@conn)
119:       end

[Validate]