sqlitetclcreate-function

Sqlite (within SqliteStudio): invalid command name "parray"


I am discovering writing functions in TCL for Sqlite (https://github.com/pawelsalawa/sqlitestudio/wiki/ScriptingTcl).

I wanted to play a basic exemple found in the official page of sqlite(http://sqlite.org/tclsqlite.html):

db eval {SELECT * FROM MyTable ORDER BY MyID} values { 
    parray values
    puts ""
}

I get the following error:

Error while requesting the database « -- » : invalid command name "parray"

Help is very welcome :)


Solution

  • SqliteStudio does not seem to fully initialise Tcl, as you would expect it from a non-embedded installation:

    Using external Tcl packages or modules is not possible, because Tcl interpreters are not initialized with "init.tcl".

    See Wiki.

    Background

    Standard Tcl sources init.tcl, early as part of an Tcl interpreter's initialisation. init.tcl, in turn, registers a number of Tcl procs for autoloading. parray is one of those lazily acquired procs.

    Ways forward

    I am not familiar with SqliteStudio. Why not stick with sqlite's standard Tcl frontend, which gives you full Tcl and comes with Tcl distributions free house? But this certainly depends on your requirements.

    That said, you could attempt to force-load init.tcl in SqliteStudio's embedded Tcl, but I don't know (and can't test) whether the distribution has not pruned these scripts or whether they were effectively relocated. From the top of my head (untested):

    source [file join $tcl_library init.tcl]
    # ...
    db eval {SELECT * FROM MyTable ORDER BY MyID} values { 
        parray values
        puts ""
    }