views:

82

answers:

2

Is there a way to check the syntax of a SQLite3 script without running it?

Basically, I'm looking for the SQLite3 equivalent of ruby -c script.rb, perl -c script.pl, php --syntax-check script.php, etc.

I've thought of using explain, but most of the scripts I'd like to check are kept around for reference purposes (and don't necessarily have an associated database). Using explain would also make it hard to use with something like Syntastic. (That is, I'm only wanting to check syntax, not semantics.)

Update:

I'm confused. Let's say I want to syntax check this:

select * from foo;

I could do something like:

echo 'explain select * from foo;' | sqlite3

But then I get:

SQL error near line 1: no such table: foo

All I'd expect to see is "Syntax OK" (or something similar). Is that possible?

A: 

You could probably use EXPLAIN against an in memory database. With sqlite3, you can get an in memory database by passing ":memory:" as the filename to sqlite3_open_v2().

dicroce
A: 

As you mentioned, you can use the EXPLAIN keyword. It will return information about how the statement would be executed had you omitted the preceding EXPLAIN keyword.

Brian R. Bondy