User defined functions

Sqliteman provides the following user-defined function in addition to the built-in functions supported by sqlite:-

exec (NAME, STATEMENT)

This function is called with two arguments which are both sql strings. NAME must be either NULL or a valid sql identifier which is not the name of an existing table or view or index. Otherwise the exec() function will fail with an appropriate error message. The exec() function can also fail if sqlite runs out of memory or encounters a similar fatal error.

  • If NAME is NULL, exec() returns the first row of the first column of the table returned by executing STATEMENT as an sql statement. If executing STATEMENT fails, or succeeds but does not generate a table, exec() returns NULL.
  • If NAME is a valid sql identifier which is not the name of an existing table or view, the exec() function creates table NAME containing the result of attempting to execute STATEMENT as an sql statement, and exec() itself returns NULL. In this case if STATEMENT succeeds but does not generate a table, exec() does not create a table and returns NULL, and if STATEMENT fails exec() does not create a table and returns the error message caused by the failure. Normally EXPLAIN, most PRAGMAs, SELECT, and VALUES statements generate tables if they succeed.

exec() can be used in scripts to execute dynamically generated statements, check for errors, and examine results of PRAGMAs. The form with a NULL first argument can be used to extract a value from a table without causing the script to fail if the table does not exist. exec() is used by sqliteman's internal tests. These are included in the source distribution and can be examined as examples for how to use it.

Sqliteman also provides two additonal collators LOCALIZED and LOCALIZED_CASE. These sort in Locale order. LOCALIZED is like the LOCALIZED collator provided by the Android implementation of sqlite (which is not case-sensitive), while the LOCALIZED_CASE collator is case-sensitive. Care should be taken when using these collators. It is always safe to use them in queries inside sqliteman itself. However if an object which references LOCALIZED or LOCALIZED_CASE (such as a view) is created in the database, it will not be possible to access that object with an sqlite implementation which does not support that collator.