4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 ******************************************************************************
13 ** This SQLite extension adds a debug "authorizer" callback to the database
14 ** connection. The callback merely writes the authorization request to
15 ** standard output and returns SQLITE_OK.
17 ** This extension can be used (for example) in the command-line shell to
18 ** trace the operation of the authorizer.
20 #include "sqlite3ext.h"
21 SQLITE_EXTENSION_INIT1
25 ** Display the authorization request
27 static int authCallback(
38 case SQLITE_CREATE_INDEX
: zOp
= "CREATE_INDEX"; break;
39 case SQLITE_CREATE_TABLE
: zOp
= "CREATE_TABLE"; break;
40 case SQLITE_CREATE_TEMP_INDEX
: zOp
= "CREATE_TEMP_INDEX"; break;
41 case SQLITE_CREATE_TEMP_TABLE
: zOp
= "CREATE_TEMP_TABLE"; break;
42 case SQLITE_CREATE_TEMP_TRIGGER
: zOp
= "CREATE_TEMP_TRIGGER"; break;
43 case SQLITE_CREATE_TEMP_VIEW
: zOp
= "CREATE_TEMP_VIEW"; break;
44 case SQLITE_CREATE_TRIGGER
: zOp
= "CREATE_TRIGGER"; break;
45 case SQLITE_CREATE_VIEW
: zOp
= "CREATE_VIEW"; break;
46 case SQLITE_DELETE
: zOp
= "DELETE"; break;
47 case SQLITE_DROP_INDEX
: zOp
= "DROP_INDEX"; break;
48 case SQLITE_DROP_TABLE
: zOp
= "DROP_TABLE"; break;
49 case SQLITE_DROP_TEMP_INDEX
: zOp
= "DROP_TEMP_INDEX"; break;
50 case SQLITE_DROP_TEMP_TABLE
: zOp
= "DROP_TEMP_TABLE"; break;
51 case SQLITE_DROP_TEMP_TRIGGER
: zOp
= "DROP_TEMP_TRIGGER"; break;
52 case SQLITE_DROP_TEMP_VIEW
: zOp
= "DROP_TEMP_VIEW"; break;
53 case SQLITE_DROP_TRIGGER
: zOp
= "DROP_TRIGGER"; break;
54 case SQLITE_DROP_VIEW
: zOp
= "DROP_VIEW"; break;
55 case SQLITE_INSERT
: zOp
= "INSERT"; break;
56 case SQLITE_PRAGMA
: zOp
= "PRAGMA"; break;
57 case SQLITE_READ
: zOp
= "READ"; break;
58 case SQLITE_SELECT
: zOp
= "SELECT"; break;
59 case SQLITE_TRANSACTION
: zOp
= "TRANSACTION"; break;
60 case SQLITE_UPDATE
: zOp
= "UPDATE"; break;
61 case SQLITE_ATTACH
: zOp
= "ATTACH"; break;
62 case SQLITE_DETACH
: zOp
= "DETACH"; break;
63 case SQLITE_ALTER_TABLE
: zOp
= "ALTER_TABLE"; break;
64 case SQLITE_REINDEX
: zOp
= "REINDEX"; break;
65 case SQLITE_ANALYZE
: zOp
= "ANALYZE"; break;
66 case SQLITE_CREATE_VTABLE
: zOp
= "CREATE_VTABLE"; break;
67 case SQLITE_DROP_VTABLE
: zOp
= "DROP_VTABLE"; break;
68 case SQLITE_FUNCTION
: zOp
= "FUNCTION"; break;
69 case SQLITE_SAVEPOINT
: zOp
= "SAVEPOINT"; break;
70 case SQLITE_COPY
: zOp
= "COPY"; break;
71 case SQLITE_RECURSIVE
: zOp
= "RECURSIVE"; break;
75 sqlite3_snprintf(sizeof(zOpSpace
), zOpSpace
, "%d", op
);
80 if( z1
==0 ) z1
= "NULL";
81 if( z2
==0 ) z2
= "NULL";
82 if( z3
==0 ) z3
= "NULL";
83 if( z4
==0 ) z4
= "NULL";
84 printf("AUTH: %s,%s,%s,%s,%s\n", zOp
, z1
, z2
, z3
, z4
);
93 int sqlite3_showauth_init(
96 const sqlite3_api_routines
*pApi
99 SQLITE_EXTENSION_INIT2(pApi
);
100 (void)pzErrMsg
; /* Unused parameter */
101 rc
= sqlite3_set_authorizer(db
, authCallback
, 0);