NetBSD Problem Report #50493

From www@NetBSD.org  Thu Dec  3 03:05:40 2015
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.NetBSD.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8B1E7A5854
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  3 Dec 2015 03:05:40 +0000 (UTC)
Message-Id: <20151203030539.4F4C9A6551@mollari.NetBSD.org>
Date: Thu,  3 Dec 2015 03:05:39 +0000 (UTC)
From: Tr@visPau.me
Reply-To: Tr@visPau.me
To: gnats-bugs@NetBSD.org
Subject: Lua SQLite example is incorrect
X-Send-Pr-Version: www-1.0

>Number:         50493
>Category:       misc
>Synopsis:       Lua SQLite example is incorrect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 03 03:10:01 +0000 2015
>Closed-Date:    Tue Dec 08 23:06:50 +0000 2015
>Last-Modified:  Tue Dec 08 23:06:50 +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:/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()

>Release-Note:

>Audit-Trail:
From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50493 CVS commit: src/share/examples/lua
Date: Tue, 8 Dec 2015 23:04:40 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Tue Dec  8 23:04:40 UTC 2015

 Modified Files:
 	src/share/examples/lua: sqlite.lua

 Log Message:
 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


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 src/share/examples/lua/sqlite.lua

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: kamil@NetBSD.org
State-Changed-When: Wed, 09 Dec 2015 00:06:50 +0100
State-Changed-Why:
PR has been resolved with committing the patch provided by the originator (Paul Travis).


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.