Class | Sequel::DB2::Database
In: | lib/sequel/adapters/db2.rb
Parent: | Sequel::Database

### Methods

check_error checked_error connect do execute execute_insert new to_application_timestamp_db2

### Included Modules

DatabaseMethods

### Constants

TEMPORARY | = | 'GLOBAL TEMPORARY '.freeze
NullHandle | = | DB2CLI.SQLAllocHandle(DB2CLI::SQL_HANDLE_ENV, DB2CLI::SQL_NULL_HANDLE)
ERROR_MAP | = | {}

### Attributes

conversion_procs | [R] | Hash of connection procs for converting

### Public Class methods

new(opts={})

[Source]

        # File lib/sequel/adapters/db2.rb, line 47
    47:       def initialize(opts={})
    48:         super
    49:         @conversion_procs = DB2_TYPES.dup
    50:         @conversion_procs[DB2CLI::SQL_TYPE_TIMESTAMP] = method(:to_application_timestamp_db2)
    51:       end

### Public Instance methods

check_error(rc, msg)

[Source]

         # File lib/sequel/adapters/db2.rb, line 87
     87:       def check_error(rc, msg)
     88:         case rc
     89:         when DB2CLI::SQL_SUCCESS, DB2CLI::SQL_SUCCESS_WITH_INFO, DB2CLI::SQL_NO_DATA_FOUND
     90:           nil
     91:         when DB2CLI::SQL_INVALID_HANDLE, DB2CLI::SQL_STILL_EXECUTING
     92:           e = DB2Error.new("#{ERROR_MAP[rc]}: #{msg}")
     93:           e.set_backtrace(caller)
     94:           raise_error(e, :disconnect=>true)
     95:         else
     96:           e = DB2Error.new("#{ERROR_MAP[rc] || "Error code #{rc}"}: #{msg}")
     97:           e.set_backtrace(caller)
     98:           raise_error(e, :disconnect=>true)
     99:         end
    100:       end

checked_error(msg) {|| ...}

[Source]

         # File lib/sequel/adapters/db2.rb, line 102
    102:       def checked_error(msg)
    103:         rc, *ary= yield
    104:         check_error(rc, msg)
    105:         ary.length <= 1 ? ary.first : ary
    106:       end

connect(server)

[Source]

        # File lib/sequel/adapters/db2.rb, line 53
    53:       def connect(server)
    54:         opts = server_opts(server)
    55:         dbc = checked_error("Could not allocate database connection"){DB2CLI.SQLAllocHandle(DB2CLI::SQL_HANDLE_DBC, NullHandle)}
    56:         checked_error("Could not connect to database"){DB2CLI.SQLConnect(dbc, opts[:database], opts[:user], opts[:password])}
    57:         dbc
    58:       end

do(sql, opts={}, &block)

Alias for execute

execute(sql, opts={}, &block)

[Source]

        # File lib/sequel/adapters/db2.rb, line 60
    60:       def execute(sql, opts={}, &block)
    61:         synchronize(opts[:server]){|conn| log_connection_execute(conn, sql, &block)}
    62:       end

execute_insert(sql, opts={})

[Source]

        # File lib/sequel/adapters/db2.rb, line 65
    65:       def execute_insert(sql, opts={})
    66:         synchronize(opts[:server]) do |conn|
    67:           log_connection_execute(conn, sql)
    68:           sql = "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"
    69:           log_connection_execute(conn, sql) do |sth|
    70:             name, buflen, datatype, size, digits, nullable = checked_error("Could not describe column"){DB2CLI.SQLDescribeCol(sth, 1, 256)}
    71:             if DB2CLI.SQLFetch(sth) != DB2CLI::SQL_NO_DATA_FOUND
    72:               v, _ = checked_error("Could not get data"){DB2CLI.SQLGetData(sth, 1, datatype, size)}
    73:               if v.is_a?(String)
    74:                 return v.to_i
    75:               else
    76:                 return nil
    77:               end
    78:             end
    79:           end
    80:         end
    81:       end

to_application_timestamp_db2(v)

[Source]

         # File lib/sequel/adapters/db2.rb, line 108
    108:       def to_application_timestamp_db2(v)
    109:         to_application_timestamp(v.to_s)
    110:       end

[Validate]