2424
2525#import " SQLite-Bridging.h"
2626
27+ @import sqlite3;
28+
2729#import " fts3_tokenizer.h"
2830
29- static int _SQLiteBusyHandler (void * context, int tries) {
30- return ((__bridge SQLiteBusyHandlerCallback )context)(tries);
31+ static int __SQLiteBusyHandler (void * context, int tries) {
32+ return ((__bridge _SQLiteBusyHandlerCallback )context)(tries);
3133}
3234
33- int SQLiteBusyHandler (sqlite3 * handle, SQLiteBusyHandlerCallback callback) {
35+ int _SQLiteBusyHandler (SQLiteHandle * handle, _SQLiteBusyHandlerCallback callback) {
3436 if (callback) {
35- return sqlite3_busy_handler (handle, _SQLiteBusyHandler , (__bridge void *)callback);
37+ return sqlite3_busy_handler ((sqlite3 *) handle, __SQLiteBusyHandler , (__bridge void *)callback);
3638 } else {
37- return sqlite3_busy_handler (handle, 0 , 0 );
39+ return sqlite3_busy_handler ((sqlite3 *) handle, 0 , 0 );
3840 }
3941}
4042
41- static void _SQLiteTrace (void * context, const char * SQL) {
42- ((__bridge SQLiteTraceCallback )context)(SQL);
43+ static void __SQLiteTrace (void * context, const char * SQL) {
44+ ((__bridge _SQLiteTraceCallback )context)(SQL);
4345}
4446
45- void SQLiteTrace (sqlite3 * handle, SQLiteTraceCallback callback) {
47+ void _SQLiteTrace (SQLiteHandle * handle, _SQLiteTraceCallback callback) {
4648 if (callback) {
47- sqlite3_trace (handle, _SQLiteTrace , (__bridge void *)callback);
49+ sqlite3_trace ((sqlite3 *) handle, __SQLiteTrace , (__bridge void *)callback);
4850 } else {
49- sqlite3_trace (handle, 0 , 0 );
51+ sqlite3_trace ((sqlite3 *) handle, 0 , 0 );
5052 }
5153}
5254
53- static void _SQLiteUpdateHook (void * context, int operation, const char * db, const char * table, sqlite3_int64 rowid) {
54- ((__bridge SQLiteUpdateHookCallback )context)(operation, db, table, rowid);
55+ static void __SQLiteUpdateHook (void * context, int operation, const char * db, const char * table, long long rowid) {
56+ ((__bridge _SQLiteUpdateHookCallback )context)(operation, db, table, rowid);
5557}
5658
57- void SQLiteUpdateHook (sqlite3 * handle, SQLiteUpdateHookCallback callback) {
58- sqlite3_update_hook (handle, _SQLiteUpdateHook , (__bridge void *)callback);
59+ void _SQLiteUpdateHook (SQLiteHandle * handle, _SQLiteUpdateHookCallback callback) {
60+ sqlite3_update_hook ((sqlite3 *) handle, __SQLiteUpdateHook , (__bridge void *)callback);
5961}
6062
61- static int _SQLiteCommitHook (void * context) {
62- return ((__bridge SQLiteCommitHookCallback )context)();
63+ static int __SQLiteCommitHook (void * context) {
64+ return ((__bridge _SQLiteCommitHookCallback )context)();
6365}
6466
65- void SQLiteCommitHook (sqlite3 * handle, SQLiteCommitHookCallback callback) {
66- sqlite3_commit_hook (handle, _SQLiteCommitHook , (__bridge void *)callback);
67+ void _SQLiteCommitHook (SQLiteHandle * handle, _SQLiteCommitHookCallback callback) {
68+ sqlite3_commit_hook ((sqlite3 *) handle, __SQLiteCommitHook , (__bridge void *)callback);
6769}
6870
69- static void _SQLiteRollbackHook (void * context) {
70- ((__bridge SQLiteRollbackHookCallback )context)();
71+ static void __SQLiteRollbackHook (void * context) {
72+ ((__bridge _SQLiteRollbackHookCallback )context)();
7173}
7274
73- void SQLiteRollbackHook (sqlite3 * handle, SQLiteRollbackHookCallback callback) {
74- sqlite3_rollback_hook (handle, _SQLiteRollbackHook , (__bridge void *)callback);
75+ void _SQLiteRollbackHook (SQLiteHandle * handle, _SQLiteRollbackHookCallback callback) {
76+ sqlite3_rollback_hook ((sqlite3 *) handle, __SQLiteRollbackHook , (__bridge void *)callback);
7577}
7678
77- static void _SQLiteCreateFunction (sqlite3_context * context, int argc, sqlite3_value ** argv) {
78- ((__bridge SQLiteCreateFunctionCallback )sqlite3_user_data (context))(context, argc, argv);
79+ static void __SQLiteCreateFunction (sqlite3_context * context, int argc, sqlite3_value ** argv) {
80+ ((__bridge _SQLiteCreateFunctionCallback )sqlite3_user_data (context))((SQLiteContext *) context, argc, (SQLiteValue **) argv);
7981}
8082
81- int SQLiteCreateFunction (sqlite3 * handle, const char * name, int argc, int deterministic, SQLiteCreateFunctionCallback callback) {
83+ int _SQLiteCreateFunction (SQLiteHandle * handle, const char * name, int argc, int deterministic, _SQLiteCreateFunctionCallback callback) {
8284 if (callback) {
8385 int flags = SQLITE_UTF8;
8486 if (deterministic) {
8587#ifdef SQLITE_DETERMINISTIC
8688 flags |= SQLITE_DETERMINISTIC;
8789#endif
8890 }
89- return sqlite3_create_function_v2 (handle, name, -1 , flags, (__bridge void *)callback, &_SQLiteCreateFunction , 0 , 0 , 0 );
91+ return sqlite3_create_function_v2 ((sqlite3 *) handle, name, -1 , flags, (__bridge void *)callback, &__SQLiteCreateFunction , 0 , 0 , 0 );
9092 } else {
91- return sqlite3_create_function_v2 (handle, name, 0 , 0 , 0 , 0 , 0 , 0 , 0 );
93+ return sqlite3_create_function_v2 ((sqlite3 *) handle, name, 0 , 0 , 0 , 0 , 0 , 0 , 0 );
9294 }
9395}
9496
95- static int _SQLiteCreateCollation (void * context, int len_lhs, const void * lhs, int len_rhs, const void * rhs) {
96- return ((__bridge SQLiteCreateCollationCallback )context)(lhs, rhs);
97+ static int __SQLiteCreateCollation (void * context, int len_lhs, const void * lhs, int len_rhs, const void * rhs) {
98+ return ((__bridge _SQLiteCreateCollationCallback )context)(lhs, rhs);
9799}
98100
99- int SQLiteCreateCollation (sqlite3 * handle, const char * name, SQLiteCreateCollationCallback callback) {
101+ int _SQLiteCreateCollation (SQLiteHandle * handle, const char * name, _SQLiteCreateCollationCallback callback) {
100102 if (callback) {
101- return sqlite3_create_collation_v2 (handle, name, SQLITE_UTF8, (__bridge void *)callback, &_SQLiteCreateCollation , 0 );
103+ return sqlite3_create_collation_v2 ((sqlite3 *) handle, name, SQLITE_UTF8, (__bridge void *)callback, &__SQLiteCreateCollation , 0 );
102104 } else {
103- return sqlite3_create_collation_v2 (handle, name, 0 , 0 , 0 , 0 );
105+ return sqlite3_create_collation_v2 ((sqlite3 *) handle, name, 0 , 0 , 0 , 0 );
104106 }
105107}
106108
107109#pragma mark - FTS
108110
109- typedef struct _SQLiteTokenizer {
111+ typedef struct __SQLiteTokenizer {
110112 sqlite3_tokenizer base;
111- __unsafe_unretained SQLiteTokenizerNextCallback callback;
112- } _SQLiteTokenizer ;
113+ __unsafe_unretained _SQLiteTokenizerNextCallback callback;
114+ } __SQLiteTokenizer ;
113115
114- typedef struct _SQLiteTokenizerCursor {
116+ typedef struct __SQLiteTokenizerCursor {
115117 void * base;
116118 const char * input;
117119 int inputOffset;
118120 int inputLength;
119121 int idx;
120- } _SQLiteTokenizerCursor;
121-
122+ } __SQLiteTokenizerCursor;
122123
123- static NSMutableDictionary * _SQLiteTokenizerMap ;
124+ static NSMutableDictionary * __SQLiteTokenizerMap ;
124125
125- static int _SQLiteTokenizerCreate (int argc, const char * const * argv, sqlite3_tokenizer ** ppTokenizer) {
126- _SQLiteTokenizer * tokenizer = (_SQLiteTokenizer *)sqlite3_malloc (sizeof (_SQLiteTokenizer ));
126+ static int __SQLiteTokenizerCreate (int argc, const char * const * argv, sqlite3_tokenizer ** ppTokenizer) {
127+ __SQLiteTokenizer * tokenizer = (__SQLiteTokenizer *)sqlite3_malloc (sizeof (__SQLiteTokenizer ));
127128 if (!tokenizer) {
128129 return SQLITE_NOMEM;
129130 }
130131 memset (tokenizer, 0 , sizeof (* tokenizer)); // FIXME: needed?
131132
132133 NSString * key = [NSString stringWithUTF8String: argv[0 ]];
133- tokenizer->callback = [_SQLiteTokenizerMap objectForKey: key];
134+ tokenizer->callback = [__SQLiteTokenizerMap objectForKey: key];
134135 if (!tokenizer->callback ) {
135136 return SQLITE_ERROR;
136137 }
@@ -139,13 +140,13 @@ static int _SQLiteTokenizerCreate(int argc, const char * const * argv, sqlite3_t
139140 return SQLITE_OK;
140141}
141142
142- static int _SQLiteTokenizerDestroy (sqlite3_tokenizer * pTokenizer) {
143+ static int __SQLiteTokenizerDestroy (sqlite3_tokenizer * pTokenizer) {
143144 sqlite3_free (pTokenizer);
144145 return SQLITE_OK;
145146}
146147
147- static int _SQLiteTokenizerOpen (sqlite3_tokenizer * pTokenizer, const char * pInput, int nBytes, sqlite3_tokenizer_cursor ** ppCursor) {
148- _SQLiteTokenizerCursor * cursor = (_SQLiteTokenizerCursor *)sqlite3_malloc (sizeof (_SQLiteTokenizerCursor ));
148+ static int __SQLiteTokenizerOpen (sqlite3_tokenizer * pTokenizer, const char * pInput, int nBytes, sqlite3_tokenizer_cursor ** ppCursor) {
149+ __SQLiteTokenizerCursor * cursor = (__SQLiteTokenizerCursor *)sqlite3_malloc (sizeof (__SQLiteTokenizerCursor ));
149150 if (!cursor) {
150151 return SQLITE_NOMEM;
151152 }
@@ -159,14 +160,14 @@ static int _SQLiteTokenizerOpen(sqlite3_tokenizer * pTokenizer, const char * pIn
159160 return SQLITE_OK;
160161}
161162
162- static int _SQLiteTokenizerClose (sqlite3_tokenizer_cursor * pCursor) {
163+ static int __SQLiteTokenizerClose (sqlite3_tokenizer_cursor * pCursor) {
163164 sqlite3_free (pCursor);
164165 return SQLITE_OK;
165166}
166167
167- static int _SQLiteTokenizerNext (sqlite3_tokenizer_cursor * pCursor, const char ** ppToken, int * pnBytes, int * piStartOffset, int * piEndOffset, int * piPosition) {
168- _SQLiteTokenizerCursor * cursor = (_SQLiteTokenizerCursor *)pCursor;
169- _SQLiteTokenizer * tokenizer = (_SQLiteTokenizer *)cursor->base ;
168+ static int __SQLiteTokenizerNext (sqlite3_tokenizer_cursor * pCursor, const char ** ppToken, int * pnBytes, int * piStartOffset, int * piEndOffset, int * piPosition) {
169+ __SQLiteTokenizerCursor * cursor = (__SQLiteTokenizerCursor *)pCursor;
170+ __SQLiteTokenizer * tokenizer = (__SQLiteTokenizer *)cursor->base ;
170171
171172 cursor->inputOffset += cursor->inputLength ;
172173 const char * input = cursor->input + cursor->inputOffset ;
@@ -183,27 +184,27 @@ static int _SQLiteTokenizerNext(sqlite3_tokenizer_cursor * pCursor, const char *
183184 return SQLITE_OK;
184185}
185186
186- static const sqlite3_tokenizer_module _SQLiteTokenizerModule = {
187+ static const sqlite3_tokenizer_module __SQLiteTokenizerModule = {
187188 0 ,
188- _SQLiteTokenizerCreate ,
189- _SQLiteTokenizerDestroy ,
190- _SQLiteTokenizerOpen ,
191- _SQLiteTokenizerClose ,
192- _SQLiteTokenizerNext
189+ __SQLiteTokenizerCreate ,
190+ __SQLiteTokenizerDestroy ,
191+ __SQLiteTokenizerOpen ,
192+ __SQLiteTokenizerClose ,
193+ __SQLiteTokenizerNext
193194};
194195
195- int SQLiteRegisterTokenizer (sqlite3 * db, const char * moduleName, const char * submoduleName, SQLiteTokenizerNextCallback callback) {
196+ int _SQLiteRegisterTokenizer (SQLiteHandle * db, const char * moduleName, const char * submoduleName, _SQLiteTokenizerNextCallback callback) {
196197 static dispatch_once_t onceToken;
197198 dispatch_once (&onceToken, ^{
198- _SQLiteTokenizerMap = [NSMutableDictionary new ];
199+ __SQLiteTokenizerMap = [NSMutableDictionary new ];
199200 });
200201
201202 sqlite3_stmt * stmt;
202- int status = sqlite3_prepare_v2 (db, " SELECT fts3_tokenizer(?, ?)" , -1 , &stmt, 0 );
203+ int status = sqlite3_prepare_v2 ((sqlite3 *) db, " SELECT fts3_tokenizer(?, ?)" , -1 , &stmt, 0 );
203204 if (status != SQLITE_OK ){
204205 return status;
205206 }
206- const sqlite3_tokenizer_module * pModule = &_SQLiteTokenizerModule ;
207+ const sqlite3_tokenizer_module * pModule = &__SQLiteTokenizerModule ;
207208 sqlite3_bind_text (stmt, 1 , moduleName, -1 , SQLITE_STATIC);
208209 sqlite3_bind_blob (stmt, 2 , &pModule, sizeof (pModule), SQLITE_STATIC);
209210 sqlite3_step (stmt);
@@ -212,7 +213,7 @@ int SQLiteRegisterTokenizer(sqlite3 * db, const char * moduleName, const char *
212213 return status;
213214 }
214215
215- [_SQLiteTokenizerMap setObject: [callback copy ] forKey: [NSString stringWithUTF8String: submoduleName]];
216+ [__SQLiteTokenizerMap setObject: [callback copy ] forKey: [NSString stringWithUTF8String: submoduleName]];
216217
217218 return SQLITE_OK;
218219}
0 commit comments