int sqlite3_complete(const char *sql); int sqlite3_complete16(const void *sql); sqlite3_int64 sqlite3_incomplete(const char *sql);
These routines are useful during command-line input to determine if the currently entered text seems to form a complete SQL statement or if additional input is needed before sending the text into SQLite for parsing. The sqlite3_complete(X) and sqlite3_complete16(X) routines return 1 if the input string X appears to be a complete SQL statement. A statement is judged to be complete if it ends with a semicolon token and is not a prefix of a well-formed CREATE TRIGGER statement. Semicolons that are embedded within string literals or quoted identifier names or comments are not independent tokens (they are part of the token in which they are embedded) and thus do not count as a statement terminator. Whitespace and comments that follow the final semicolon are ignored.
The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0 if the statement is incomplete. If a memory allocation fails, then SQLITE_NOMEM is returned.
The sqlite3_incomplete(X) routine is similar to sqlite3_complete(X) except that sqlite3_incomplete(X) returns 0 if the input X is complete and non-zero if X is incomplete. The non-zero return from sqlite3_incomplete(X) contains additional information about what is needed to complete the input X. The sqlite3_incomplete(X) interface is only available for UTF-8 text.
None of these routines do a full parse the SQL statements and thus will not detect syntactically incorrect SQL. They only determine if input text has properly terminated comments, string literals, and quoted identifiers, and if the statement ends with a semicolon.
If SQLite has not been initialized using sqlite3_initialize() prior to invoking sqlite3_complete16() then sqlite3_initialize() is invoked automatically by sqlite3_complete16(). If that initialization fails, then the return value from sqlite3_complete16() will be non-zero regardless of whether or not the input SQL is complete.
The X input to sqlite3_complete(X) and sqlite3_incomplete(X) must be a zero-terminated UTF-8 string.
The input to sqlite3_complete16() must be a zero-terminated UTF-16 string in native byte order.
See also lists of Objects, Constants, and Functions.
*** DRAFT ***