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 48
48:       def initialize(connection_param)
49:         @conn = if connection_param.class == String
50:           IBM_DB.connect(connection_param, '', '')
51:         else  # connect using catalog 
52:           IBM_DB.connect(*connection_param)
53:         end
54: 
55:         self.autocommit = true
56:         @prepared_statements = {}
57:       end

Public Instance methods

Check whether the connection is in autocommit state or not.

[Source]

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

Turn autocommit on or off for the connection.

[Source]

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

Close the connection, disconnecting from DB2.

[Source]

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

Commit the currently outstanding transaction on this connection.

[Source]

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

Return the related error message for the connection.

[Source]

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

Return the related error message for the connection.

[Source]

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

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

[Source]

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

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

[Source]

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

Rollback the currently outstanding transaction on this connection.

[Source]

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

[Validate]