GNU bug report logs - #61151
30.0.50; sqlite-more-p is confusing

Previous Next

Package: emacs;

Reported by: Helmut Eller <eller.helmut <at> gmail.com>

Date: Sun, 29 Jan 2023 14:53:02 UTC

Severity: normal

Found in version 30.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61151 in the body.
You can then email your comments to 61151 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Sun, 29 Jan 2023 14:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Helmut Eller <eller.helmut <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 29 Jan 2023 14:53:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; sqlite-more-p is confusing
Date: Sun, 29 Jan 2023 15:52:34 +0100
This code

  (let* ((db (sqlite-open))
         (stmt (sqlite-select db "values ('a',0), ('b',1)" nil 'set))
         (rows '()))
    (while (sqlite-more-p stmt)
      (push (sqlite-next stmt) rows))
    rows)

returns: (nil ("b" 1) ("a" 0))

I would expect: (("b" 1) ("a" 0))

I think it would be more natural, if sqlite-more-p would return false
before sqlite-next returns nil the first time.

Helmut



In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.35, cairo version 1.16.0) of 2023-01-29 built on caladan
Repository revision: 254c75fc2935e7edef079166d90b231278115a2f
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-xpm=ifavailable --with-jpeg=ifavailable
 --with-gif=ifavailable --with-tiff=ifavailable'

Configured features:
CAIRO DBUS FREETYPE GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSELINUX
LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND
SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XINPUT2 GTK3
ZLIB




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Sun, 29 Jan 2023 15:26:02 GMT) Full text and rfc822 format available.

Message #8 received at 61151 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 61151 <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Sun, 29 Jan 2023 17:25:44 +0200
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Date: Sun, 29 Jan 2023 15:52:34 +0100
> 
> This code
> 
>   (let* ((db (sqlite-open))
>          (stmt (sqlite-select db "values ('a',0), ('b',1)" nil 'set))
>          (rows '()))
>     (while (sqlite-more-p stmt)
>       (push (sqlite-next stmt) rows))
>     rows)
> 
> returns: (nil ("b" 1) ("a" 0))
> 
> I would expect: (("b" 1) ("a" 0))
> 
> I think it would be more natural, if sqlite-more-p would return false
> before sqlite-next returns nil the first time.

I'm not sure I understand why you need sqlite-more-p here.
sqlite-next returns nil when it hits the end, so it should be enough.
If we document this fact in the doc string of sqlite-next, would that
be good enough to satisfy your use cases?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Sun, 29 Jan 2023 16:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 61151 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61151 <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Sun, 29 Jan 2023 17:05:07 +0100
On Sun, Jan 29 2023, Eli Zaretskii wrote:

> I'm not sure I understand why you need sqlite-more-p here.
> sqlite-next returns nil when it hits the end, so it should be enough.
> If we document this fact in the doc string of sqlite-next, would that
> be good enough to satisfy your use cases?

Yes, I guess it would be possible to get rid of sqlite-more-p.

However, sqlite-next seems to return nil once, but then it starts over.
E.g this

  (let* ((db (sqlite-open))
         (stmt (sqlite-select db "values ('a',0), ('b',1)" nil 'set))
         (rows '()))
    (list
     (sqlite-next stmt)
     (sqlite-next stmt)
     (sqlite-next stmt)
     (sqlite-next stmt)))
   
returns: (("a" 0) ("b" 1) nil ("a" 0))

This "wrap around" behavior is strange.

In summary, I think that sqlite-next should signal and error instead of
returning nil.  And sqlite-more-p should be used to detect the end of
the stream.  (Theoretically, sqlite-next could then also return zero
length rows, though that's probably not needed in practice.)

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Sun, 29 Jan 2023 16:49:01 GMT) Full text and rfc822 format available.

Message #14 received at 61151 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 61151 <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Sun, 29 Jan 2023 18:48:31 +0200
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Cc: 61151 <at> debbugs.gnu.org
> Date: Sun, 29 Jan 2023 17:05:07 +0100
> 
> On Sun, Jan 29 2023, Eli Zaretskii wrote:
> 
> > I'm not sure I understand why you need sqlite-more-p here.
> > sqlite-next returns nil when it hits the end, so it should be enough.
> > If we document this fact in the doc string of sqlite-next, would that
> > be good enough to satisfy your use cases?
> 
> Yes, I guess it would be possible to get rid of sqlite-more-p.
> 
> However, sqlite-next seems to return nil once, but then it starts over.

This should be easy to fix.

> In summary, I think that sqlite-next should signal and error instead of
> returning nil.

I think we can only signal an error if sqlite-next is called again
after it returned nil, otherwise it is not justified.  But I'm not an
expert on databases, so maybe I'm missing something.

> And sqlite-more-p should be used to detect the end of
> the stream.

I don't think it's possible without trying to read.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Sun, 29 Jan 2023 18:21:02 GMT) Full text and rfc822 format available.

Message #17 received at 61151 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61151 <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Sun, 29 Jan 2023 19:20:30 +0100
On Sun, Jan 29 2023, Eli Zaretskii wrote:

>> However, sqlite-next seems to return nil once, but then it starts over.
>
> This should be easy to fix.

The documentation[1] also says: 

  SQLITE_DONE means that the statement has finished executing
  successfully. sqlite3_step() should not be called again on this
  virtual machine without first calling sqlite3_reset() to reset the
  virtual machine back to its initial state.

So this would seems like prudent fix.

>> In summary, I think that sqlite-next should signal and error instead of
>> returning nil.
>
> I think we can only signal an error if sqlite-next is called again
> after it returned nil, otherwise it is not justified.  But I'm not an
> expert on databases, so maybe I'm missing something.
>
>> And sqlite-more-p should be used to detect the end of
>> the stream.
>
> I don't think it's possible without trying to read.

If we don't change the way the API works, then maybe the documentation
should mention that the proper way to iterate over the results is a bit
unusual. E.g.:

(let* ((db (sqlite-open))
       (stmt (sqlite-select db "values ('a',0), ('b',1)" nil 'set))
       (rows '())
       row)
  (while (progn (setq row (sqlite-next stmt))
		(sqlite-more-p stmt))
    (push row rows))
  rows)

And perhaps provide a function like sqlite-for-each that hides this
peculiarity.

Helmut

[1] https://sqlite.org/c3ref/step.html




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Sun, 29 Jan 2023 18:45:01 GMT) Full text and rfc822 format available.

Message #20 received at 61151 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 61151 <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Sun, 29 Jan 2023 20:44:19 +0200
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Cc: 61151 <at> debbugs.gnu.org
> Date: Sun, 29 Jan 2023 19:20:30 +0100
> 
> On Sun, Jan 29 2023, Eli Zaretskii wrote:
> 
> >> However, sqlite-next seems to return nil once, but then it starts over.
> >
> > This should be easy to fix.
> 
> The documentation[1] also says: 
> 
>   SQLITE_DONE means that the statement has finished executing
>   successfully. sqlite3_step() should not be called again on this
>   virtual machine without first calling sqlite3_reset() to reset the
>   virtual machine back to its initial state.
> 
> So this would seems like prudent fix.

What is "this"?  Signaling an error after sqlite-next returns nil?  Or
something else?

> If we don't change the way the API works, then maybe the documentation
> should mention that the proper way to iterate over the results is a bit
> unusual. E.g.:
> 
> (let* ((db (sqlite-open))
>        (stmt (sqlite-select db "values ('a',0), ('b',1)" nil 'set))
>        (rows '())
>        row)
>   (while (progn (setq row (sqlite-next stmt))
> 		(sqlite-more-p stmt))
>     (push row rows))
>   rows)
> 
> And perhaps provide a function like sqlite-for-each that hides this
> peculiarity.

Let me think about this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61151; Package emacs. (Mon, 30 Jan 2023 06:58:02 GMT) Full text and rfc822 format available.

Message #23 received at 61151 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61151 <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Mon, 30 Jan 2023 07:57:09 +0100
On Sun, Jan 29 2023, Eli Zaretskii wrote:

>> On Sun, Jan 29 2023, Eli Zaretskii wrote:
>> 
>> >> However, sqlite-next seems to return nil once, but then it starts over.
>> >
>> > This should be easy to fix.
>> 
>> The documentation[1] also says: 
>> 
>>   SQLITE_DONE means that the statement has finished executing
>>   successfully. sqlite3_step() should not be called again on this
>>   virtual machine without first calling sqlite3_reset() to reset the
>>   virtual machine back to its initial state.
>> 
>> So this would seems like prudent fix.
>
> What is "this"?  Signaling an error after sqlite-next returns nil?  Or
> something else?

I meant to not call sqlite3_step again after that it has returned
SQLITE_DONE.  Either by returning nil or signaling an error.

Helmut




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Thu, 02 Feb 2023 19:50:02 GMT) Full text and rfc822 format available.

Notification sent to Helmut Eller <eller.helmut <at> gmail.com>:
bug acknowledged by developer. (Thu, 02 Feb 2023 19:50:02 GMT) Full text and rfc822 format available.

Message #28 received at 61151-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 61151-done <at> debbugs.gnu.org
Subject: Re: bug#61151: 30.0.50; sqlite-more-p is confusing
Date: Thu, 02 Feb 2023 21:49:00 +0200
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Cc: 61151 <at> debbugs.gnu.org
> Date: Mon, 30 Jan 2023 07:57:09 +0100
> 
> On Sun, Jan 29 2023, Eli Zaretskii wrote:
> 
> >> On Sun, Jan 29 2023, Eli Zaretskii wrote:
> >> 
> >> >> However, sqlite-next seems to return nil once, but then it starts over.
> >> >
> >> > This should be easy to fix.
> >> 
> >> The documentation[1] also says: 
> >> 
> >>   SQLITE_DONE means that the statement has finished executing
> >>   successfully. sqlite3_step() should not be called again on this
> >>   virtual machine without first calling sqlite3_reset() to reset the
> >>   virtual machine back to its initial state.
> >> 
> >> So this would seems like prudent fix.
> >
> > What is "this"?  Signaling an error after sqlite-next returns nil?  Or
> > something else?
> 
> I meant to not call sqlite3_step again after that it has returned
> SQLITE_DONE.  Either by returning nil or signaling an error.

I went with the former.

I also documented that it returns nil when the statement finishes
execution.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 03 Mar 2023 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 112 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.