-
Notifications
You must be signed in to change notification settings - Fork 3
/
sweepea.pxd
292 lines (250 loc) · 10.5 KB
/
sweepea.pxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
from cpython.bytes cimport PyBytes_Check
from cpython.object cimport PyObject
from cpython.unicode cimport PyUnicode_AsUTF8String
from cpython.unicode cimport PyUnicode_Check
cdef inline bytes encode(key):
cdef bytes bkey
if PyUnicode_Check(key):
bkey = PyUnicode_AsUTF8String(key)
else:
bkey = <bytes>key
return bkey
cdef inline unicode decode(key):
cdef unicode ukey
if PyBytes_Check(key):
ukey = key.decode('utf-8')
else:
ukey = key
return ukey
cdef struct sqlite3_index_constraint:
int iColumn
unsigned char op
unsigned char usable
int iTermOffset
cdef struct sqlite3_index_orderby:
int iColumn
unsigned char desc
cdef struct sqlite3_index_constraint_usage:
int argvIndex
unsigned char omit
cdef extern from "sqlite3.h" nogil:
ctypedef struct sqlite3:
int busyTimeout
ctypedef struct sqlite3_backup
ctypedef struct sqlite3_blob
ctypedef struct sqlite3_context
ctypedef struct sqlite3_value
ctypedef long long sqlite3_int64
ctypedef unsigned long long sqlite_uint64
# Virtual tables.
ctypedef struct sqlite3_module # Forward reference.
ctypedef struct sqlite3_vtab:
const sqlite3_module *pModule
int nRef
char *zErrMsg
ctypedef struct sqlite3_vtab_cursor:
sqlite3_vtab *pVtab
ctypedef struct sqlite3_index_info:
int nConstraint
sqlite3_index_constraint *aConstraint
int nOrderBy
sqlite3_index_orderby *aOrderBy
sqlite3_index_constraint_usage *aConstraintUsage
int idxNum
char *idxStr
int needToFreeIdxStr
int orderByConsumed
double estimatedCost
sqlite3_int64 estimatedRows
int idxFlags
ctypedef struct sqlite3_module:
int iVersion
int (*xCreate)(sqlite3*, void *pAux, int argc, char **argv,
sqlite3_vtab **ppVTab, char**)
int (*xConnect)(sqlite3*, void *pAux, int argc, char **argv,
sqlite3_vtab **ppVTab, char**)
int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*)
int (*xDisconnect)(sqlite3_vtab *pVTab)
int (*xDestroy)(sqlite3_vtab *pVTab)
int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor)
int (*xClose)(sqlite3_vtab_cursor*)
int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
int argc, sqlite3_value **argv)
int (*xNext)(sqlite3_vtab_cursor*)
int (*xEof)(sqlite3_vtab_cursor*)
int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context *, int)
int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid)
int (*xUpdate)(sqlite3_vtab *pVTab, int, sqlite3_value **,
sqlite3_int64 **)
int (*xBegin)(sqlite3_vtab *pVTab)
int (*xSync)(sqlite3_vtab *pVTab)
int (*xCommit)(sqlite3_vtab *pVTab)
int (*xRollback)(sqlite3_vtab *pVTab)
int (*xFindFunction)(sqlite3_vtab *pVTab, int nArg, const char *zName,
void (**pxFunc)(sqlite3_context *, int,
sqlite3_value **),
void **ppArg)
int (*xRename)(sqlite3_vtab *pVTab, const char *zNew)
int (*xSavepoint)(sqlite3_vtab *pVTab, int)
int (*xRelease)(sqlite3_vtab *pVTab, int)
int (*xRollbackTo)(sqlite3_vtab *pVTab, int)
cdef int sqlite3_declare_vtab(sqlite3 *db, const char *zSQL)
cdef int sqlite3_create_module(sqlite3 *db, const char *zName,
const sqlite3_module *p, void *pClientData)
# Encoding.
cdef int SQLITE_UTF8 = 1
# Return values.
cdef int SQLITE_OK = 0
cdef int SQLITE_ERROR = 1
cdef int SQLITE_NOMEM = 7
# Function type.
cdef int SQLITE_DETERMINISTIC = 0x800
# Types of filtering operations.
cdef int SQLITE_INDEX_CONSTRAINT_EQ = 2
cdef int SQLITE_INDEX_CONSTRAINT_GT = 4
cdef int SQLITE_INDEX_CONSTRAINT_LE = 8
cdef int SQLITE_INDEX_CONSTRAINT_LT = 16
cdef int SQLITE_INDEX_CONSTRAINT_GE = 32
cdef int SQLITE_INDEX_CONSTRAINT_MATCH = 64
# sqlite_value_type.
cdef int SQLITE_INTEGER = 1
cdef int SQLITE_FLOAT = 2
cdef int SQLITE3_TEXT = 3
cdef int SQLITE_TEXT = 3
cdef int SQLITE_BLOB = 4
cdef int SQLITE_NULL = 5
ctypedef void (*sqlite3_destructor_type)(void*)
# Converting from Sqlite -> Python.
cdef const void *sqlite3_value_blob(sqlite3_value*)
cdef int sqlite3_value_bytes(sqlite3_value*)
cdef double sqlite3_value_double(sqlite3_value*)
cdef int sqlite3_value_int(sqlite3_value*)
cdef sqlite3_int64 sqlite3_value_int64(sqlite3_value*)
cdef const unsigned char *sqlite3_value_text(sqlite3_value*)
cdef int sqlite3_value_type(sqlite3_value*)
cdef int sqlite3_value_numeric_type(sqlite3_value*)
# Converting from Python -> Sqlite.
cdef void sqlite3_result_double(sqlite3_context*, double)
cdef void sqlite3_result_error(sqlite3_context*, const char*, int)
cdef void sqlite3_result_error_toobig(sqlite3_context*)
cdef void sqlite3_result_error_nomem(sqlite3_context*)
cdef void sqlite3_result_error_code(sqlite3_context*, int)
cdef void sqlite3_result_int(sqlite3_context*, int)
cdef void sqlite3_result_int64(sqlite3_context*, sqlite3_int64)
cdef void sqlite3_result_null(sqlite3_context*)
cdef void sqlite3_result_text(sqlite3_context*, const char*, int,
void(*)(void*))
cdef void sqlite3_result_value(sqlite3_context*, sqlite3_value*)
# Memory management.
cdef void* sqlite3_malloc(int)
cdef void sqlite3_free(void *)
cdef int sqlite3_changes(sqlite3 *db)
cdef int sqlite3_get_autocommit(sqlite3 *db)
cdef sqlite3_int64 sqlite3_last_insert_rowid(sqlite3 *db)
cdef void *sqlite3_commit_hook(sqlite3 *, int(*)(void *), void *)
cdef void *sqlite3_rollback_hook(sqlite3 *, void(*)(void *), void *)
cdef void *sqlite3_update_hook(
sqlite3 *,
void(*)(void *, int, char *, char *, sqlite3_int64),
void *)
cdef int SQLITE_STATUS_MEMORY_USED = 0
cdef int SQLITE_STATUS_PAGECACHE_USED = 1
cdef int SQLITE_STATUS_PAGECACHE_OVERFLOW = 2
cdef int SQLITE_STATUS_SCRATCH_USED = 3
cdef int SQLITE_STATUS_SCRATCH_OVERFLOW = 4
cdef int SQLITE_STATUS_MALLOC_SIZE = 5
cdef int SQLITE_STATUS_PARSER_STACK = 6
cdef int SQLITE_STATUS_PAGECACHE_SIZE = 7
cdef int SQLITE_STATUS_SCRATCH_SIZE = 8
cdef int SQLITE_STATUS_MALLOC_COUNT = 9
cdef int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag)
cdef int SQLITE_DBSTATUS_LOOKASIDE_USED = 0
cdef int SQLITE_DBSTATUS_CACHE_USED = 1
cdef int SQLITE_DBSTATUS_SCHEMA_USED = 2
cdef int SQLITE_DBSTATUS_STMT_USED = 3
cdef int SQLITE_DBSTATUS_LOOKASIDE_HIT = 4
cdef int SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5
cdef int SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6
cdef int SQLITE_DBSTATUS_CACHE_HIT = 7
cdef int SQLITE_DBSTATUS_CACHE_MISS = 8
cdef int SQLITE_DBSTATUS_CACHE_WRITE = 9
cdef int SQLITE_DBSTATUS_DEFERRED_FKS = 10
#cdef int SQLITE_DBSTATUS_CACHE_USED_SHARED = 11
cdef int sqlite3_db_status(sqlite3 *, int op, int *pCur, int *pHigh, int reset)
cdef int SQLITE_DELETE = 9
cdef int SQLITE_INSERT = 18
cdef int SQLITE_UPDATE = 23
cdef int SQLITE_CONFIG_SINGLETHREAD = 1 # None
cdef int SQLITE_CONFIG_MULTITHREAD = 2 # None
cdef int SQLITE_CONFIG_SERIALIZED = 3 # None
cdef int SQLITE_CONFIG_SCRATCH = 6 # void *, int sz, int N
cdef int SQLITE_CONFIG_PAGECACHE = 7 # void *, int sz, int N
cdef int SQLITE_CONFIG_HEAP = 8 # void *, int nByte, int min
cdef int SQLITE_CONFIG_MEMSTATUS = 9 # boolean
cdef int SQLITE_CONFIG_LOOKASIDE = 13 # int, int
cdef int SQLITE_CONFIG_URI = 17 # int
cdef int SQLITE_CONFIG_MMAP_SIZE = 22 # sqlite3_int64, sqlite3_int64
cdef int SQLITE_CONFIG_STMTJRNL_SPILL = 26 # int nByte
cdef int SQLITE_DBCONFIG_MAINDBNAME = 1000 # const char*
cdef int SQLITE_DBCONFIG_LOOKASIDE = 1001 # void* int int
cdef int SQLITE_DBCONFIG_ENABLE_FKEY = 1002 # int int*
cdef int SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003 # int int*
cdef int SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004 # int int*
cdef int SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005 # int int*
cdef int SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE = 1006 # int int*
cdef int SQLITE_DBCONFIG_ENABLE_QPSG = 1007 # int int*
cdef int sqlite3_config(int, ...)
cdef int sqlite3_db_config(sqlite3*, int op, ...)
# Misc.
cdef int sqlite3_busy_handler(sqlite3 *db, int(*)(void *, int), void *)
cdef int sqlite3_sleep(int ms)
cdef sqlite3_backup *sqlite3_backup_init(
sqlite3 *pDest,
const char *zDestName,
sqlite3 *pSource,
const char *zSourceName)
# Backup.
cdef int sqlite3_backup_step(sqlite3_backup *p, int nPage)
cdef int sqlite3_backup_finish(sqlite3_backup *p)
cdef int sqlite3_backup_remaining(sqlite3_backup *p)
cdef int sqlite3_backup_pagecount(sqlite3_backup *p)
# Error handling.
cdef int sqlite3_errcode(sqlite3 *db)
cdef int sqlite3_errstr(int)
cdef const char *sqlite3_errmsg(sqlite3 *db)
cdef int sqlite3_blob_open(
sqlite3*,
const char *zDb,
const char *zTable,
const char *zColumn,
sqlite3_int64 iRow,
int flags,
sqlite3_blob **ppBlob)
cdef int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64)
cdef int sqlite3_blob_close(sqlite3_blob *)
cdef int sqlite3_blob_bytes(sqlite3_blob *)
cdef int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset)
cdef int sqlite3_blob_write(sqlite3_blob *, const void *z, int n,
int iOffset)
cdef extern from "_pysqlite/connection.h":
ctypedef struct pysqlite_Connection:
sqlite3* db
double timeout
int initialized
PyObject* isolation_level
char* begin_statement
# The sweepea_vtab struct embeds the base sqlite3_vtab struct, and adds a field
# to store a reference to the Python implementation.
ctypedef struct sweepea_vtab:
sqlite3_vtab base
void *table_func_cls
# Like sweepea_vtab, the sweepea_cursor embeds the base sqlite3_vtab_cursor and
# adds fields to store references to the current index, the Python
# implementation, the current rows' data, and a flag for whether the cursor has
# been exhausted.
ctypedef struct sweepea_cursor:
sqlite3_vtab_cursor base
long long idx
void *table_func
void *row_data
bint stopped