Skip to content

Commit

Permalink
Database#query should accept nil for backwards compat. Fixes RF #28192
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 11, 2010
1 parent fab1763 commit 22b0c3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/sqlite3/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,21 @@ def execute_batch( sql, *bind_vars )
# returned, or you could have problems with locks on the table. If called
# with a block, +close+ will be invoked implicitly when the block
# terminates.
def query( sql, *bind_vars )
def query( sql, bind_vars = [], *args )

if bind_vars.nil? || !args.empty?
if args.empty?
bind_vars = []
else
bind_vars = [nil] + args
end

warn(<<-eowarn) if $VERBOSE
#{caller[0]} is calling SQLite3::Database#query with nil or multiple bind params
without using an array. Please switch to passing bind parameters as an array.
eowarn
end

result = prepare( sql ).execute( *bind_vars )
if block_given?
begin
Expand Down
4 changes: 4 additions & 0 deletions test/test_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,9 @@ def test_close_with_open_statements
@db.close
end
end

def test_execute_with_empty_bind_params
assert_equal [['foo']], @db.execute("select 'foo'", [])
end
end
end

0 comments on commit 22b0c3d

Please sign in to comment.