diff options
| author | kamil <kamil@NetBSD.org> | 2015-12-08 23:04:40 +0000 |
|---|---|---|
| committer | kamil <kamil@NetBSD.org> | 2015-12-08 23:04:40 +0000 |
| commit | 6ea8ed496863973ed728a4cc3f6de7791d1e5095 (patch) | |
| tree | 98783cc0442c0fe8ab294269a473b66405831fa8 /share/examples/lua/sqlite.lua | |
| parent | 25520fdb9e47e14d266ac2947b69f7e7bdd59f50 (diff) | |
Correct mistakes in the sqlite.lua example
Changes:
- 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, looks
like a typo.
Patch by Travis Paul
Closes PR misc/50493
Diffstat (limited to 'share/examples/lua/sqlite.lua')
| -rw-r--r-- | share/examples/lua/sqlite.lua | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/share/examples/lua/sqlite.lua b/share/examples/lua/sqlite.lua index 37d331d869b..e333004c499 100644 --- a/share/examples/lua/sqlite.lua +++ b/share/examples/lua/sqlite.lua @@ -1,4 +1,4 @@ --- $NetBSD: sqlite.lua,v 1.2 2014/07/19 18:38:34 lneto Exp $ +-- $NetBSD: sqlite.lua,v 1.3 2015/12/08 23:04:40 kamil Exp $ local sqlite = require 'sqlite' @@ -13,8 +13,7 @@ print('this is sqlite ' .. sqlite.libversion() .. ' (' .. 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 @@ else 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 @@ else end s2:finalize() - stmt = db:prepare('drop table testx') + stmt = db:prepare('drop table test') stmt:step() stmt:finalize() db:close() @@ -57,4 +56,3 @@ end print('shutdown sqlite') sqlite.shutdown() - |
