From e6d5ad33c31a81357846e8dc280cfcd72d49412d Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Thu, 14 Sep 2017 14:51:25 -0400 Subject: [PATCH] Multi-step exec support (#27) --- spec/db_spec.cr | 8 ++++++++ src/sqlite3/statement.cr | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/db_spec.cr b/spec/db_spec.cr index 658525c..ff508f6 100644 --- a/spec/db_spec.cr +++ b/spec/db_spec.cr @@ -119,4 +119,12 @@ DB::DriverSpecs(DB::Any).run do end end end + + it "handles single-step pragma statements" do |db| + db.exec %(PRAGMA synchronous = OFF) + end + + it "handles multi-step pragma statements" do |db| + db.exec %(PRAGMA journal_mode = memory) + end end diff --git a/src/sqlite3/statement.cr b/src/sqlite3/statement.cr index 90c4d7e..510da04 100644 --- a/src/sqlite3/statement.cr +++ b/src/sqlite3/statement.cr @@ -19,7 +19,11 @@ class SQLite3::Statement < DB::Statement end # exec - step = LibSQLite3::Code.new LibSQLite3.step(self) + step = uninitialized LibSQLite3::Code + loop do + step = LibSQLite3::Code.new LibSQLite3.step(self) + break unless step == LibSQLite3::Code::ROW + end raise Exception.new(sqlite3_connection) unless step == LibSQLite3::Code::DONE rows_affected = LibSQLite3.changes(sqlite3_connection).to_i64