Created
July 24, 2021 19:39
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following recipe shows an error with the LuaSQL library for | |
SQLite3. | |
Tested with Debian 10.10 (buster), SQLite3 3.35.5, LuaSQL 2.6.0. | |
Note that the second row of the table Cursor doesn't print, and there | |
is a "there are open cursors" error message. | |
Is this a bug, or am I missing something? I don't think it's necessary | |
to close the cursor explicitly in this case, and even if that was the | |
problem, the second row should still print. | |
https://keplerproject.github.io/luasql/manual.html#cursor_object | |
> A call to fetch after the last row has already being returned will | |
> close the corresponding cursor. | |
############################################################ | |
cursor.lua | |
############################################################ | |
local luasql = require "luasql.sqlite3" | |
local function rows (connection, sql_statement) | |
print("calling rows") | |
-- retrieve a cursor | |
local cursor = assert (connection:execute (sql_statement)) | |
return function () | |
return cursor:fetch() | |
end | |
end | |
function Cursor (dbname) | |
local env = assert (luasql.sqlite3()) | |
local con = assert (env:connect(dbname)) | |
for Date, Num in rows (con, string.format("select Date, Num from %s", "opencursors")) do | |
print(Date, Num) | |
end | |
con:close() | |
env:close() | |
end | |
Cursor("cursor.db") | |
############################################################ | |
date.sql | |
############################################################ | |
PRAGMA foreign_keys=OFF; | |
BEGIN TRANSACTION; | |
CREATE TABLE opencursors ( | |
"Date" DATE, | |
"Num" NUM | |
); | |
INSERT INTO opencursors VALUES('2019-04-02', 0); | |
INSERT INTO opencursors VALUES(NULL, 1); | |
COMMIT; | |
############################################################ | |
cursor.sh | |
############################################################ | |
rm cursor.db | |
cat date.sql | sqlite3 cursor.db | |
lua5.3 cursor.lua | |
############################################################ | |
sh cursor.sh | |
calling rows | |
2019-04-02 0 | |
lua5.3: cursor.lua:18: LuaSQL: there are open cursors | |
stack traceback: | |
[C]: in method 'close' | |
cursor.lua:18: in function 'Cursor' | |
cursor.lua:22: in main chunk | |
[C]: in ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment