Email list hosting service & mailing list manager

World's simplest Scheme interface to sqlite3 John Cowan (29 Aug 2020 03:00 UTC)
(missing)
(missing)
Fwd: World's simplest Scheme interface to sqlite3 John Cowan (29 Aug 2020 17:57 UTC)
Re: Fwd: World's simplest Scheme interface to sqlite3 Lassi Kortela (29 Aug 2020 18:44 UTC)
Re: Fwd: World's simplest Scheme interface to sqlite3 John Cowan (29 Aug 2020 22:37 UTC)
SQL API sketch with some code Lassi Kortela (30 Aug 2020 13:24 UTC)
Re: SQL API sketch with some code Lassi Kortela (30 Aug 2020 13:46 UTC)
Re: SQL API sketch with some code John Cowan (30 Aug 2020 20:47 UTC)
Re: SQL API sketch with some code Lassi Kortela (31 Aug 2020 05:02 UTC)
Re: SQL API sketch with some code Lassi Kortela (31 Aug 2020 05:14 UTC)
Re: SQL API sketch with some code John Cowan (31 Aug 2020 15:38 UTC)
Re: SQL API sketch with some code Lassi Kortela (31 Aug 2020 15:54 UTC)
Re: SQL API sketch with some code John Cowan (31 Aug 2020 17:12 UTC)
Re: SQL API sketch with some code Lassi Kortela (31 Aug 2020 19:20 UTC)
Reflection on the database schema Lassi Kortela (30 Aug 2020 13:35 UTC)
Re: Reflection on the database schema John Cowan (30 Aug 2020 19:51 UTC)
Re: Fwd: World's simplest Scheme interface to sqlite3 Alaric Snell-Pym (31 Aug 2020 22:03 UTC)
Re: Fwd: World's simplest Scheme interface to sqlite3 Lassi Kortela (02 Sep 2020 08:38 UTC)
Re: Fwd: World's simplest Scheme interface to sqlite3 John Cowan (02 Sep 2020 17:09 UTC)
SQL statement caching Lassi Kortela (02 Sep 2020 17:21 UTC)
Re: SQL statement caching John Cowan (02 Sep 2020 18:13 UTC)
Re: SQL statement caching Lassi Kortela (02 Sep 2020 18:53 UTC)
Re: World's simplest Scheme interface to sqlite3 Lassi Kortela (29 Aug 2020 11:40 UTC)
Re: World's simplest Scheme interface to sqlite3 Ivan Raikov (29 Aug 2020 04:06 UTC)
Re: World's simplest Scheme interface to sqlite3 Lassi Kortela (29 Aug 2020 11:24 UTC)
Re: World's simplest Scheme interface to sqlite3 John Cowan (29 Aug 2020 17:47 UTC)
Re: World's simplest Scheme interface to sqlite3 Lassi Kortela (29 Aug 2020 18:23 UTC)
Re: World's simplest Scheme interface to sqlite3 John Cowan (29 Aug 2020 22:15 UTC)
Re: World's simplest Scheme interface to sqlite3 Amirouche Boubekki (29 Aug 2020 07:33 UTC)
Re: World's simplest Scheme interface to sqlite3 Lassi Kortela (29 Aug 2020 11:37 UTC)

SQL statement caching Lassi Kortela 02 Sep 2020 17:21 UTC

> After studying the question a bit more, I realize that there is good
> reason for the C API to separate statement preparation from statement
> binding; preparation does all the parsing and compiling to bytecode,
> which is one of the more expensive parts of sending a query, whereas
> binding substitutes values for the parameters.
>
> As I don't want to expose the prepared-statement foreign objects in the
> API, a practical (as opposed to POC) implementation will need to provide
> a statement cache.  Most SQLite interfaces do this, but it is not part
> of SQLite itself.  The cache is basically a bounded-size mapping that
> maps SQL strings (or hashes of them) to the internal prepared-statement
> objects.  When the cache is full, an element is kicked out and the
> corresponding prepared-statement object is freed.
>
> So when we call -exec/-eval, the cache is searched; on a miss, we
> prepare the statement and add it to the cache.  Then it is bound and
> executed.

So a table where SQL strings are weak references pointing to sqlite_stmt
foreign objects? And it's probably good enough to compare the strings
using eq?.

If you want to optimize for speed, then (sql-do `("mumble @a @b @c
mumble" a ,a b ,b c ,c)) is a bit wasteful as well. SQLite uses
positional parameters internally, and the user must convert named
parameters to positional ones using sqlite3_bind_parameter_index().

If the statement stays the same, then the name->position mapping stays
the same as well and should be cached. Further, destructuring an
alist/plist on every call to unpack parameter values is unnecessary effort.