1.Dd January 24, 2024 2.Dt SQLITE3_KEYWORD_COUNT 3 3.Os 4.Sh NAME 5.Nm sqlite3_keyword_count , 6.Nm sqlite3_keyword_name , 7.Nm sqlite3_keyword_check 8.Nd SQL keyword checking 9.Sh SYNOPSIS 10.In sqlite3.h 11.Ft int 12.Fo sqlite3_keyword_count 13.Fa "void" 14.Fc 15.Ft int 16.Fo sqlite3_keyword_name 17.Fa "int" 18.Fa "const char**" 19.Fa "int*" 20.Fc 21.Ft int 22.Fo sqlite3_keyword_check 23.Fa "const char*" 24.Fa "int" 25.Fc 26.Sh DESCRIPTION 27These routines provide access to the set of SQL language keywords recognized 28by SQLite. 29Applications can uses these routines to determine whether or not a 30specific identifier needs to be escaped (for example, by enclosing 31in double-quotes) so as not to confuse the parser. 32.Pp 33The sqlite3_keyword_count() interface returns the number of distinct 34keywords understood by SQLite. 35.Pp 36The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and 37makes *Z point to that keyword expressed as UTF8 and writes the number 38of bytes in the keyword into *L. 39The string that *Z points to is not zero-terminated. 40The sqlite3_keyword_name(N,Z,L) routine returns SQLITE_OK if N is within 41bounds and SQLITE_ERROR if not. 42If either Z or L are NULL or invalid pointers then calls to sqlite3_keyword_name(N,Z,L) 43result in undefined behavior. 44.Pp 45The sqlite3_keyword_check(Z,L) interface checks to see whether or not 46the L-byte UTF8 identifier that Z points to is a keyword, returning 47non-zero if it is and zero if not. 48.Pp 49The parser used by SQLite is forgiving. 50It is often possible to use a keyword as an identifier as long as such 51use does not result in a parsing ambiguity. 52For example, the statement "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" 53is accepted by SQLite, and creates a new table named "BEGIN" with three 54columns named "REPLACE", "PRAGMA", and "END". 55Nevertheless, best practice is to avoid using keywords as identifiers. 56Common techniques used to avoid keyword name collisions include: 57.Bl -bullet 58.It 59Put all identifier names inside double-quotes. 60This is the official SQL way to escape identifier names. 61.It 62Put identifier names inside [...]. 63This is not standard SQL, but it is what SQL Server does and so lots 64of programmers use this technique. 65.It 66Begin every identifier with the letter "Z" as no SQL keywords start 67with "Z". 68.It 69Include a digit somewhere in every identifier name. 70.El 71.Pp 72Note that the number of keywords understood by SQLite can depend on 73compile-time options. 74For example, "VACUUM" is not a keyword if SQLite is compiled with the 75-DSQLITE_OMIT_VACUUM option. 76Also, new keywords may be added to future releases of SQLite. 77.Sh IMPLEMENTATION NOTES 78These declarations were extracted from the 79interface documentation at line 8331. 80.Bd -literal 81SQLITE_API int sqlite3_keyword_count(void); 82SQLITE_API int sqlite3_keyword_name(int,const char**,int*); 83SQLITE_API int sqlite3_keyword_check(const char*,int); 84.Ed 85