/usr/lib/ruby/vendor_ruby/sequel/adapters/cubrid.rb is in ruby-sequel 4.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | require 'cubrid'
Sequel.require 'adapters/shared/cubrid'
module Sequel
module Cubrid
CUBRID_TYPE_PROCS = {
::Cubrid::DATE => lambda{|t| Date.new(t.year, t.month, t.day)},
::Cubrid::TIME => lambda{|t| SQLTime.create(t.hour, t.min, t.sec)},
21 => lambda{|s| s.to_i}
}
class Database < Sequel::Database
include Sequel::Cubrid::DatabaseMethods
ROW_COUNT = "SELECT ROW_COUNT()".freeze
LAST_INSERT_ID = "SELECT LAST_INSERT_ID()".freeze
set_adapter_scheme :cubrid
def connect(server)
opts = server_opts(server)
conn = ::Cubrid.connect(
opts[:database],
opts[:host] || 'localhost',
opts[:port] || 30000,
opts[:user] || 'public',
opts[:password] || ''
)
conn.auto_commit = true
conn
end
def server_version
@server_version ||= synchronize{|c| c.server_version}
end
def execute(sql, opts=OPTS)
synchronize(opts[:server]) do |conn|
r = log_yield(sql) do
begin
conn.query(sql)
rescue => e
raise_error(e)
end
end
if block_given?
yield(r)
else
begin
case opts[:type]
when :dui
# This is cubrid's API, but it appears to be completely broken,
# giving StandardError: ERROR: CCI, -18, Invalid request handle
#r.affected_rows
# Work around bugs by using the ROW_COUNT function.
begin
r2 = conn.query(ROW_COUNT)
r2.each{|a| return a.first.to_i}
ensure
r2.close if r2
end
when :insert
begin
r2 = conn.query(LAST_INSERT_ID)
r2.each{|a| return a.first.to_i}
ensure
r2.close if r2
end
end
ensure
r.close
end
end
end
end
def execute_ddl(sql, opts=OPTS)
execute(sql, opts.merge(:type=>:ddl))
end
def execute_dui(sql, opts=OPTS)
execute(sql, opts.merge(:type=>:dui))
end
def execute_insert(sql, opts=OPTS)
execute(sql, opts.merge(:type=>:insert))
end
private
def begin_transaction(conn, opts=OPTS)
log_yield(TRANSACTION_BEGIN){conn.auto_commit = false}
end
def commit_transaction(conn, opts=OPTS)
log_yield(TRANSACTION_COMMIT){conn.commit}
end
def database_error_classes
[StandardError]
end
def remove_transaction(conn, committed)
conn.auto_commit = true
ensure
super
end
# This doesn't actually work, as the cubrid ruby driver
# does not implement transactions correctly.
def rollback_transaction(conn, opts=OPTS)
log_yield(TRANSACTION_ROLLBACK){conn.rollback}
end
end
class Dataset < Sequel::Dataset
include Sequel::Cubrid::DatasetMethods
COLUMN_INFO_NAME = "name".freeze
COLUMN_INFO_TYPE = "type_name".freeze
Database::DatasetClass = self
def fetch_rows(sql)
execute(sql) do |stmt|
begin
procs =
cols = stmt.column_info.map{|c| [output_identifier(c[COLUMN_INFO_NAME]), CUBRID_TYPE_PROCS[c[COLUMN_INFO_TYPE]]]}
@columns = cols.map{|c| c.first}
stmt.each do |r|
row = {}
cols.zip(r).each{|(k, p), v| row[k] = (v && p) ? p.call(v) : v}
yield row
end
ensure
stmt.close
end
end
self
end
end
end
end
|