Hi all,

First of all, this is not about using SQLite as an embedded library from C, or whatever other language. It does not affect the sqlite3.c file at all. It only applies to the shell (so logically, it only affects shell.c)

So here’s my suggestion for what (I feel) is a significant improvement for the SHELL version of SQLite without being too much of a programming complication in my view. (Those who usually attack any new concept, please pause a moment and give it some thought, then attack as usual!)

Because I primarily use SQLite as a tool (from the shell), and given that SQLite does not (yet, if ever) support stored procedures, I often find myself (as I believe most people on this list) writing scripts that will do a certain task, and then run those using the shell with something like “sqlite3 my.db < script.sql”

I think we can all agree that the single most important advantage of SQLite is the one-file-holds-everything deal (both for the database file, and for the application or library file). On that principle,...

The problem with having all those scripts separate from the database file somehow violate the previous assertion. Plus, there is the problem that scripts cannot be made to have parameters (AFAIK).
So, two birds with one stone, ...

Wouldn’t it be nice if we could have those scripts somehow saved in the sqlite_master table (or some other new system table, if this one would cause compatibility issues), and then be able to call them very easily from the shell with some special prefix (e.g., :SCRIPTNAME parm1 parm2 parm3 ... – or some similar simple syntax). The : character could be some other special character (except for . used for built in commands.)

Then the shell, using the simplest of macro expansion techniques of plain text replacement, would read each line from the saved script, convert occurrence of the each parameter to the text appearing in the invocation and run it as if it was just typed on the keyboard.

For example, if my script was:

SELECT ~1~ from ~2~ where name like (‘%~3~%’);

giving the shell command:

:SCRIPTNAME * my_table some_name

would be executed as:

SELECT * from my_table where name like (‘%some_name%’);

I have used ~number~ as a parameter placeholder, but anything that works without ambiguities in the grammar would work.

And, then the next line of the script would be executing in a similar manner until the whole script is exhausted.

This capability would make the shell capable of supporting very complex script-based command-line applications all stored within the same single database file!

Thanks for listening (hopefully).

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

Reply via email to