Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Firebird] Rails 4 Fixes #512

Closed
wants to merge 1 commit into from

2 participants

@rzane

Calling visit_Arel_Nodes_SelectCore(x) raised an Argument Error with Rails 4. It looks like this change was made for other adapters with @ce7d68d.

Not-null blob values were inserting null values and failing as described in #430. I basically copied the changes that were made in @47bcdcf for the DB2 adapter.

Firebird can't have the table name in the set clause of an update statement. I added the quote_table_name_for_assignment override used in the SQLite3 adapter. (https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/sqlite3/adapter.rb#L226-L228)

@kares
Collaborator

Ray, I already added ad137a6 for the other fixes you squashed into one please rebase and open another PR and include a better commit message - just like you did previously ... Thanks!

@kares kares closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 10, 2013
  1. @rzane

    Rails 4 Fixes

    rzane authored
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 3 deletions.
  1. +1 −1  lib/arel/visitors/firebird.rb
  2. +32 −2 lib/arjdbc/firebird/adapter.rb
View
2  lib/arel/visitors/firebird.rb
@@ -11,7 +11,7 @@ def visit_Arel_Nodes_SelectStatement o, a = nil
].compact.join(' ').strip
sql = [
- o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
+ o.cores.map { |x| do_visit_select_core x, a }.join,
("ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?),
].compact.join ' '
View
34 lib/arjdbc/firebird/adapter.rb
@@ -10,7 +10,7 @@ def self.extended(adapter); initialize!; end
# @private
def self.initialize!
return if @@_initialized; @@_initialized = true
-
+
require 'arjdbc/util/serialized_attributes'
Util::SerializedAttributes.setup /blob/i
end
@@ -75,6 +75,24 @@ def self.emulate_booleans; @@emulate_booleans; end
# @see #emulate_booleans?
def self.emulate_booleans=(emulate); @@emulate_booleans = emulate; end
+ # @private
+ @@update_lob_values = true
+
+ # Updating records with LOB values (binary/text columns) in a separate
+ # statement can be disabled using :
+ #
+ # ArJdbc::Firebird.update_lob_values = false
+ def self.update_lob_values?; @@update_lob_values; end
+ # @see #update_lob_values?
+ def self.update_lob_values=(update); @@update_lob_values = update; end
+
+ # @see #update_lob_values?
+ def update_lob_values?; Firebird.update_lob_values?; end
+
+ # @see #quote
+ # @private
+ BLOB_VALUE_MARKER = "''"
+
ADAPTER_NAME = 'Firebird'.freeze
def adapter_name
@@ -222,8 +240,15 @@ def quote(value, column = nil)
return value if sql_literal?(value)
type = column && column.type
+
# BLOBs are updated separately by an after_save trigger.
- return "NULL" if type == :binary || type == :text
+ if type == :binary || type == :text
+ if update_lob_values?
+ return value.nil? ? "NULL" : BLOB_VALUE_MARKER
+ else
+ return "'#{quote_string(value)}'"
+ end
+ end
case value
when String, ActiveSupport::Multibyte::Chars
@@ -280,6 +305,11 @@ def quoted_false
end
# @override
+ def quote_table_name_for_assignment(table, attr)
+ quote_column_name(attr)
+ end if ::ActiveRecord::VERSION::MAJOR >= 4
+
+ # @override
def quote_column_name(column_name)
column_name = column_name.to_s
%Q("#{column_name =~ /[[:upper:]]/ ? column_name : column_name.upcase}")
Something went wrong with that request. Please try again.