3 def self.adapter_selector
4 [/firebird/i, lambda{|cfg,adapt| adapt.extend(::JdbcSpec::FireBird)}]
8 tp[:primary_key] = 'INTEGER NOT NULL PRIMARY KEY'
9 tp[:string][:limit] = 252
10 tp[:integer][:limit] = nil
14 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) # :nodoc:
19 def add_limit_offset!(sql, options) # :nodoc:
21 limit_string = "FIRST #{options[:limit]}"
22 limit_string << " SKIP #{options[:offset]}" if options[:offset]
23 sql.sub!(/\A(\s*SELECT\s)/i, '\&' + limit_string + ' ')
27 def prefetch_primary_key?(table_name = nil)
31 def default_sequence_name(table_name, primary_key) # :nodoc:
35 def next_sequence_value(sequence_name)
36 select_one("SELECT GEN_ID(#{sequence_name}, 1 ) FROM RDB$DATABASE;")["gen_id"]
39 def create_table(name, options = {}) #:nodoc:
41 execute "CREATE GENERATOR #{name}_seq"
44 def rename_table(name, new_name) #:nodoc:
45 execute "RENAME #{name} TO #{new_name}"
46 execute "UPDATE RDB$GENERATORS SET RDB$GENERATOR_NAME='#{new_name}_seq' WHERE RDB$GENERATOR_NAME='#{name}_seq'" rescue nil
49 def drop_table(name, options = {}) #:nodoc:
51 execute "DROP GENERATOR #{name}_seq" rescue nil
54 def change_column(table_name, column_name, type, options = {}) #:nodoc:
55 execute "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type_to_sql(type, options[:limit])}"
58 def rename_column(table_name, column_name, new_column_name)
59 execute "ALTER TABLE #{table_name} ALTER #{column_name} TO #{new_column_name}"
62 def remove_index(table_name, options) #:nodoc:
63 execute "DROP INDEX #{index_name(table_name, options)}"
66 def quote(value, column = nil) # :nodoc:
67 return value.quoted_id if value.respond_to?(:quoted_id)
69 if [Time, DateTime].include?(value.class)
70 "CAST('#{value.strftime("%Y-%m-%d %H:%M:%S")}' AS TIMESTAMP)"
72 if column && column.type == :primary_key
79 def quote_string(string) # :nodoc:
80 string.gsub(/'/, "''")
83 def quote_column_name(column_name) # :nodoc:
84 %Q("#{ar_to_fb_case(column_name)}")
87 def quoted_true # :nodoc:
91 def quoted_false # :nodoc:
97 # Maps uppercase Firebird column names to lowercase for ActiveRecord;
98 # mixed-case columns retain their original case.
99 def fb_to_ar_case(column_name)
100 column_name =~ /[[:lower:]]/ ? column_name : column_name.to_s.downcase
103 # Maps lowercase ActiveRecord column names to uppercase for Fierbird;
104 # mixed-case columns retain their original case.
105 def ar_to_fb_case(column_name)
106 column_name =~ /[[:upper:]]/ ? column_name : column_name.to_s.upcase