dbcli/litecli

Feature request: support more parameter templates recognized by sqlite3_bind

zmwangx opened this issue · 5 comments

Favorite queries seem to be very useful as poor man's prepared statements, which sqlite3 CLI lacks. However, right now only shell-style parameter templates $1, $2, etc. are allowed. It would be nice to support more templates recognized by sqlite3_bind(), so that prepared statements can be directly taken from code or logs. At the very least, ? would be immensely helpful.

@zmwangx Can you post a couple of examples of prepared SQL statements. It is not obvious from the docs page.

Sure, I'm talking about statements like

INSERT INTO user (first_name, last_name, email, registered_at) VALUES (?,?,?,?);
SELECT * FROM user WHERE email = ?;
SELECT * FROM user WHERE registered_at BETWEEN ? AND ?;

You know, parametrized SQL that is commonly used in language bindings (e.g. Python's sqlite3 module). ? is just the simplest form, and probably the easiest to implement.


https://litecli.com/favorites/ gives this example:

\fs user_by_name select * from users where name = '$1'

It would be nice to be able to write

\fs user_by_name select * from users where name = ?

instead.

That should be doable, I have a vague remembrance of supporting this in pgcli or mycli and then we took it out for some reason. I'll dig up the old commits to see if the reasoning is still valid, if not, I'll take a stab at implementing this.

Cool, thanks for the effort.

This is now released as part of 1.1.0. Please upgrade using pip install -U litecli.