Sqlite will perform the substitution of Tcl variables in a query. You can flag 
the variable with a ‘$’ or with a ‘:’ (which makes it more like other SQL APIs).

So you can write:

    $db eval { 
            SELECT   Tea
            FROM     teaInStock 
            ORDER BY LastUsed DESC
            LIMIT   :nrToFetch;
    } {
            ...
    }

or even

    $db eval { 
            SELECT   Tea
            FROM     teaInStock
            ORDER BY LastUsed DESC
            LIMIT   $nrToFetch;
    } {
            ... do something with $Tea ...
    }

This latter case works because the query is surrounded by {} so Tcl won’t 
substitute the variable, it will be seen and securely inserted into the query 
by SQLite.

This is rather nifty, which is why I recently added pretty much exactly this 
functionality to Pgtcl (though due to differences between PostgreSQL and SQLite 
syntax I had to restrict it to using “:”). The equivalent code would be:

pg_select $db -variables {
            SELECT   Tea
            FROM     teaInStock 
            ORDER BY LastUsed DESC
            LIMIT   :nrToFetch;
    } row {
            ... do something with $row(Tea) ...
    }


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to