Unit 5 wrote:
1) If I have a statement that includes "WHERE 0 = 1",
does sqlite optimize the query and return right away
or would it execute the query anyway?
It will be executed.
2) Is there a way to get column names form a statement
without (or before) executing the statement? For
example, when a user enters a statement like "select *
from ...".
Prepare thee statement using the sqlite3_prepare() API, then use the
sqlite3_column_name() API to get the names of the result columns. The
query won't execute until you use the sqlite3_step() API.
3) I would like to test the validity of sql statements
before executing them. So I thought I could use "db
complete" command. But now I am not sure what "db
complete" command does. In my tests, it returns 0
(false) regardless of the sql statement. In fact the
only times I have gotton true is if the statement is
empty. The statements are (all are valid and return
data):
% db complete "select 2 * 2 "
% db complete "select a from tab1"
% db complete "select a from tab1 where a < 10"
% db complete "select a from tab1 where a < 10
order by a"
This API function basically check for lexical completeness for the shell
input routines. It simply checks for a lexically valid statement that
ends with a semicolon. You statements don't end with semicolons, hence
they return false.
What you probably want to do is use sqlite3_prepare() to check if the
statement is syntactically valid. If it is you will get a success return
code, if not you will get an error return code.
I understand you are using TCL but I believe all these API functions are
exposed through the TCL API as well.
HTH
Dennis Cote