Commit Diff


commit - 74585e1b0b054cad5d547230c5b2f2b43b71a37b
commit + 69d19e3e527d425a414641ed8e57b47070af1f73
blob - e1f208053a03ef5212cc37babf94b66789e5db08
blob + 5ab5a97987bcd2e604d4125a7109c601fe5ee3f0
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http
 
 ### Fixed
 
+- Executing `close` method in a `Client` instance (#2).
+
 [Unreleased]: https://github.com/ligurio/molly/compare/0.1.0...HEAD
 
 ## 0.1.0
blob - 226b07db3953549d976d8f8565fe7f6f5a67346a
blob + 42c704265fea99494356c63c38a5bc9e9fda113d
--- molly/client.lua
+++ molly/client.lua
@@ -58,12 +58,14 @@ local function invoke(thread_id, opts)
     log.debug('Opening connection by thread %d to DB (%s)', thread_id, addr)
     local ok, err = pcall(client.open, client, addr)
     if not ok then
+        log.info('ERROR: %s', err)
         return false, err
     end
 
     log.debug('Setting up DB (%s) by thread %d', addr, thread_id)
     ok, err = pcall(client.setup, client)
     if not ok then
+        log.info('ERROR: %s', err)
         return false, err
     end
 
@@ -92,12 +94,14 @@ local function invoke(thread_id, opts)
     log.debug('Tearing down DB (%s) by thread %d', addr, thread_id)
     ok, err = pcall(client.teardown, client)
     if not ok then
+        log.info('ERROR: %s', err)
         return false, err
     end
 
     log.debug('Closing connection to DB (%s) by thread %d', addr, thread_id)
     ok, err = pcall(client.close, client)
     if not ok then
+        log.info('ERROR: %s', err)
         return false, err
     end
 
blob - 45499684569da4aae4dd29049674c94529723041
blob + e32ddd1f1928d03274b1e74e23267d8872081fbb
--- test/examples/sqlite-list-append.lua
+++ test/examples/sqlite-list-append.lua
@@ -87,14 +87,17 @@ end
 sqlite_list_append.teardown = function(self)
     --self.insert_stmt:finalize()
     --self.select_stmt:finalize()
-    local changes = self.db:total_changes()
-    --assert(changes == 500, string.format('Number of operations is wrong (%d != 500)', changes))
-    print('Total changes in SQLite DB:', changes)
     return true
 end
 
 sqlite_list_append.close = function(self)
-    self.db:close()
+    -- Close database. All SQL statements prepared using
+    -- db:prepare() should have been finalized before this
+    -- function is called. The function returns sqlite3.OK on
+    -- success or else a numerical error code.
+    if self.db:isopen() then
+        assert(self.db:close() == sqlite3.OK)
+    end
     return true
 end
 
blob - d31eac653acd39e8ed058a2a8efb35e13f3b714c
blob + be1af7a2a9b443e0e6eeba289209ab2f736bdae8
--- test/examples/sqlite-rw-register.lua
+++ test/examples/sqlite-rw-register.lua
@@ -104,14 +104,17 @@ end
 sqlite_rw_register.teardown = function(self)
     --self.insert_stmt:finalize()
     --self.select_stmt:finalize()
-    local changes = self.db:total_changes()
-    assert(changes == 500, string.format('Number of operations is wrong (%d != 500)', changes))
-    print('Total changes in SQLite DB:', changes)
     return true
 end
 
 sqlite_rw_register.close = function(self)
-    self.db:close()
+    -- Close database. All SQL statements prepared using
+    -- db:prepare() should have been finalized before this
+    -- function is called. The function returns sqlite3.OK on
+    -- success or else a numerical error code.
+    if self.db:isopen() then
+        assert(self.db:close() == sqlite3.OK)
+    end
     return true
 end