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:.
- #arel2_visitors ⇒ Object
-
#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
.extended(mod) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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] value = value.to_yaml if unserializable_attribute?(c.name, c) 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
22 23 24 |
# File 'lib/arjdbc/firebird/adapter.rb', line 22 def adapter_name 'Firebird' end |
#add_limit_offset!(sql, options) ⇒ Object
:nodoc:
43 44 45 46 47 48 49 |
# File 'lib/arjdbc/firebird/adapter.rb', line 43 def add_limit_offset!(sql, ) # :nodoc: if [:limit] limit_string = "FIRST #{[:limit]}" limit_string << " SKIP #{[:offset]}" if [:offset] sql.sub!(/\A(\s*SELECT\s)/i, '\&' + limit_string + ' ') end end |
#arel2_visitors ⇒ Object
26 27 28 29 |
# File 'lib/arjdbc/firebird/adapter.rb', line 26 def arel2_visitors require 'arel/visitors/firebird' {'firebird' => ::Arel::Visitors::Firebird, 'firebirdsql' => ::Arel::Visitors::Firebird} end |
#change_column(table_name, column_name, type, options = {}) ⇒ Object
:nodoc:
78 79 80 |
# File 'lib/arjdbc/firebird/adapter.rb', line 78 def change_column(table_name, column_name, type, = {}) #:nodoc: execute "ALTER TABLE #{table_name} ALTER #{column_name} TYPE #{type_to_sql(type, [:limit])}" end |
#create_table(name, options = {}) ⇒ Object
:nodoc:
63 64 65 66 |
# File 'lib/arjdbc/firebird/adapter.rb', line 63 def create_table(name, = {}) #:nodoc: super(name, ) execute "CREATE GENERATOR #{name}_seq" end |
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:
55 56 57 |
# File 'lib/arjdbc/firebird/adapter.rb', line 55 def default_sequence_name(table_name, primary_key) # :nodoc: "#{table_name}_seq" end |
#drop_table(name, options = {}) ⇒ Object
:nodoc:
73 74 75 76 |
# File 'lib/arjdbc/firebird/adapter.rb', line 73 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:
38 39 40 41 |
# File 'lib/arjdbc/firebird/adapter.rb', line 38 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
31 32 33 34 35 36 |
# File 'lib/arjdbc/firebird/adapter.rb', line 31 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
59 60 61 |
# File 'lib/arjdbc/firebird/adapter.rb', line 59 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
51 52 53 |
# File 'lib/arjdbc/firebird/adapter.rb', line 51 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
:nodoc:
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/arjdbc/firebird/adapter.rb', line 90 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:
110 111 112 |
# File 'lib/arjdbc/firebird/adapter.rb', line 110 def quote_column_name(column_name) # :nodoc: %Q("#{ar_to_fb_case(column_name)}") end |
#quote_string(string) ⇒ Object
:nodoc:
106 107 108 |
# File 'lib/arjdbc/firebird/adapter.rb', line 106 def quote_string(string) # :nodoc: string.gsub(/'/, "''") end |
#quoted_false ⇒ Object
:nodoc:
118 119 120 |
# File 'lib/arjdbc/firebird/adapter.rb', line 118 def quoted_false # :nodoc: quote(0) end |
#quoted_true ⇒ Object
:nodoc:
114 115 116 |
# File 'lib/arjdbc/firebird/adapter.rb', line 114 def quoted_true # :nodoc: quote(1) end |
#remove_index(table_name, options) ⇒ Object
:nodoc:
86 87 88 |
# File 'lib/arjdbc/firebird/adapter.rb', line 86 def remove_index(table_name, ) #:nodoc: execute "DROP INDEX #{index_name(table_name, )}" end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
82 83 84 |
# File 'lib/arjdbc/firebird/adapter.rb', line 82 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:
68 69 70 71 |
# File 'lib/arjdbc/firebird/adapter.rb', line 68 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 |