Methods
Public Instance
Included modules
Constants
ERROR_MAP | = | {} | ||
NullHandle | = | DB2CLI.SQLAllocHandle(DB2CLI::SQL_HANDLE_ENV, DB2CLI::SQL_NULL_HANDLE) | ||
TEMPORARY | = | 'GLOBAL TEMPORARY '.freeze |
Attributes
conversion_procs | [R] |
Hash of connection procs for converting |
Public Instance methods
check_error
(rc, msg)
[show source]
# File lib/sequel/adapters/db2.rb, line 85 def check_error(rc, msg) case rc when DB2CLI::SQL_SUCCESS, DB2CLI::SQL_SUCCESS_WITH_INFO, DB2CLI::SQL_NO_DATA_FOUND nil when DB2CLI::SQL_INVALID_HANDLE, DB2CLI::SQL_STILL_EXECUTING e = DB2Error.new("#{ERROR_MAP[rc]}: #{msg}") e.set_backtrace(caller) raise_error(e, :disconnect=>true) else e = DB2Error.new("#{ERROR_MAP[rc] || "Error code #{rc}"}: #{msg}") e.set_backtrace(caller) raise_error(e, :disconnect=>true) end end
checked_error
(msg)
[show source]
# File lib/sequel/adapters/db2.rb, line 100 def checked_error(msg) rc, *ary= yield check_error(rc, msg) ary.length <= 1 ? ary.first : ary end
connect
(server)
[show source]
# File lib/sequel/adapters/db2.rb, line 47 def connect(server) opts = server_opts(server) dbc = checked_error("Could not allocate database connection"){DB2CLI.SQLAllocHandle(DB2CLI::SQL_HANDLE_DBC, NullHandle)} checked_error("Could not connect to database"){DB2CLI.SQLConnect(dbc, opts[:database], opts[:user], opts[:password])} dbc end
disconnect_connection
(conn)
[show source]
# File lib/sequel/adapters/db2.rb, line 54 def disconnect_connection(conn) DB2CLI.SQLDisconnect(conn) DB2CLI.SQLFreeHandle(DB2CLI::SQL_HANDLE_DBC, conn) end
execute
(sql, opts=OPTS, &block)
[show source]
# File lib/sequel/adapters/db2.rb, line 59 def execute(sql, opts=OPTS, &block) synchronize(opts[:server]){|conn| log_connection_execute(conn, sql, &block)} end
execute_insert
(sql, opts=OPTS)
[show source]
# File lib/sequel/adapters/db2.rb, line 63 def execute_insert(sql, opts=OPTS) synchronize(opts[:server]) do |conn| log_connection_execute(conn, sql) sql = "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1" log_connection_execute(conn, sql) do |sth| name, buflen, datatype, size, digits, nullable = checked_error("Could not describe column"){DB2CLI.SQLDescribeCol(sth, 1, 256)} if DB2CLI.SQLFetch(sth) != DB2CLI::SQL_NO_DATA_FOUND v, _ = checked_error("Could not get data"){DB2CLI.SQLGetData(sth, 1, datatype, size)} if v.is_a?(String) return v.to_i else return nil end end end end end
to_application_timestamp_db2
(v)
[show source]
# File lib/sequel/adapters/db2.rb, line 106 def to_application_timestamp_db2(v) to_application_timestamp(v.to_s) end