On 04/09/2010 01:25 PM, Shaun Seckman (Firaxis) wrote:
> I'm running into a nasty problem towards the end of the file however.
> At the very end there are 3 characters left that are just whitespace
> characters.  When I pass this string into sqlite3_prepare_v2() I get a
> return value of 0 as if it's a valid statement.

http://sqlite.org/c3ref/prepare.html

   If the input text contains no SQL (if the input is an empty string
   or a comment) then *ppStmt is set to NULL

Similarly your file could contain this.  I suggest using it for testing.

   ;;;; select 3 ;;;;


 > However, when I attempt
> to call sqlite3_sql() I will get a crash in sqlite.

Don't do that then.  prepare already told you there was no SQL.  Note that 
pzTail is still set correctly.

> If I call
> sqlite3_step() I receive the error code SQLITE_MISUSE.

Don't do that either :-)

> What would be very useful is if whitespace or comments were the only
> data passed into sqlite3_prepvare_v2() for it to return an error code
> that it was an empty statement or something similar.

It does, except an empty statement is not an error.  You get NULL returned 
as documented.

> Otherwise there's
> no other way that I can tell how you could prevent the misuse code or
> crash to occur.

You are way overthinking all this.  Additionally you do not need to call 
sqlite3_sql since zSql was the start of the statement and pzTail points to 
the end.  This will be the case even when there are empty statements.

> I know there is sqlite_complete() but I would have expected prepare to
> perform something similar.  Also sqlite_complete assumes a NULL
> terminated string which is different from most other API functions that
> allow for a string/length combination.

complete is unrelated to your problem unless you are trying to a read the 
contents of a file in the smallest chunks possible.

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

Reply via email to