Skip to content

Commit af493aa

Browse files
committed
do not raise an exception on statements that are only comments
1 parent 254d6fd commit af493aa

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/sqlite3/database.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,18 @@ def execute_batch( sql, bind_vars = [], *args )
221221
sql = sql.strip
222222
until sql.empty? do
223223
prepare( sql ) do |stmt|
224-
# FIXME: this should probably use sqlite3's api for batch execution
225-
# This implementation requires stepping over the results.
226-
if bind_vars.length == stmt.bind_parameter_count
227-
stmt.bind_params(bind_vars)
224+
unless stmt.closed?
225+
# FIXME: this should probably use sqlite3's api for batch execution
226+
# This implementation requires stepping over the results.
227+
if bind_vars.length == stmt.bind_parameter_count
228+
stmt.bind_params(bind_vars)
229+
end
230+
stmt.step
228231
end
229-
stmt.step
230232
sql = stmt.remainder.strip
231233
end
232234
end
235+
# FIXME: we should not return `nil` as a success return value
233236
nil
234237
end
235238

test/test_database.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ def test_changes
6060
assert_equal [[30]], @db.execute("select number from items")
6161
end
6262

63+
def test_batch_last_comment_is_processed
64+
# FIXME: nil as a successful return value is kinda dumb
65+
assert_nil @db.execute_batch <<-eosql
66+
CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT);
67+
-- omg
68+
eosql
69+
end
70+
6371
def test_new
6472
db = SQLite3::Database.new(':memory:')
6573
assert db

0 commit comments

Comments
 (0)