Module: ArJdbc::FireBird
- Defined in:
- lib/arjdbc/firebird/adapter.rb
Constant Summary collapse
- @@_lob_callback_added =
nil
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(types) ⇒ 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
34 35 36 37 38 39 40 |
# File 'lib/arjdbc/firebird/adapter.rb', line 34 def self.arel2_visitors(config) require 'arel/visitors/firebird' { 'firebird' => ::Arel::Visitors::Firebird, 'firebirdsql' => ::Arel::Visitors::Firebird } end |
.extended(mod) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/arjdbc/firebird/adapter.rb', line 8 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 |column| value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column) next if value.nil? connection.write_large_object( column.type == :binary, column.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
30 31 32 |
# File 'lib/arjdbc/firebird/adapter.rb', line 30 def adapter_name 'Firebird' end |
#add_limit_offset!(sql, options) ⇒ Object
:nodoc:
55 56 57 58 59 60 61 |
# File 'lib/arjdbc/firebird/adapter.rb', line 55 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 |
#change_column(table_name, column_name, type, options = {}) ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/arjdbc/firebird/adapter.rb', line 90 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:
75 76 77 78 |
# File 'lib/arjdbc/firebird/adapter.rb', line 75 def create_table(name, = {}) #:nodoc: super(name, ) execute "CREATE GENERATOR #{name}_seq" end |
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:
67 68 69 |
# File 'lib/arjdbc/firebird/adapter.rb', line 67 def default_sequence_name(table_name, primary_key) # :nodoc: "#{table_name}_seq" end |
#drop_table(name, options = {}) ⇒ Object
:nodoc:
85 86 87 88 |
# File 'lib/arjdbc/firebird/adapter.rb', line 85 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:
50 51 52 53 |
# File 'lib/arjdbc/firebird/adapter.rb', line 50 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) # :nodoc: execute(sql, name, binds) id_value end |
#modify_types(types) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/arjdbc/firebird/adapter.rb', line 42 def modify_types(types) super(types) types[:primary_key] = 'INTEGER NOT NULL PRIMARY KEY' types[:string][:limit] = 252 types[:integer][:limit] = nil types end |
#next_sequence_value(sequence_name) ⇒ Object
71 72 73 |
# File 'lib/arjdbc/firebird/adapter.rb', line 71 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
63 64 65 |
# File 'lib/arjdbc/firebird/adapter.rb', line 63 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
:nodoc:
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/arjdbc/firebird/adapter.rb', line 102 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:
122 123 124 |
# File 'lib/arjdbc/firebird/adapter.rb', line 122 def quote_column_name(column_name) # :nodoc: %Q("#{ar_to_fb_case(column_name)}") end |
#quote_string(string) ⇒ Object
:nodoc:
118 119 120 |
# File 'lib/arjdbc/firebird/adapter.rb', line 118 def quote_string(string) # :nodoc: string.gsub(/'/, "''") end |
#quoted_false ⇒ Object
:nodoc:
130 131 132 |
# File 'lib/arjdbc/firebird/adapter.rb', line 130 def quoted_false # :nodoc: quote(0) end |
#quoted_true ⇒ Object
:nodoc:
126 127 128 |
# File 'lib/arjdbc/firebird/adapter.rb', line 126 def quoted_true # :nodoc: quote(1) end |
#remove_index(table_name, options) ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/arjdbc/firebird/adapter.rb', line 98 def remove_index(table_name, ) #:nodoc: execute "DROP INDEX #{index_name(table_name, )}" end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
94 95 96 |
# File 'lib/arjdbc/firebird/adapter.rb', line 94 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:
80 81 82 83 |
# File 'lib/arjdbc/firebird/adapter.rb', line 80 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 |