unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Detlev Zundel <dzu@denx.de>
To: David Pirotte <david@altosw.be>
Cc: Andy Wingo <wingo@pobox.com>, guile-devel@gnu.org
Subject: Re: Problems with guile-sqlite3
Date: Mon, 04 Apr 2011 18:22:18 +0200	[thread overview]
Message-ID: <m2sjtyasw5.fsf@ohwell.denx.de> (raw)
In-Reply-To: <20110401200551.2f7c4135@rascar> (David Pirotte's message of "Fri, 1 Apr 2011 20:05:51 -0300")

[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-sqlite-map-really-apply-the-procedure-argument.patch --]
[-- Type: text/x-diff, Size: 592 bytes --]

From 1018e0617b08c0f79556ea1e6188963ce01bb952 Mon Sep 17 00:00:00 2001
From: Detlev Zundel <dzu@denx.de>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Add-some-basic-functionality-testing.patch --]
[-- Type: text/x-diff, Size: 2072 bytes --]

From f45fc5c709d241a147e061e92062993cce1b4841 Mon Sep 17 00:00:00 2001
From: Detlev Zundel <dzu@denx.de>
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  <wingo@pobox.com>
+;;;;   Copyright (C) 2011 Detlev Zundel <dzu@denx.de>
 ;;;;
 ;;;; 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-Fix-interpretation-of-null-pointers-from-the-library.patch --]
[-- Type: text/x-diff, Size: 1205 bytes --]

From 97aae36202ca7ba0abec5cf0da95a56ac706805f Mon Sep 17 00:00:00 2001
From: Detlev Zundel <dzu@denx.de>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-Fix-sqlite-bind.patch --]
[-- Type: text/x-diff, Size: 1293 bytes --]

From c37f372990d9edddd859e9b999eb38151ce33cf8 Mon Sep 17 00:00:00 2001
From: Detlev Zundel <dzu@denx.de>
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


  reply	other threads:[~2011-04-04 16:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-30 22:52 Problems with guile-sqlite3 Detlev Zundel
2011-03-31 10:25 ` Andy Wingo
2011-03-31 14:03   ` Detlev Zundel
2011-03-31 16:18     ` Detlev Zundel
2011-04-01  5:33       ` David Pirotte
2011-04-01  9:12         ` Detlev Zundel
2011-04-01 23:05           ` David Pirotte
2011-04-04 16:22             ` Detlev Zundel [this message]
2011-04-04 20:50               ` Andy Wingo
2011-04-04 21:28                 ` Detlev Zundel
2011-04-11 15:05                   ` Detlev Zundel
2011-04-20 15:22               ` David Pirotte
2011-04-20 15:51                 ` Detlev Zundel
2011-04-21 12:17                   ` Andy Wingo
2011-04-21 21:58                     ` David Pirotte
2011-04-01 11:34       ` Andy Wingo
2011-04-01 14:33         ` Detlev Zundel
2011-04-01 14:49           ` Andy Wingo
2011-03-31 14:28   ` Ludovic Courtès
2011-03-31 14:54     ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sjtyasw5.fsf@ohwell.denx.de \
    --to=dzu@denx.de \
    --cc=david@altosw.be \
    --cc=guile-devel@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).