So, using the tail pointer from sqlite3_prepare_v2() I'm now running through a loop to process all statements in a file. I'm presently using pointer math in order to determine the length of the tail command since no length value is returned as part of the function.
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. However, when I attempt to call sqlite3_sql() I will get a crash in sqlite. If I call sqlite3_step() I receive the error code SQLITE_MISUSE. 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. Otherwise there's no other way that I can tell how you could prevent the misuse code or crash to occur. 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. Perhaps I missed something else in the documentation? -Shaun -----Original Message----- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Shaun Seckman (Firaxis) Sent: Friday, April 09, 2010 3:37 PM To: General Discussion of SQLite Database Subject: Re: [sqlite] SQLite parsing of a .sql file Ah, I missed that in the documentation. This is perfect! Precisely what I needed with much less work than copying the shell.c code. Thanks a bunch! -----Original Message----- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Dan Kennedy Sent: Friday, April 09, 2010 3:24 PM To: General Discussion of SQLite Database Subject: Re: [sqlite] SQLite parsing of a .sql file On Apr 10, 2010, at 1:51 AM, Adam DeVita wrote: > Is this a 1 off import? If so, perhaps the command line tool > can .read it. > > On Fri, Apr 9, 2010 at 2:13 PM, Shaun Seckman (Firaxis) < > shaun.seck...@firaxis.com> wrote: > >> Greetings, >> >> I've got a .SQL file that contains multiple SQL insert statements for >> various tables as well as comments embedded throughout. When I >> attempted to pass the file into sqlite3_exec, I found that only the >> first SQL command was getting executed. That should not be the case. sqlite3_exec() should execute the whole script. >> What is the best way to ensure >> that all commands are executed? Parsing the file line-by-line is >> inaccurate as multiple statements may be on the same line and looking >> for the next ';' character has parsing problems as well. >> >> >> >> The documents state that sqlite3_complete() only returns a 1 if the >> statement is complete. Were this method to return the index into the >> character array to denote WHERE the SQL statement is complete, I >> could >> use that to parse multiple statements. >> >> >> >> Does anyone have any suggestions? See also the 5th parameter to sqlite3_prepare_v2(). This API allows you to compile the first statement in an SQL script and returns a pointer to the start of the next statement in the script at the same time. http://www.sqlite.org/c3ref/prepare.html Dan. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users