On 2014/05/18 17:24, Wolfgang Enzinger wrote:

i _think_ what you want is:

http://sqlite.org/c3ref/complete.html
I don't think so, because this function essentially checks "if [the
statement] ends with a semicolon token". Furthermore, "these routines do
not parse the SQL statements thus will not detect syntactically incorrect
SQL".

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?

I mean you can see if the SQL keywords used are valid keywords, i.e. SELECT, INSERT, CREATE, etc... but for that a simple Key-list look-up and white-space separation check would suffice. However to know whether the SQL itself is valid, that can never be done without a connection (i.e. knowledge of the DB Schema being available to the parser).

I mean the following will be valid SQL:
SELECT zxyyffCCgahajiklMM019101kkjdjhd12 FROM lkjsdndn23n2323 WHERE Patrick IS 
Dead;

But you would look far and wide to find an actual schema in existence for which that would be a valid statement. Simply having the words SELECT and FROM with anything in between might be fine in most cases.

A more sensible example would be the following statement:
CREATE TABLE xx (int INTEGER PRIMARY KEY) WITHOUT ROWID;

This will work on some versions of SQLite files and connections, but not on 
others. How would you know without a connection?
There is no universal correctness for SQL statements - though there are standards for how statements /SHOULD/ be composed and interpreted, but as experience on this list have taught us: No single SQL engine follows that to the letter - though I imagine you can get some software that might check universal SQL92 conformance (I've never seen any, but maybe James Lowden might know).

Either way, the SQL in SQLite will work mostly in SQLite but not necessarily elsewhere, and checking the validity of that would be insensible without a schema and file version - i.e. a connection to an actual file.



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

Reply via email to