NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
misc/50493: Lua SQLite example is incorrect
>Number: 50493
>Category: misc
>Synopsis: Lua SQLite example is incorrect
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: misc-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Dec 03 03:10:01 +0000 2015
>Originator: Travis Pau
>Release: current
>Organization:
>Environment:
NetBSD kagato.netverb.com 7.99.23 NetBSD 7.99.23 (GENERIC) #0: Wed Dec 2 01:13:34 EST 2015 tpaul%nagi.netverb.com@localhost:/build/obj/amd64/x86_64/current/sys/arch/amd64/compile/GENERIC amd64
>Description:
I discovered 3 issues with the sqlite.lua example:
The open flag: sqlite.OPEN_CREATE will open the DB for reading and writing, adding sqlite.OPEN_READWRITE to sqlite.OPEN_CREATE will cause the DB to not be created and prevent the script from continuing.
When using stmt:bind_parameter_index() the parameter needs to be prefixed with ':' if that was used in the prepared statement, otherwise the incorrect index of 0 is returned.
The drop table statement has an "x" appended to the table name, I believe this is a typo.
>How-To-Repeat:
lua /usr/src/share/examples/lua/sqlite.lua
>Fix:
Index: sqlite.lua
===================================================================
RCS file: /cvsroot/src/share/examples/lua/sqlite.lua,v
retrieving revision 1.2
diff -u -r1.2 sqlite.lua
--- sqlite.lua 19 Jul 2014 18:38:34 -0000 1.2
+++ sqlite.lua 3 Dec 2015 03:02:50 -0000
@@ -13,8 +13,7 @@
sqlite.libversion_number() .. ')')
print('sourceid ' .. sqlite.sourceid())
-db, state = sqlite.open('/tmp/db.sqlite',
- sqlite.OPEN_READWRITE + sqlite.OPEN_CREATE)
+db, state = sqlite.open('/tmp/db.sqlite', sqlite.OPEN_CREATE)
if state ~= sqlite.OK then
print('db open failed')
@@ -33,7 +32,7 @@
print('statement has ' .. stmt:bind_parameter_count() .. ' parameters')
print('param 1 name: ' .. stmt:bind_parameter_name(1))
- print('param name is at index ' .. stmt:bind_parameter_index('name'))
+ print('param name is at index ' .. stmt:bind_parameter_index(':name'))
stmt:bind(1, 'Hardmeier')
stmt:step()
@@ -49,7 +48,7 @@
end
s2:finalize()
- stmt = db:prepare('drop table testx')
+ stmt = db:prepare('drop table test')
stmt:step()
stmt:finalize()
db:close()
Home |
Main Index |
Thread Index |
Old Index