SQLite compile authorize callback Compile-Time Authorization Callbacks

Original: https://www.sqlite.org/c3ref/set_authorizer.html

 
int sqlite3_set_authorizer (
 sqlite3 *,
  int (* xAuth) (void *, int, const char *, const char *, const char *, const char *),
 void * pUserData
);
This function will register an authorization callback function to a the specified database handle, the first parameter specifies the database handle. When the SQL statement is compiled sqlite3_prepare or her variants sqlite3_prepare_v2, sqlite3_prepare16, sqlite3_prepare166_v2 and other functions, it will call the callback function. On different compilers point, perform different operations, authorized the callback function will be executed, and returns the current operation is legitimate (At various points during the compilation process , as logic is beingcreated to perform various actions, the authorizer callback is invoked to seeif those actions are allowed). If the callback function returns SQLITE_OK, showing the action is permitted, SQLITE_IGNORE the specified operation is not allowed, but allows the compiler, SQLITE_DENY will return an error, and does not perform the operation. If the callback function returns other values, rather than one of the above three types, sqlite3_prepare_v2 function will trigger an error message (then the sqlite3_prepare_v2 () or equivalent call that triggered theauthorizer will fail with an error message.)


SQLITE_OK allow SQL execution
SQLITE_DENY refuse to execute SQL
SQLITE_IGNORE allows SQL execution, but attempts to read the record rally returns NULL, try to write a record rally is ignored

The first parameter authorization callback function will be set into the third function of sqlite3_set_authorizer. The second function is an integer opcode, which specifies the operation is allowed. Third to sixth parameter is a zero character string to end, these three parameters contain additional details of the operation which is permitted to be authorized.


Guess you like

Origin blog.51cto.com/fengyuzaitu/2429734