On Sun, 18 May 2014 19:15:18 +0200
RSmith <rsm...@rsweb.co.za> wrote:

> > As Igor says, http://sqlite.org/c3ref/prepare.html would be
> > appropriate. However, a database connection is required for this.
> 
> But of course....  What kind of syntactical correctness can you hope
> to check without a connection?

You could hope for the kind of syntactical correctness that conforms to
the rules of the syntax.  No schema infomation is required for that.  

        select A from T where W = 'foo';

is valid syntax.  It might not execute correctly, expecially if there's
no  table T with columns A and W, but that's not a syntax issue. 

Would a function that checks the syntax independent of schema be useful?
That depends on how it's defined. As things stand, SQLite might be able
to identify simple errors, 

        sqlite> select 1a from T;
        Error: unrecognized token: "1a"

That message is returned (with a connection, of course) from a database
with no table T.  It's a fine message, no objection here.  But I'm
having difficulty imagining how I might take advantage of it as a
programmer.  What's the difference between check-then-execute and
execute, if the error is the same?  

I can easily imagine uses for a generalized SQLite parser, one that
returned an abstract syntax tree.  A program might use such a thing for
all sorts of "server-side" functionality, for example to process a
string provided to a virtual table function.  

But that's a very different sort of project. It wouldn't be easy to do
in SQLite because AIUI the byte-code program produced by the prepare
functions is concrete, comprising operations and references to actual
database objects.  

--jkl


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to