Matt Wilson wrote:

1) Wildcards in the SQL passed to cursor.execute() now use the sqlite native '?' or ':N:' format. Previously Python syntax was allowed. Making this change lets us bind parameters to compiled SQL statements natively, without converting them to strings. This will also allow us to re-use a compiled statement by rebinding parameters later.


I've recently checked in change to SQLite that help with the TCL interface. These changes are still experimental, but they seem to be working out well. These changes might also be useful to Python. (Or not. I'll let the Python experts make that judgement.)

SQLite now accepts as a wildcard, a dollar sign '$' followed by
a TCL variable name.  The resulting wildcard is a place-holder,
just like "?" or ":NNN:".  The only difference is you get to use
a descriptive name for the place-holder.

After the statement is compiled using sqlite3_prepare(), you can
find out how many wildcards are in the original statement using
sqlite3_bind_parameter_count().  Once you know how many wildcards
there are, you can find the name of each wildcard using
sqlite3_bind_parameter_name() - a new API.

In the TCL interface, I use this as follows:

   *  Compile the SQL statement using sqlite3_prepare().
   *  For each wildcard:
       +   Look up the name of the wildcard using
           sqlite3_bind_parameter_name().
       +   Bind the value of the TCL variable with the
           same name.
   *  Use sqlite3_step() to execute the SQL statement.

In this way, I get to specify TCL variables directly in the
SQL statement, not as parameters added to the end.  For
example:

   db eval {UPDATE t1 SET value=$bigblob WHERE rowid=$id}

I do not know if this new technique will be helpful to Python
or not, but I thought I would bring it to your attention, just
in case it is.  Please note that the changes to support this
are in CVS but have not be added to a "release".  Also note
that these changes are still considered experimental and are
subject to change as more experience with the design becomes
available.



--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565



Reply via email to