Module: ArJdbc::FireBird
- Defined in:
- lib/arjdbc/firebird/adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #adapter_name ⇒ Object
-
#add_limit_offset!(sql, options) ⇒ Object
:nodoc:.
-
#change_column(table_name, column_name, type, options = {}) ⇒ Object
:nodoc:.
-
#create_table(name, options = {}) ⇒ Object
:nodoc:.
-
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:.
-
#drop_table(name, options = {}) ⇒ Object
:nodoc:.
-
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) ⇒ Object
:nodoc:.
- #modify_types(tp) ⇒ Object
- #next_sequence_value(sequence_name) ⇒ Object
- #prefetch_primary_key?(table_name = nil) ⇒ Boolean
-
#quote(value, column = nil) ⇒ Object
:nodoc:.
-
#quote_column_name(column_name) ⇒ Object
:nodoc:.
-
#quote_string(string) ⇒ Object
:nodoc:.
-
#quoted_false ⇒ Object
:nodoc:.
-
#quoted_true ⇒ Object
:nodoc:.
-
#remove_index(table_name, options) ⇒ Object
:nodoc:.
- #rename_column(table_name, column_name, new_column_name) ⇒ Object
-
#rename_table(name, new_name) ⇒ Object
:nodoc:.
Class Method Details
.arel2_visitors(config) ⇒ Object
30 31 32 33 |
# File 'lib/arjdbc/firebird/adapter.rb', line 30 def self.arel2_visitors(config) require 'arel/visitors/firebird' {}.tap {|v| %w(firebird firebirdsql).each {|a| v[a] = ::Arel::Visitors::Firebird } } end |
.extended(mod) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/arjdbc/firebird/adapter.rb', line 4 def self.extended(mod) unless @lob_callback_added ActiveRecord::Base.class_eval do def after_save_with_firebird_blob self.class.columns.select { |c| c.sql_type =~ /blob/i }.each do |c| value = self[c.name] if respond_to?(:unserializable_attribute?) value = value.to_yaml if unserializable_attribute?(c.name, c) else value = value.to_yaml if value.is_a?(Hash) end next if value.nil? connection.write_large_object(c.type == :binary, c.name, self.class.table_name, self.class.primary_key, quote_value(id), value) end end end ActiveRecord::Base.after_save :after_save_with_firebird_blob @lob_callback_added = true end end |
Instance Method Details
#adapter_name ⇒ Object
26 27 28 |
# File 'lib/arjdbc/firebird/adapter.rb', line 26 def adapter_name 'Firebird' end |
#add_limit_offset!(sql, options) ⇒ Object
:nodoc:
47 48 49 50 51 52 53 |
# File 'lib/arjdbc/firebird/adapter.rb', line 47 def add_limit_offset!(sql, ) # :nodoc: if [:limit] limit_string = "FIRST #{options[:limit]}" limit_string << " SKIP #{options[:offset]}" if [:offset] sql.sub!(/\A(\s*SELECT\s)/i, '\&' + limit_string + ' ') end end |
#change_column(table_name, column_name, type, options = {}) ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/arjdbc/firebird/adapter.rb', line 82 def change_column(table_name, column_name, type, = {}) #:nodoc: execute "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type_to_sql(type, options[:limit])}" end |
#create_table(name, options = {}) ⇒ Object
:nodoc:
67 68 69 70 |
# File 'lib/arjdbc/firebird/adapter.rb', line 67 def create_table(name, = {}) #:nodoc: super(name, ) execute "CREATE GENERATOR #{name}_seq" end |
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:
59 60 61 |
# File 'lib/arjdbc/firebird/adapter.rb', line 59 def default_sequence_name(table_name, primary_key) # :nodoc: "#{table_name}_seq" end |
#drop_table(name, options = {}) ⇒ Object
:nodoc:
77 78 79 80 |
# File 'lib/arjdbc/firebird/adapter.rb', line 77 def drop_table(name, = {}) #:nodoc: super(name) execute "DROP GENERATOR #{name}_seq" rescue nil end |
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) ⇒ Object
:nodoc:
42 43 44 45 |
# File 'lib/arjdbc/firebird/adapter.rb', line 42 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) # :nodoc: execute(sql, name, binds) id_value end |
#modify_types(tp) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/arjdbc/firebird/adapter.rb', line 35 def modify_types(tp) tp[:primary_key] = 'INTEGER NOT NULL PRIMARY KEY' tp[:string][:limit] = 252 tp[:integer][:limit] = nil tp end |
#next_sequence_value(sequence_name) ⇒ Object
63 64 65 |
# File 'lib/arjdbc/firebird/adapter.rb', line 63 def next_sequence_value(sequence_name) select_one("SELECT GEN_ID(#{sequence_name}, 1 ) FROM RDB$DATABASE;")["gen_id"] end |
#prefetch_primary_key?(table_name = nil) ⇒ Boolean
55 56 57 |
# File 'lib/arjdbc/firebird/adapter.rb', line 55 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
:nodoc:
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/arjdbc/firebird/adapter.rb', line 94 def quote(value, column = nil) # :nodoc: return value.quoted_id if value.respond_to?(:quoted_id) # BLOBs are updated separately by an after_save trigger. return value.nil? ? "NULL" : "'#{quote_string(value[0..1])}'" if column && [:binary, :text].include?(column.type) if [Time, DateTime].include?(value.class) "CAST('#{value.strftime("%Y-%m-%d %H:%M:%S")}' AS TIMESTAMP)" else if column && column.type == :primary_key return value.to_s end super end end |
#quote_column_name(column_name) ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/arjdbc/firebird/adapter.rb', line 114 def quote_column_name(column_name) # :nodoc: %Q("#{ar_to_fb_case(column_name)}") end |
#quote_string(string) ⇒ Object
:nodoc:
110 111 112 |
# File 'lib/arjdbc/firebird/adapter.rb', line 110 def quote_string(string) # :nodoc: string.gsub(/'/, "''") end |
#quoted_false ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/arjdbc/firebird/adapter.rb', line 122 def quoted_false # :nodoc: quote(0) end |
#quoted_true ⇒ Object
:nodoc:
118 119 120 |
# File 'lib/arjdbc/firebird/adapter.rb', line 118 def quoted_true # :nodoc: quote(1) end |
#remove_index(table_name, options) ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/arjdbc/firebird/adapter.rb', line 90 def remove_index(table_name, ) #:nodoc: execute "DROP INDEX #{index_name(table_name, options)}" end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
86 87 88 |
# File 'lib/arjdbc/firebird/adapter.rb', line 86 def rename_column(table_name, column_name, new_column_name) execute "ALTER TABLE #{table_name} ALTER #{column_name} TO #{new_column_name}" end |
#rename_table(name, new_name) ⇒ Object
:nodoc:
72 73 74 75 |
# File 'lib/arjdbc/firebird/adapter.rb', line 72 def rename_table(name, new_name) #:nodoc: execute "RENAME #{name} TO #{new_name}" execute "UPDATE RDB$GENERATORS SET RDB$GENERATOR_NAME='#{new_name}_seq' WHERE RDB$GENERATOR_NAME='#{name}_seq'" rescue nil end |