Skip to content

Commit

Permalink
Use . instead of __ to separate the qualified bound variables created…
Browse files Browse the repository at this point in the history
… by unbind

The double underscore is already used by the native postgres adapter
to specify types.

There was already a partial fix for this earlier in the SQLite
adapter, but it only handled the SQL serialization.  This completes
that fix by also handling the bind variables.
  • Loading branch information
jeremyevans committed May 25, 2011
1 parent ba43176 commit 5dbc188
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/sequel/adapters/sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ module ArgumentMapper
# but with the keys converted to strings.
def map_to_prepared_args(hash)
args = {}
hash.each{|k,v| args[k.to_s] = v}
hash.each{|k,v| args[k.to_s.gsub('.', '__')] = v}
args
end

Expand Down
15 changes: 13 additions & 2 deletions lib/sequel/ast_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,18 @@ def v(o)
# and use the bound variables to execute it with the same values.
#
# This class only does a limited form of unbinding where the variable names
# and values can be associated unambiguously.
# and values can be associated unambiguously. The only cases it handles
# are <tt>SQL::ComplexExpression<tt> with an operator in +UNBIND_OPS+, a
# first argument that's an instance of a member of +UNBIND_KEY_CLASSES+, and
# a second argument that's an instance of a member of +UNBIND_VALUE_CLASSES+.
#
# So it can handle cases like:
#
# DB.filter(:a=>1).exclude(:b=>2).where{c > 3}
#
# But it cannot handle cases like:
#
# DB.filter(:a + 1 < 0)
class Unbinder < ASTTransformer
# The <tt>SQL::ComplexExpression<tt> operates that will be considered
# for transformation.
Expand Down Expand Up @@ -149,7 +160,7 @@ def bind_key(obj)
when SQL::Identifier
bind_key(obj.value)
when SQL::QualifiedIdentifier
:"#{bind_key(obj.table)}__#{bind_key(obj.column)}"
:"#{bind_key(obj.table)}.#{bind_key(obj.column)}"
else
raise Error, "unhandled object in Sequel::Unbinder#bind_key: #{obj}"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/core/dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3657,7 +3657,7 @@ def @ds.fetch_rows(sql, &block)
end

specify "should handle QualifiedIdentifiers" do
@u[@ds.filter{foo__bar > 1}].should == ["SELECT * FROM t WHERE (foo.bar > $foo.bar)", {:foo__bar=>1}]
@u[@ds.filter{foo__bar > 1}].should == ["SELECT * FROM t WHERE (foo.bar > $foo.bar)", {:"foo.bar"=>1}]
end

specify "should handle deep nesting" do
Expand Down

0 comments on commit 5dbc188

Please sign in to comment.