From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Detlev Zundel Newsgroups: gmane.lisp.guile.devel Subject: Re: Problems with guile-sqlite3 Date: Mon, 04 Apr 2011 18:22:18 +0200 Message-ID: References: <20110401023323.32041242@rascar> <20110401200551.2f7c4135@rascar> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1301934301 32606 80.91.229.12 (4 Apr 2011 16:25:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 4 Apr 2011 16:25:01 +0000 (UTC) Cc: Andy Wingo , guile-devel@gnu.org To: David Pirotte Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 04 18:24:56 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q6maB-000150-Ln for guile-devel@m.gmane.org; Mon, 04 Apr 2011 18:24:53 +0200 Original-Received: from localhost ([127.0.0.1]:54594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6ma9-0008Bg-UA for guile-devel@m.gmane.org; Mon, 04 Apr 2011 12:24:49 -0400 Original-Received: from [140.186.70.92] (port=44372 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6mXr-00075W-2M for guile-devel@gnu.org; Mon, 04 Apr 2011 12:22:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6mXl-0007GZ-OJ for guile-devel@gnu.org; Mon, 04 Apr 2011 12:22:26 -0400 Original-Received: from mail-out.m-online.net ([212.18.0.9]:45664) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q6mXl-0007Ep-Bl for guile-devel@gnu.org; Mon, 04 Apr 2011 12:22:21 -0400 Original-Received: from frontend1.mail.m-online.net (unknown [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id C415F1C08CD1; Mon, 4 Apr 2011 18:22:18 +0200 (CEST) X-Auth-Info: Y4mJHMy4RSlCVHnipIXL3tEk9rlemzs2FtvqRW8n6eI= Original-Received: from mail.denx.de (host-82-135-33-74.customer.m-online.net [82.135.33.74]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA id AC5871C000B0; Mon, 4 Apr 2011 18:22:18 +0200 (CEST) Original-Received: from ohwell.denx.de (ohwell [10.0.40.4]) by mail.denx.de (Postfix) with ESMTP id 921094BC1526; Mon, 4 Apr 2011 18:22:18 +0200 (CEST) Original-Received: from dzu by ohwell.denx.de with local (Exim 4.72) (envelope-from ) id 1Q6mXi-0003Yx-DB; Mon, 04 Apr 2011 18:22:18 +0200 In-Reply-To: <20110401200551.2f7c4135@rascar> (David Pirotte's message of "Fri, 1 Apr 2011 20:05:51 -0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 212.18.0.9 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:12153 Archived-At: --=-=-= Content-Type: text/plain Hi David, > I spotted where the problem comes from: it is when a text value is empty. I have > produced a small but complete example [attached]: can you reproduce it ? Yes, thanks for the test case, I can now reproduce it and hopefully the attached patches work for you also. The first one fixes the ignorance of 'proc' of the 'sqlite-map' procedure. It took me a while to figure this one out ;) The second patch extends 'tests/basic.test' with some statements that make the problem discovered by you show up. The third patch fixes the problem for me. Andy, is this the 'right way' to test for null pointers? I could not find a cleaner solution in my limited search... The fourth patch fixes a problem I discovered while playing with sqlite-bind. Really this should generate more testcases. Andy, I have now cloned your repo at gitorious[1] for you to pull if that's easier. I am perfectly happy to rework patches if anything needs to be done for that. Thanks Detlev [1] https://gitorious.org/~dzu/guile-sqlite3/guile-sqlite3-dzu -- Bacchus, n. A convenient deity invented by the ancients as an excuse for getting drunk. -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu@denx.de --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Make-sqlite-map-really-apply-the-procedure-argument.patch >From 1018e0617b08c0f79556ea1e6188963ce01bb952 Mon Sep 17 00:00:00 2001 From: Detlev Zundel Date: Mon, 4 Apr 2011 18:11:58 +0200 Subject: [PATCH 1/4] Make sqlite-map really apply the procedure argument --- sqlite3.scm | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/sqlite3.scm b/sqlite3.scm index 3369e02..2492d15 100644 --- a/sqlite3.scm +++ b/sqlite3.scm @@ -425,4 +425,5 @@ seed)))) (define (sqlite-map proc stmt) - (reverse! (sqlite-fold cons '() stmt))) + (map proc + (reverse! (sqlite-fold cons '() stmt)))) -- 1.7.4.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Add-some-basic-functionality-testing.patch >From f45fc5c709d241a147e061e92062993cce1b4841 Mon Sep 17 00:00:00 2001 From: Detlev Zundel Date: Mon, 4 Apr 2011 18:12:39 +0200 Subject: [PATCH 2/4] Add some basic functionality testing --- tests/basic.test | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-) diff --git a/tests/basic.test b/tests/basic.test index 1e5a3e0..46b395c 100644 --- a/tests/basic.test +++ b/tests/basic.test @@ -1,6 +1,6 @@ ;;;; basic.test --- -*- mode: scheme; coding: utf-8; -*- ;;;; -;;;; Copyright (C) 2010 Andy Wingo +;;;; Copyright (C) 2011 Detlev Zundel ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -17,6 +17,47 @@ ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (define-module (tests basic-test) + #:use-module (ice-9 format) #:use-module (sqlite3)) +(define (sqlite-exec db sql) + (let ((stmt (sqlite-prepare db sql))) + (sqlite-map display stmt))) + +;; Cleanup database so we can check creation +(define db-name "tests/simple.db") +(if (file-exists? db-name) + (begin + (format #t "Removing leftover database ~a~%" db-name) + (delete-file db-name))) + +(format #t "Creating test database ~a:" db-name) +(define db (sqlite-open db-name (logior SQLITE_OPEN_CREATE + SQLITE_OPEN_READWRITE))) +(format #t "~40tOk~%") + +(format #t "Creating table 'project':") +(sqlite-exec + db + "create table project ( + reference integer primary key, + name text, + website text + )") +(format #t "~40tOk~%") + +(format #t "Inserting a dataset:") +(sqlite-exec db "insert into project values (1, 'Guile', '')") +(format #t "~40tOk~%") + +(format #t "Reading dataset: ") +(sqlite-exec db "select * from project") +(format #t "~40tOk~%") + +(sqlite-close db) + +(format #t "Removing database ~a" db-name) +(delete-file db-name) +(format #t "~40tOk~%") + (exit 0) -- 1.7.4.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-Fix-interpretation-of-null-pointers-from-the-library.patch >From 97aae36202ca7ba0abec5cf0da95a56ac706805f Mon Sep 17 00:00:00 2001 From: Detlev Zundel Date: Mon, 4 Apr 2011 18:13:18 +0200 Subject: [PATCH 3/4] Fix interpretation of null pointers from the library --- sqlite3.scm | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sqlite3.scm b/sqlite3.scm index 2492d15..9e48ff5 100644 --- a/sqlite3.scm +++ b/sqlite3.scm @@ -373,11 +373,15 @@ (value-double (stmt-pointer stmt) i)) ((3) ; SQLITE3_TEXT (let ((p (value-blob (stmt-pointer stmt) i))) - (utf8->string - (pointer->bytevector p (value-bytes (stmt-pointer stmt) i))))) + (if (eq? p %null-pointer) + "" + (utf8->string + (pointer->bytevector p (value-bytes (stmt-pointer stmt) i)))))) ((4) ; SQLITE_BLOB (let ((p (value-blob (stmt-pointer stmt) i))) - (pointer->bytevector p (value-bytes (stmt-pointer stmt) i)))) + (if (eq? p %null-pointer) + (make-bytevector 0) + (pointer->bytevector p (value-bytes (stmt-pointer stmt) i))))) ((5) ; SQLITE_NULL #f))))) -- 1.7.4.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0004-Fix-sqlite-bind.patch >From c37f372990d9edddd859e9b999eb38151ce33cf8 Mon Sep 17 00:00:00 2001 From: Detlev Zundel Date: Mon, 4 Apr 2011 18:09:06 +0200 Subject: [PATCH 4/4] Fix sqlite-bind. - sqlite-transient needs to be a pointer - fix typo for string case --- sqlite3.scm | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlite3.scm b/sqlite3.scm index 9e48ff5..97550b4 100644 --- a/sqlite3.scm +++ b/sqlite3.scm @@ -290,7 +290,8 @@ int (dynamic-func "sqlite3_bind_null" libsqlite3) (list '* int))) - (sqlite-transient (make-bytevector (sizeof '*) #xff))) + (sqlite-transient (bytevector->pointer + (make-bytevector (sizeof '*) #xff)))) (lambda (stmt key val) (assert-live-stmt! stmt) (let ((idx (key->index stmt key)) @@ -300,7 +301,7 @@ (bind-blob p idx (bytevector->pointer val) (bytevector-length val) sqlite-transient)) ((string? val) - (let ((bv ((string->utf8 val)))) + (let ((bv (string->utf8 val))) (bind-text p idx (bytevector->pointer bv) (bytevector-length bv) sqlite-transient))) ((and (integer? val) (exact? val)) -- 1.7.4.1 --=-=-=--