On 5/8/18, David Burgess <dburges...@gmail.com> wrote:
>> The usual way of handling that in SQLite is to store a script in a text
>> column someplace, then execute them as needed.
> Is there a simple way to do this from SQLite shell?

Not at this time, as the CLI does not link against libtcl.

But funny you should bring it up.  I have in my notes the idea of
reimplementing the CLI a s TCL script.  In fact, I've done a little
work in that direction.  From the canonical source tree, you can type:

    make sqltclsh

(or "sqltclsh.exe" on windows) to get a self-contained binary that
includes TCL and SQLite.  There is a small TCL script that runs that
provides a CLI to TCL.  The only thing you would need to do is adapt
that 72-line script to provide a CLI to SQLite instead.  Or, better,
provide a CLI that gives easy access to *both* TCL and SQLite.  That,
plus you'll need to add the usual readline/editline gadgetry.  That
would give a really cool utility program with access to a full-fledged
programming language (TCL) coupled with a the industry-leading
embedded SQL database engine.

When the sqltclsh program runs, it first checks to see if an SQLite
Archive database has been appended to the executable file itself, and
if it has and that archive contains a "main.tcl" script, it runs that
script.  If not, it then checks command-line arguments, and if the
first argument is a TCL script, it runs that script. If it doesn't
find that, then it runs a built-in "tclsh-emulator" script.  You can
read about this whole process in the source file

So to develop a CLI-replacement written in TCL, you just start writing
a TCL script and test it using the command "sqltclsh main.tcl".  After
you get it working acceptably, you can append that file to the
sqltclsh executable like this:

   sqlite3 -Aaf sqltclsh main.tcl

Then, the next time you run sqltclsh, it will launch your application
rather the built-in "tclsh-emulator".

Or, you can do other TCL+SQLite stand-alone applications in the same way.

I eagerly wait to see what y'all come up with!
D. Richard Hipp
sqlite-users mailing list

Reply via email to