3 def self.adapter_selector
4 [/mimer/i, lambda {|cfg,adapt| adapt.extend(::JdbcSpec::Mimer)}]
8 tp[:primary_key] = "INTEGER NOT NULL PRIMARY KEY"
9 tp[:boolean][:limit] = nil
10 tp[:string][:limit] = 255
11 tp[:binary] = {:name => "BINARY VARYING", :limit => 4096}
12 tp[:text] = {:name => "VARCHAR", :limit => 4096}
13 tp[:datetime] = { :name => "TIMESTAMP" }
14 tp[:timestamp] = { :name => "TIMESTAMP" }
15 tp[:time] = { :name => "TIMESTAMP" }
16 tp[:date] = { :name => "TIMESTAMP" }
20 def default_sequence_name(table, column) #:nodoc:
24 def create_table(name, options = {}) #:nodoc:
26 execute "CREATE SEQUENCE #{name}_seq" unless options[:id] == false
29 def drop_table(name, options = {}) #:nodoc:
30 super(name) rescue nil
31 execute "DROP SEQUENCE #{name}_seq" rescue nil
34 def change_column(table_name, column_name, type, options = {}) #:nodoc:
35 execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} #{type_to_sql(type, options[:limit])}"
38 def change_column_default(table_name, column_name, default) #:nodoc:
39 execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET DEFAULT #{quote(default)}"
42 def remove_index(table_name, options = {}) #:nodoc:
43 execute "DROP INDEX #{index_name(table_name, options)}"
46 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
47 if pk.nil? # Who called us? What does the sql look like? No idea!
49 elsif id_value # Pre-assigned id
50 log(sql, name) { @connection.execute_insert sql,pk }
51 else # Assume the sql contains a bind-variable for the id
52 id_value = select_one("SELECT NEXT_VALUE OF #{sequence_name} AS val FROM MIMER.ONEROW")['val']
54 execute_prepared_insert(sql,id_value)
60 def execute_prepared_insert(sql, id)
62 @stmts[sql] ||= @connection.ps(sql)
69 def quote(value, column = nil) #:nodoc:
70 return value.quoted_id if value.respond_to?(:quoted_id)
72 if String === value && column && column.type == :binary
73 return "X'#{quote_string(value.unpack("C*").collect {|v| v.to_s(16)}.join)}'"
76 when String : %Q{'#{quote_string(value)}'}
77 when NilClass : 'NULL'
80 when Numeric : value.to_s
81 when Date, Time : %Q{TIMESTAMP '#{value.strftime("%Y-%m-%d %H:%M:%S")}'}
82 else %Q{'#{quote_string(value.to_yaml)}'}
94 def add_limit_offset!(sql, options) # :nodoc:
95 @limit = options[:limit]
96 @offset = options[:offset]
99 def select_all(sql, name = nil)
101 if !@limit || @limit == -1
104 range = @offset...(@offset+@limit)
106 select(sql, name)[range]
108 @limit = @offset = nil
111 def select_one(sql, name = nil)
113 select(sql, name)[@offset]
115 @limit = @offset = nil
118 def _execute(sql, name = nil)
121 if !@limit || @limit == -1
124 range = @offset...(@offset+@limit)
126 @connection.execute_query(sql)[range]
128 @connection.execute_update(sql)
131 @limit = @offset = nil