24
24
25
25
#import " SQLite-Bridging.h"
26
26
27
+ @import sqlite3;
28
+
27
29
#import " fts3_tokenizer.h"
28
30
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);
31
33
}
32
34
33
- int SQLiteBusyHandler (sqlite3 * handle, SQLiteBusyHandlerCallback callback) {
35
+ int _SQLiteBusyHandler (SQLiteHandle * handle, _SQLiteBusyHandlerCallback callback) {
34
36
if (callback) {
35
- return sqlite3_busy_handler (handle, _SQLiteBusyHandler , (__bridge void *)callback);
37
+ return sqlite3_busy_handler ((sqlite3 *) handle, __SQLiteBusyHandler , (__bridge void *)callback);
36
38
} else {
37
- return sqlite3_busy_handler (handle, 0 , 0 );
39
+ return sqlite3_busy_handler ((sqlite3 *) handle, 0 , 0 );
38
40
}
39
41
}
40
42
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);
43
45
}
44
46
45
- void SQLiteTrace (sqlite3 * handle, SQLiteTraceCallback callback) {
47
+ void _SQLiteTrace (SQLiteHandle * handle, _SQLiteTraceCallback callback) {
46
48
if (callback) {
47
- sqlite3_trace (handle, _SQLiteTrace , (__bridge void *)callback);
49
+ sqlite3_trace ((sqlite3 *) handle, __SQLiteTrace , (__bridge void *)callback);
48
50
} else {
49
- sqlite3_trace (handle, 0 , 0 );
51
+ sqlite3_trace ((sqlite3 *) handle, 0 , 0 );
50
52
}
51
53
}
52
54
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);
55
57
}
56
58
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);
59
61
}
60
62
61
- static int _SQLiteCommitHook (void * context) {
62
- return ((__bridge SQLiteCommitHookCallback )context)();
63
+ static int __SQLiteCommitHook (void * context) {
64
+ return ((__bridge _SQLiteCommitHookCallback )context)();
63
65
}
64
66
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);
67
69
}
68
70
69
- static void _SQLiteRollbackHook (void * context) {
70
- ((__bridge SQLiteRollbackHookCallback )context)();
71
+ static void __SQLiteRollbackHook (void * context) {
72
+ ((__bridge _SQLiteRollbackHookCallback )context)();
71
73
}
72
74
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);
75
77
}
76
78
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);
79
81
}
80
82
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) {
82
84
if (callback) {
83
85
int flags = SQLITE_UTF8;
84
86
if (deterministic) {
85
87
#ifdef SQLITE_DETERMINISTIC
86
88
flags |= SQLITE_DETERMINISTIC;
87
89
#endif
88
90
}
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 );
90
92
} 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 );
92
94
}
93
95
}
94
96
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);
97
99
}
98
100
99
- int SQLiteCreateCollation (sqlite3 * handle, const char * name, SQLiteCreateCollationCallback callback) {
101
+ int _SQLiteCreateCollation (SQLiteHandle * handle, const char * name, _SQLiteCreateCollationCallback callback) {
100
102
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 );
102
104
} 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 );
104
106
}
105
107
}
106
108
107
109
#pragma mark - FTS
108
110
109
- typedef struct _SQLiteTokenizer {
111
+ typedef struct __SQLiteTokenizer {
110
112
sqlite3_tokenizer base;
111
- __unsafe_unretained SQLiteTokenizerNextCallback callback;
112
- } _SQLiteTokenizer ;
113
+ __unsafe_unretained _SQLiteTokenizerNextCallback callback;
114
+ } __SQLiteTokenizer ;
113
115
114
- typedef struct _SQLiteTokenizerCursor {
116
+ typedef struct __SQLiteTokenizerCursor {
115
117
void * base;
116
118
const char * input;
117
119
int inputOffset;
118
120
int inputLength;
119
121
int idx;
120
- } _SQLiteTokenizerCursor;
121
-
122
+ } __SQLiteTokenizerCursor;
122
123
123
- static NSMutableDictionary * _SQLiteTokenizerMap ;
124
+ static NSMutableDictionary * __SQLiteTokenizerMap ;
124
125
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 ));
127
128
if (!tokenizer) {
128
129
return SQLITE_NOMEM;
129
130
}
130
131
memset (tokenizer, 0 , sizeof (* tokenizer)); // FIXME: needed?
131
132
132
133
NSString * key = [NSString stringWithUTF8String: argv[0 ]];
133
- tokenizer->callback = [_SQLiteTokenizerMap objectForKey: key];
134
+ tokenizer->callback = [__SQLiteTokenizerMap objectForKey: key];
134
135
if (!tokenizer->callback ) {
135
136
return SQLITE_ERROR;
136
137
}
@@ -139,13 +140,13 @@ static int _SQLiteTokenizerCreate(int argc, const char * const * argv, sqlite3_t
139
140
return SQLITE_OK;
140
141
}
141
142
142
- static int _SQLiteTokenizerDestroy (sqlite3_tokenizer * pTokenizer) {
143
+ static int __SQLiteTokenizerDestroy (sqlite3_tokenizer * pTokenizer) {
143
144
sqlite3_free (pTokenizer);
144
145
return SQLITE_OK;
145
146
}
146
147
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 ));
149
150
if (!cursor) {
150
151
return SQLITE_NOMEM;
151
152
}
@@ -159,14 +160,14 @@ static int _SQLiteTokenizerOpen(sqlite3_tokenizer * pTokenizer, const char * pIn
159
160
return SQLITE_OK;
160
161
}
161
162
162
- static int _SQLiteTokenizerClose (sqlite3_tokenizer_cursor * pCursor) {
163
+ static int __SQLiteTokenizerClose (sqlite3_tokenizer_cursor * pCursor) {
163
164
sqlite3_free (pCursor);
164
165
return SQLITE_OK;
165
166
}
166
167
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 ;
170
171
171
172
cursor->inputOffset += cursor->inputLength ;
172
173
const char * input = cursor->input + cursor->inputOffset ;
@@ -183,27 +184,27 @@ static int _SQLiteTokenizerNext(sqlite3_tokenizer_cursor * pCursor, const char *
183
184
return SQLITE_OK;
184
185
}
185
186
186
- static const sqlite3_tokenizer_module _SQLiteTokenizerModule = {
187
+ static const sqlite3_tokenizer_module __SQLiteTokenizerModule = {
187
188
0 ,
188
- _SQLiteTokenizerCreate ,
189
- _SQLiteTokenizerDestroy ,
190
- _SQLiteTokenizerOpen ,
191
- _SQLiteTokenizerClose ,
192
- _SQLiteTokenizerNext
189
+ __SQLiteTokenizerCreate ,
190
+ __SQLiteTokenizerDestroy ,
191
+ __SQLiteTokenizerOpen ,
192
+ __SQLiteTokenizerClose ,
193
+ __SQLiteTokenizerNext
193
194
};
194
195
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) {
196
197
static dispatch_once_t onceToken;
197
198
dispatch_once (&onceToken, ^{
198
- _SQLiteTokenizerMap = [NSMutableDictionary new ];
199
+ __SQLiteTokenizerMap = [NSMutableDictionary new ];
199
200
});
200
201
201
202
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 );
203
204
if (status != SQLITE_OK ){
204
205
return status;
205
206
}
206
- const sqlite3_tokenizer_module * pModule = &_SQLiteTokenizerModule ;
207
+ const sqlite3_tokenizer_module * pModule = &__SQLiteTokenizerModule ;
207
208
sqlite3_bind_text (stmt, 1 , moduleName, -1 , SQLITE_STATIC);
208
209
sqlite3_bind_blob (stmt, 2 , &pModule, sizeof (pModule), SQLITE_STATIC);
209
210
sqlite3_step (stmt);
@@ -212,7 +213,7 @@ int SQLiteRegisterTokenizer(sqlite3 * db, const char * moduleName, const char *
212
213
return status;
213
214
}
214
215
215
- [_SQLiteTokenizerMap setObject: [callback copy ] forKey: [NSString stringWithUTF8String: submoduleName]];
216
+ [__SQLiteTokenizerMap setObject: [callback copy ] forKey: [NSString stringWithUTF8String: submoduleName]];
216
217
217
218
return SQLITE_OK;
218
219
}
0 commit comments