Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / sqlite / src / ext / misc / showauth.c
blob87a9a6843c4dc1d291a8755900754e1a3fad2b8a
1 /*
2 ** 2014-09-21
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
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
22 #include <stdio.h>
25 ** Display the authorization request
27 static int authCallback(
28 void *pClientData,
29 int op,
30 const char *z1,
31 const char *z2,
32 const char *z3,
33 const char *z4
35 const char *zOp;
36 char zOpSpace[50];
37 switch( op ){
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;
74 default: {
75 sqlite3_snprintf(sizeof(zOpSpace), zOpSpace, "%d", op);
76 zOp = zOpSpace;
77 break;
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);
85 return SQLITE_OK;
90 #ifdef _WIN32
91 __declspec(dllexport)
92 #endif
93 int sqlite3_showauth_init(
94 sqlite3 *db,
95 char **pzErrMsg,
96 const sqlite3_api_routines *pApi
98 int rc = SQLITE_OK;
99 SQLITE_EXTENSION_INIT2(pApi);
100 (void)pzErrMsg; /* Unused parameter */
101 rc = sqlite3_set_authorizer(db, authCallback, 0);
102 return rc;