Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow Fixnum values to be quoted #192

Open
wants to merge 1 commit into from

3 participants

@neerajdotname

Currently User.where(id: '10') would result in query where the
value is integer 10 instead of string 10. That's because id column is
of type 'Integer`.

However User.where(name: 10) would not result in value in string even though column name is of type "string"

This PR allows "Fixnum" to be quoted so that in ActiveRecord proper
quoting can be done based on column type.

Please see rails/rails#11138 for the changes in ActiveRecord side.

@neerajdotname neerajdotname Allow Fixnum values to be quoted
Currently `User.where(id: '10')` would result in query where the
value is integer 10 instead of string 10. That's because id column is
of type 'Integer`.

However `User.where(name: 10)` would not result in value in string even
though name column is of type 'String'.

This PR allows "Fixnum" to be quoted so that in ActiveRecord proper
quoting can be done based on column type.
8c444af
@dylanahsmith

This appears to be a duplicate of pull #162, although is missing quoting for bignum.

@tamird

obsolete, good to close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 27, 2013
  1. @neerajdotname

    Allow Fixnum values to be quoted

    neerajdotname authored
    Currently `User.where(id: '10')` would result in query where the
    value is integer 10 instead of string 10. That's because id column is
    of type 'Integer`.
    
    However `User.where(name: 10)` would not result in value in string even
    though name column is of type 'String'.
    
    This PR allows "Fixnum" to be quoted so that in ActiveRecord proper
    quoting can be done based on column type.
This page is out of date. Refresh to see the latest.
View
1  lib/arel/visitors/to_sql.rb
@@ -575,6 +575,7 @@ def quoted o, a
alias :visit_Hash :quoted
alias :visit_NilClass :quoted
alias :visit_String :quoted
+ alias :visit_Fixnum :quoted
alias :visit_Symbol :quoted
alias :visit_Time :quoted
alias :visit_TrueClass :quoted
View
2  test/nodes/test_equality.rb
@@ -43,7 +43,7 @@ def quote_table_name(*args) @quote_count += 1; super; end
attr = Table.new(:users)[:id]
test = attr.eq(10)
test.to_sql engine
- engine.connection.quote_count.must_equal 2
+ engine.connection.quote_count.must_equal 3
end
end
end
View
4 test/support/fake_record.rb
@@ -107,6 +107,10 @@ def columns_hash
def schema_cache
connection
end
+
+ def quote *args
+ connection.quote *args
+ end
end
class Base
Something went wrong with that request. Please try again.