class Sequel::IBMDB::Connection

  1. lib/sequel/adapters/ibmdb.rb
Parent: IBMDB

Wraps an underlying connection to DB2 using IBM_DB.

Classes and Modules

  1. 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

new (connection_string)

Create the underlying IBM_DB connection.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 47
def initialize(connection_string)
  @conn = IBM_DB.connect(connection_string, '', '')
  self.autocommit = true
  @prepared_statements = {}
end

Public Instance methods

autocommit ()

Check whether the connection is in autocommit state or not.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 54
def autocommit
  IBM_DB.autocommit(@conn) == 1
end
autocommit= (value)

Turn autocommit on or off for the connection.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 59
def autocommit=(value)
  IBM_DB.autocommit(@conn, value ? IBM_DB::SQL_AUTOCOMMIT_ON : IBM_DB::SQL_AUTOCOMMIT_OFF)
end
close ()

Close the connection, disconnecting from DB2.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 64
def close
  IBM_DB.close(@conn)
end
commit ()

Commit the currently outstanding transaction on this connection.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 69
def commit
  IBM_DB.commit(@conn)
end
error_msg ()

Return the related error message for the connection.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 74
def error_msg
  IBM_DB.getErrormsg(@conn, IBM_DB::DB_CONN)
end
error_sqlstate ()

Return the related error message for the connection.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 79
def error_sqlstate
  IBM_DB.getErrorstate(@conn, IBM_DB::DB_CONN)
end
execute (sql)

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

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 85
def execute(sql)
  stmt = IBM_DB.exec(@conn, sql)
  raise Error.new(error_msg, error_sqlstate) unless stmt
  Statement.new(stmt)
end
execute_prepared (ps_name, *values)

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

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 93
def execute_prepared(ps_name, *values)
  stmt = @prepared_statements[ps_name].last
  res = stmt.execute(*values)
  unless res
    raise Error.new("Error executing statement #{ps_name}: #{error_msg}", error_sqlstate)
  end
  stmt
end
prepare (sql, ps_name)

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

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 104
def prepare(sql, ps_name)
  if stmt = IBM_DB.prepare(@conn, sql)
    ps_name = ps_name.to_sym
    stmt = Statement.new(stmt)
    @prepared_statements[ps_name] = [sql, stmt]
  else
    err = error_msg
    err = "Error preparing #{ps_name} with SQL: #{sql}" if error_msg.nil? || error_msg.empty?
    raise Error.new(err, error_sqlstate)
  end
end
rollback ()

Rollback the currently outstanding transaction on this connection.

[show source]
# File lib/sequel/adapters/ibmdb.rb, line 117
def rollback
  IBM_DB.rollback(@conn)
end