Permalink
Browse files

If no bind variables are sent, do not throw an error if the query con…

…tains a ?
  • Loading branch information...
1 parent 591a1e7 commit aec81b891fe3ec511c27e706fb3d59ded06e2952 @kreynolds committed Oct 10, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −1 lib/cassandra-cql/statement.rb
  2. +0 −4 spec/statement_spec.rb
@@ -102,10 +102,12 @@ def self.cast_to_cql(obj)
end
def self.sanitize(statement, bind_vars=[])
+ # If there are no bind variables, return the statement unaltered
+ return statement if bind_vars.empty?
+
bind_vars = bind_vars.dup
expected_bind_vars = statement.count("?")
- return statement if expected_bind_vars == 0 and bind_vars.empty?
raise Error::InvalidBindVariable, "Wrong number of bound variables (statement expected #{expected_bind_vars}, was #{bind_vars.size})" if expected_bind_vars != bind_vars.size
statement.gsub(/\?/) {
View
@@ -183,10 +183,6 @@
context "when expecting bind vars" do
it "should raise an exception with bind variable mismatch" do
- expect {
- Statement.sanitize("use keyspace ?")
- }.to raise_error(Error::InvalidBindVariable)
-
expect {
Statement.sanitize("use keyspace ?", ['too', 'many'])
}.to raise_error(Error::InvalidBindVariable)

0 comments on commit aec81b8

Please sign in to comment.