"Compact" query strings for prepared-statement cache?

If SQL queries are stored in Tcl variables declared across multiple lines to keep them readable, using:

set ::SQL::QueryName {

and executed using

db eval $::SQL::QueryName

should something be done to the query strings since they will be the keys in the prepared-statements cache?

For example, ending each line with the line-continuation character \, build with append statements, or running some type of mapping on them to make a single line with no unnecesary spaces?

Hadn't thought about it before because caching is sort of automatic in Tcl SQLite.

Thank you.


  • I wouldn't bother doing clever stuff like that; statement caching is usually totally happy as an automatic thing that happens behind the scenes. Just write the SQL directly as program literals (the obvious first option!) and it should all work out fine.

    One principle of Tcl is that we try to make obvious-looking code be fast code, with as few contortions as possible (as this makes it easier for users to adopt and adapt). The only real common rules we have for fast code are "put things in procedures" and "put braces round expressions". There are a few other tricks (such as the now-very-inaccurately-named K trick), but you don't normally need them. A consequence of this attitude is that caches are transparent and in fact pretty ubiquitous; they're the job of C extensions to worry about, not normal user code.

    In short, don't sweat it. Seriously.