| 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 |
import sys, os |
| 27 |
from cffi import FFI as _FFI |
| 28 |
|
| 29 |
_ffi = _FFI() |
| 30 |
|
| 31 |
_ffi.cdef(""" |
| 32 |
#define SQLITE_OK ... |
| 33 |
#define SQLITE_ERROR ... |
| 34 |
#define SQLITE_INTERNAL ... |
| 35 |
#define SQLITE_PERM ... |
| 36 |
#define SQLITE_ABORT ... |
| 37 |
#define SQLITE_BUSY ... |
| 38 |
#define SQLITE_LOCKED ... |
| 39 |
#define SQLITE_NOMEM ... |
| 40 |
#define SQLITE_READONLY ... |
| 41 |
#define SQLITE_INTERRUPT ... |
| 42 |
#define SQLITE_IOERR ... |
| 43 |
#define SQLITE_CORRUPT ... |
| 44 |
#define SQLITE_NOTFOUND ... |
| 45 |
#define SQLITE_FULL ... |
| 46 |
#define SQLITE_CANTOPEN ... |
| 47 |
#define SQLITE_PROTOCOL ... |
| 48 |
#define SQLITE_EMPTY ... |
| 49 |
#define SQLITE_SCHEMA ... |
| 50 |
#define SQLITE_TOOBIG ... |
| 51 |
#define SQLITE_CONSTRAINT ... |
| 52 |
#define SQLITE_MISMATCH ... |
| 53 |
#define SQLITE_MISUSE ... |
| 54 |
#define SQLITE_NOLFS ... |
| 55 |
#define SQLITE_AUTH ... |
| 56 |
#define SQLITE_FORMAT ... |
| 57 |
#define SQLITE_RANGE ... |
| 58 |
#define SQLITE_NOTADB ... |
| 59 |
#define SQLITE_ROW ... |
| 60 |
#define SQLITE_DONE ... |
| 61 |
#define SQLITE_INTEGER ... |
| 62 |
#define SQLITE_FLOAT ... |
| 63 |
#define SQLITE_BLOB ... |
| 64 |
#define SQLITE_NULL ... |
| 65 |
#define SQLITE_TEXT ... |
| 66 |
#define SQLITE3_TEXT ... |
| 67 |
|
| 68 |
static void *const SQLITE_TRANSIENT; |
| 69 |
#define SQLITE_UTF8 ... |
| 70 |
|
| 71 |
#define SQLITE_DENY ... |
| 72 |
#define SQLITE_IGNORE ... |
| 73 |
|
| 74 |
#define SQLITE_ALTER_TABLE ... |
| 75 |
#define SQLITE_ANALYZE ... |
| 76 |
#define SQLITE_ATTACH ... |
| 77 |
#define SQLITE_CREATE_INDEX ... |
| 78 |
#define SQLITE_CREATE_TABLE ... |
| 79 |
#define SQLITE_CREATE_TEMP_INDEX ... |
| 80 |
#define SQLITE_CREATE_TEMP_TABLE ... |
| 81 |
#define SQLITE_CREATE_TEMP_TRIGGER ... |
| 82 |
#define SQLITE_CREATE_TEMP_VIEW ... |
| 83 |
#define SQLITE_CREATE_TRIGGER ... |
| 84 |
#define SQLITE_CREATE_VIEW ... |
| 85 |
#define SQLITE_CREATE_VTABLE ... |
| 86 |
#define SQLITE_DELETE ... |
| 87 |
#define SQLITE_DETACH ... |
| 88 |
#define SQLITE_DROP_INDEX ... |
| 89 |
#define SQLITE_DROP_TABLE ... |
| 90 |
#define SQLITE_DROP_TEMP_INDEX ... |
| 91 |
#define SQLITE_DROP_TEMP_TABLE ... |
| 92 |
#define SQLITE_DROP_TEMP_TRIGGER ... |
| 93 |
#define SQLITE_DROP_TEMP_VIEW ... |
| 94 |
#define SQLITE_DROP_TRIGGER ... |
| 95 |
#define SQLITE_DROP_VIEW ... |
| 96 |
#define SQLITE_DROP_VTABLE ... |
| 97 |
#define SQLITE_FUNCTION ... |
| 98 |
#define SQLITE_INSERT ... |
| 99 |
#define SQLITE_NOTICE ... |
| 100 |
#define SQLITE_PRAGMA ... |
| 101 |
#define SQLITE_READ ... |
| 102 |
#define SQLITE_RECURSIVE ... |
| 103 |
#define SQLITE_REINDEX ... |
| 104 |
#define SQLITE_SAVEPOINT ... |
| 105 |
#define SQLITE_SELECT ... |
| 106 |
#define SQLITE_TRANSACTION ... |
| 107 |
#define SQLITE_UPDATE ... |
| 108 |
#define SQLITE_WARNING ... |
| 109 |
#define SQLITE_ABORT_ROLLBACK ... |
| 110 |
#define SQLITE_BUSY_RECOVERY ... |
| 111 |
#define SQLITE_CANTOPEN_FULLPATH ... |
| 112 |
#define SQLITE_CANTOPEN_ISDIR ... |
| 113 |
#define SQLITE_CANTOPEN_NOTEMPDIR ... |
| 114 |
#define SQLITE_CORRUPT_VTAB ... |
| 115 |
#define SQLITE_IOERR_ACCESS ... |
| 116 |
#define SQLITE_IOERR_BLOCKED ... |
| 117 |
#define SQLITE_IOERR_CHECKRESERVEDLOCK ... |
| 118 |
#define SQLITE_IOERR_CLOSE ... |
| 119 |
#define SQLITE_IOERR_DELETE ... |
| 120 |
#define SQLITE_IOERR_DELETE_NOENT ... |
| 121 |
#define SQLITE_IOERR_DIR_CLOSE ... |
| 122 |
#define SQLITE_IOERR_DIR_FSYNC ... |
| 123 |
#define SQLITE_IOERR_FSTAT ... |
| 124 |
#define SQLITE_IOERR_FSYNC ... |
| 125 |
#define SQLITE_IOERR_LOCK ... |
| 126 |
#define SQLITE_IOERR_NOMEM ... |
| 127 |
#define SQLITE_IOERR_RDLOCK ... |
| 128 |
#define SQLITE_IOERR_READ ... |
| 129 |
#define SQLITE_IOERR_SEEK ... |
| 130 |
#define SQLITE_IOERR_SHMLOCK ... |
| 131 |
#define SQLITE_IOERR_SHMMAP ... |
| 132 |
#define SQLITE_IOERR_SHMOPEN ... |
| 133 |
#define SQLITE_IOERR_SHMSIZE ... |
| 134 |
#define SQLITE_IOERR_SHORT_READ ... |
| 135 |
#define SQLITE_IOERR_TRUNCATE ... |
| 136 |
#define SQLITE_IOERR_UNLOCK ... |
| 137 |
#define SQLITE_IOERR_WRITE ... |
| 138 |
#define SQLITE_LOCKED_SHAREDCACHE ... |
| 139 |
#define SQLITE_READONLY_CANTLOCK ... |
| 140 |
#define SQLITE_READONLY_RECOVERY ... |
| 141 |
|
| 142 |
#define SQLITE_LIMIT_SQL_LENGTH ... |
| 143 |
#define SQLITE_LIMIT_LENGTH ... |
| 144 |
#define SQLITE_LIMIT_COLUMN ... |
| 145 |
#define SQLITE_LIMIT_EXPR_DEPTH ... |
| 146 |
#define SQLITE_LIMIT_COMPOUND_SELECT ... |
| 147 |
#define SQLITE_LIMIT_VDBE_OP ... |
| 148 |
#define SQLITE_LIMIT_FUNCTION_ARG ... |
| 149 |
#define SQLITE_LIMIT_ATTACHED ... |
| 150 |
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH ... |
| 151 |
#define SQLITE_LIMIT_VARIABLE_NUMBER ... |
| 152 |
#define SQLITE_LIMIT_TRIGGER_DEPTH ... |
| 153 |
|
| 154 |
#define SQLITE_SERIALIZE_NOCOPY ... |
| 155 |
#define SQLITE_DESERIALIZE_FREEONCLOSE ... |
| 156 |
#define SQLITE_DESERIALIZE_RESIZEABLE ... |
| 157 |
|
| 158 |
#define SQLITE_TRACE_STMT ... |
| 159 |
|
| 160 |
static const long SQLITE_OPEN_URI; |
| 161 |
static const long SQLITE_OPEN_READWRITE; |
| 162 |
static const long SQLITE_OPEN_CREATE; |
| 163 |
|
| 164 |
const char *sqlite3_libversion(void); |
| 165 |
int sqlite3_libversion_number(void); |
| 166 |
|
| 167 |
typedef ... sqlite3; |
| 168 |
typedef ... sqlite3_stmt; |
| 169 |
typedef ... sqlite3_context; |
| 170 |
typedef ... sqlite3_value; |
| 171 |
typedef long long int sqlite3_int64; |
| 172 |
typedef unsigned long long int sqlite3_uint64; |
| 173 |
|
| 174 |
int sqlite3_open( |
| 175 |
const char *filename, /* Database filename (UTF-8) */ |
| 176 |
sqlite3 **ppDb /* OUT: SQLite db handle */ |
| 177 |
); |
| 178 |
|
| 179 |
int sqlite3_open_v2( |
| 180 |
const char *filename, /* Database filename (UTF-8) */ |
| 181 |
sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 182 |
int flags, /* Flags */ |
| 183 |
const char *zVfs /* Name of VFS module to use */ |
| 184 |
); |
| 185 |
|
| 186 |
int sqlite3_close(sqlite3 *); |
| 187 |
|
| 188 |
int sqlite3_busy_timeout(sqlite3*, int ms); |
| 189 |
int sqlite3_prepare_v2( |
| 190 |
sqlite3 *db, /* Database handle */ |
| 191 |
const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 192 |
int nByte, /* Maximum length of zSql in bytes. */ |
| 193 |
sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 194 |
const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 195 |
); |
| 196 |
int sqlite3_finalize(sqlite3_stmt *pStmt); |
| 197 |
int sqlite3_data_count(sqlite3_stmt *pStmt); |
| 198 |
int sqlite3_column_count(sqlite3_stmt *pStmt); |
| 199 |
const char *sqlite3_column_name(sqlite3_stmt*, int N); |
| 200 |
int sqlite3_get_autocommit(sqlite3*); |
| 201 |
int sqlite3_reset(sqlite3_stmt *pStmt); |
| 202 |
int sqlite3_step(sqlite3_stmt*); |
| 203 |
int sqlite3_errcode(sqlite3 *db); |
| 204 |
int sqlite3_extended_errcode(sqlite3 *db); |
| 205 |
const char *sqlite3_errmsg(sqlite3*); |
| 206 |
int sqlite3_changes(sqlite3*); |
| 207 |
|
| 208 |
int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); |
| 209 |
int sqlite3_bind_double(sqlite3_stmt*, int, double); |
| 210 |
int sqlite3_bind_int(sqlite3_stmt*, int, int); |
| 211 |
int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
| 212 |
int sqlite3_bind_null(sqlite3_stmt*, int); |
| 213 |
int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); |
| 214 |
int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); |
| 215 |
int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 216 |
int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 217 |
|
| 218 |
const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); |
| 219 |
int sqlite3_column_bytes(sqlite3_stmt*, int iCol); |
| 220 |
double sqlite3_column_double(sqlite3_stmt*, int iCol); |
| 221 |
int sqlite3_column_int(sqlite3_stmt*, int iCol); |
| 222 |
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); |
| 223 |
const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); |
| 224 |
const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); |
| 225 |
int sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 226 |
const char *sqlite3_column_decltype(sqlite3_stmt*,int); |
| 227 |
|
| 228 |
void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 229 |
int sqlite3_trace_v2( |
| 230 |
sqlite3*, |
| 231 |
unsigned uMask, |
| 232 |
int(*xCallback)(unsigned,void*,void*,void*), |
| 233 |
void *pCtx |
| 234 |
); |
| 235 |
char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); |
| 236 |
|
| 237 |
int sqlite3_create_collation( |
| 238 |
sqlite3*, |
| 239 |
const char *zName, |
| 240 |
int eTextRep, |
| 241 |
void*, |
| 242 |
int(*xCompare)(void*,int,const void*,int,const void*) |
| 243 |
); |
| 244 |
int sqlite3_set_authorizer( |
| 245 |
sqlite3*, |
| 246 |
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 247 |
void *pUserData |
| 248 |
); |
| 249 |
int sqlite3_create_function( |
| 250 |
sqlite3 *db, |
| 251 |
const char *zFunctionName, |
| 252 |
int nArg, |
| 253 |
int eTextRep, |
| 254 |
void *pApp, |
| 255 |
void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 256 |
void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 257 |
void (*xFinal)(sqlite3_context*) |
| 258 |
); |
| 259 |
void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 260 |
|
| 261 |
int sqlite3_create_window_function( |
| 262 |
sqlite3 *db, |
| 263 |
const char *zFunctionName, |
| 264 |
int nArg, |
| 265 |
int eTextRep, |
| 266 |
void *pApp, |
| 267 |
void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 268 |
void (*xFinal)(sqlite3_context*), |
| 269 |
void (*xValue)(sqlite3_context*), |
| 270 |
void (*xInverse)(sqlite3_context*,int,sqlite3_value**), |
| 271 |
void(*xDestroy)(void*) |
| 272 |
); |
| 273 |
|
| 274 |
sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 275 |
int sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 276 |
const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 277 |
int sqlite3_total_changes(sqlite3*); |
| 278 |
|
| 279 |
int sqlite3_prepare( |
| 280 |
sqlite3 *db, /* Database handle */ |
| 281 |
const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 282 |
int nByte, /* Maximum length of zSql in bytes. */ |
| 283 |
sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 284 |
const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 285 |
); |
| 286 |
|
| 287 |
void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); |
| 288 |
void sqlite3_result_double(sqlite3_context*, double); |
| 289 |
void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 290 |
void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 291 |
void sqlite3_result_error_toobig(sqlite3_context*); |
| 292 |
void sqlite3_result_error_nomem(sqlite3_context*); |
| 293 |
void sqlite3_result_error_code(sqlite3_context*, int); |
| 294 |
void sqlite3_result_int(sqlite3_context*, int); |
| 295 |
void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
| 296 |
void sqlite3_result_null(sqlite3_context*); |
| 297 |
void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); |
| 298 |
void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); |
| 299 |
void sqlite3_result_text16le(sqlite3_context*,const void*, int,void(*)(void*)); |
| 300 |
void sqlite3_result_text16be(sqlite3_context*,const void*, int,void(*)(void*)); |
| 301 |
void sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 302 |
void sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 303 |
|
| 304 |
const void *sqlite3_value_blob(sqlite3_value*); |
| 305 |
int sqlite3_value_bytes(sqlite3_value*); |
| 306 |
int sqlite3_value_bytes16(sqlite3_value*); |
| 307 |
double sqlite3_value_double(sqlite3_value*); |
| 308 |
int sqlite3_value_int(sqlite3_value*); |
| 309 |
sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| 310 |
const unsigned char *sqlite3_value_text(sqlite3_value*); |
| 311 |
const void *sqlite3_value_text16(sqlite3_value*); |
| 312 |
const void *sqlite3_value_text16le(sqlite3_value*); |
| 313 |
const void *sqlite3_value_text16be(sqlite3_value*); |
| 314 |
int sqlite3_value_type(sqlite3_value*); |
| 315 |
int sqlite3_value_numeric_type(sqlite3_value*); |
| 316 |
|
| 317 |
int sqlite3_sleep(int); |
| 318 |
const char *sqlite3_errstr(int); |
| 319 |
int sqlite3_complete(const char *sql); |
| 320 |
|
| 321 |
int sqlite3_limit(sqlite3*, int, int); |
| 322 |
|
| 323 |
void *sqlite3_malloc(int); |
| 324 |
void *sqlite3_malloc64(sqlite3_uint64); |
| 325 |
void sqlite3_free(void*); |
| 326 |
|
| 327 |
// APIs for BLOBs |
| 328 |
|
| 329 |
typedef ... sqlite3_blob; |
| 330 |
int sqlite3_blob_open( |
| 331 |
sqlite3*, |
| 332 |
const char *zDb, |
| 333 |
const char *zTable, |
| 334 |
const char *zColumn, |
| 335 |
sqlite3_int64 iRow, |
| 336 |
int flags, |
| 337 |
sqlite3_blob **ppBlob |
| 338 |
); |
| 339 |
int sqlite3_blob_close(sqlite3_blob *); |
| 340 |
int sqlite3_blob_bytes(sqlite3_blob *); |
| 341 |
int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 342 |
int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); |
| 343 |
|
| 344 |
int sqlite3_threadsafe(void); |
| 345 |
void sqlite3_interrupt(sqlite3*); |
| 346 |
""") |
| 347 |
|
| 348 |
def _has_load_extension(): |
| 349 |
"""Only available since 3.3.6""" |
| 350 |
unverified_ffi = _FFI() |
| 351 |
unverified_ffi.cdef(""" |
| 352 |
typedef ... sqlite3; |
| 353 |
int sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
| 354 |
""") |
| 355 |
libname = 'sqlite3' |
| 356 |
if sys.platform == 'win32': |
| 357 |
import os |
| 358 |
_libname = os.path.join(os.path.dirname(sys.executable), libname) |
| 359 |
if os.path.exists(_libname + '.dll'): |
| 360 |
libname = _libname |
| 361 |
unverified_lib = unverified_ffi.dlopen(libname) |
| 362 |
return hasattr(unverified_lib, 'sqlite3_enable_load_extension') |
| 363 |
|
| 364 |
def _has_backup(): |
| 365 |
"""Only available since 3.6.11""" |
| 366 |
unverified_ffi = _FFI() |
| 367 |
unverified_ffi.cdef(""" |
| 368 |
typedef ... sqlite3; |
| 369 |
typedef ... sqlite3_backup; |
| 370 |
sqlite3_backup* sqlite3_backup_init(sqlite3 *, const char* , sqlite3 *, const char*); |
| 371 |
""") |
| 372 |
libname = 'sqlite3' |
| 373 |
if sys.platform == 'win32': |
| 374 |
import os |
| 375 |
_libname = os.path.join(os.path.dirname(sys.executable), libname) |
| 376 |
if os.path.exists(_libname + '.dll'): |
| 377 |
libname = _libname |
| 378 |
unverified_lib = unverified_ffi.dlopen(libname) |
| 379 |
return hasattr(unverified_lib, 'sqlite3_backup_init') |
| 380 |
|
| 381 |
def _get_version(): |
| 382 |
unverified_ffi = _FFI() |
| 383 |
unverified_ffi.cdef(""" |
| 384 |
int sqlite3_libversion_number(void); |
| 385 |
""") |
| 386 |
libname = 'sqlite3' |
| 387 |
if sys.platform == 'win32': |
| 388 |
import os |
| 389 |
_libname = os.path.join(os.path.dirname(sys.executable), libname) |
| 390 |
if os.path.exists(_libname + '.dll'): |
| 391 |
libname = _libname |
| 392 |
unverified_lib = unverified_ffi.dlopen(libname) |
| 393 |
return unverified_lib.sqlite3_libversion_number() |
| 394 |
|
| 395 |
|
| 396 |
if _has_load_extension(): |
| 397 |
_ffi.cdef("int sqlite3_enable_load_extension(sqlite3 *db, int onoff);") |
| 398 |
_ffi.cdef("int sqlite3_load_extension(sqlite3 *db, const char *, " |
| 399 |
"const char *, char **);") |
| 400 |
if _has_backup(): |
| 401 |
_ffi.cdef(""" |
| 402 |
typedef ... sqlite3_backup; |
| 403 |
sqlite3_backup *sqlite3_backup_init(sqlite3 *, const char*, sqlite3 *, const char*); |
| 404 |
int sqlite3_backup_step(sqlite3_backup *p, int nPage); |
| 405 |
int sqlite3_backup_finish(sqlite3_backup *p); |
| 406 |
int sqlite3_backup_remaining(sqlite3_backup *p); |
| 407 |
int sqlite3_backup_pagecount(sqlite3_backup *p); |
| 408 |
""") |
| 409 |
|
| 410 |
SQLITE3_VERSION = _get_version() |
| 411 |
if SQLITE3_VERSION >= 3008003: |
| 412 |
_ffi.cdef(""" |
| 413 |
#define SQLITE_DETERMINISTIC ... |
| 414 |
""") |
| 415 |
|
| 416 |
if SQLITE3_VERSION >= 3007016: |
| 417 |
_ffi.cdef(""" |
| 418 |
#define SQLITE_CONSTRAINT_CHECK ... |
| 419 |
#define SQLITE_CONSTRAINT_COMMITHOOK ... |
| 420 |
#define SQLITE_CONSTRAINT_FOREIGNKEY ... |
| 421 |
#define SQLITE_CONSTRAINT_FUNCTION ... |
| 422 |
#define SQLITE_CONSTRAINT_NOTNULL ... |
| 423 |
#define SQLITE_CONSTRAINT_PRIMARYKEY ... |
| 424 |
#define SQLITE_CONSTRAINT_TRIGGER ... |
| 425 |
#define SQLITE_CONSTRAINT_UNIQUE ... |
| 426 |
#define SQLITE_CONSTRAINT_VTAB ... |
| 427 |
#define SQLITE_READONLY_ROLLBACK ... |
| 428 |
""") |
| 429 |
|
| 430 |
if SQLITE3_VERSION >= 3007017: |
| 431 |
_ffi.cdef(""" |
| 432 |
#define SQLITE_IOERR_MMAP ... |
| 433 |
#define SQLITE_NOTICE_RECOVER_ROLLBACK ... |
| 434 |
#define SQLITE_NOTICE_RECOVER_WAL ... |
| 435 |
""") |
| 436 |
|
| 437 |
if SQLITE3_VERSION >= 3008000: |
| 438 |
_ffi.cdef(""" |
| 439 |
#define SQLITE_BUSY_SNAPSHOT ... |
| 440 |
#define SQLITE_IOERR_GETTEMPPATH ... |
| 441 |
#define SQLITE_WARNING_AUTOINDEX ... |
| 442 |
""") |
| 443 |
|
| 444 |
if SQLITE3_VERSION >= 3008001: |
| 445 |
_ffi.cdef(""" |
| 446 |
#define SQLITE_CANTOPEN_CONVPATH ... |
| 447 |
#define SQLITE_IOERR_CONVPATH ... |
| 448 |
""") |
| 449 |
|
| 450 |
if SQLITE3_VERSION >= 3008002: |
| 451 |
_ffi.cdef(""" |
| 452 |
#define SQLITE_CONSTRAINT_ROWID ... |
| 453 |
""") |
| 454 |
|
| 455 |
if SQLITE3_VERSION >= 3008003: |
| 456 |
_ffi.cdef(""" |
| 457 |
#define SQLITE_READONLY_DBMOVED ... |
| 458 |
""") |
| 459 |
|
| 460 |
if SQLITE3_VERSION >= 3008007: |
| 461 |
_ffi.cdef(""" |
| 462 |
#define SQLITE_AUTH_USER ... |
| 463 |
#define SQLITE_LIMIT_WORKER_THREADS ... |
| 464 |
""") |
| 465 |
|
| 466 |
if SQLITE3_VERSION >= 3009000: |
| 467 |
_ffi.cdef(""" |
| 468 |
#define SQLITE_IOERR_VNODE ... |
| 469 |
""") |
| 470 |
|
| 471 |
if SQLITE3_VERSION >= 3010000: |
| 472 |
_ffi.cdef(""" |
| 473 |
#define SQLITE_IOERR_AUTH ... |
| 474 |
""") |
| 475 |
|
| 476 |
if SQLITE3_VERSION >= 3014001: |
| 477 |
_ffi.cdef(""" |
| 478 |
#define SQLITE_OK_LOAD_PERMANENTLY ... |
| 479 |
""") |
| 480 |
|
| 481 |
if SQLITE3_VERSION >= 3021000: |
| 482 |
_ffi.cdef(""" |
| 483 |
#define SQLITE_IOERR_BEGIN_ATOMIC ... |
| 484 |
#define SQLITE_IOERR_COMMIT_ATOMIC ... |
| 485 |
#define SQLITE_IOERR_ROLLBACK_ATOMIC ... |
| 486 |
""") |
| 487 |
|
| 488 |
if SQLITE3_VERSION >= 3022000: |
| 489 |
_ffi.cdef(""" |
| 490 |
#define SQLITE_ERROR_MISSING_COLLSEQ ... |
| 491 |
#define SQLITE_ERROR_RETRY ... |
| 492 |
#define SQLITE_READONLY_CANTINIT ... |
| 493 |
#define SQLITE_READONLY_DIRECTORY ... |
| 494 |
""") |
| 495 |
|
| 496 |
if SQLITE3_VERSION >= 3024000: |
| 497 |
_ffi.cdef(""" |
| 498 |
#define SQLITE_CORRUPT_SEQUENCE ... |
| 499 |
#define SQLITE_LOCKED_VTAB ... |
| 500 |
""") |
| 501 |
|
| 502 |
if SQLITE3_VERSION >= 3025000: |
| 503 |
_ffi.cdef(""" |
| 504 |
#define SQLITE_CANTOPEN_DIRTYWAL ... |
| 505 |
#define SQLITE_ERROR_SNAPSHOT ... |
| 506 |
""") |
| 507 |
|
| 508 |
if SQLITE3_VERSION >= 3031000: |
| 509 |
_ffi.cdef(""" |
| 510 |
#define SQLITE_CANTOPEN_SYMLINK ... |
| 511 |
#define SQLITE_CONSTRAINT_PINNED ... |
| 512 |
#define SQLITE_OK_SYMLINK ... |
| 513 |
""") |
| 514 |
|
| 515 |
if SQLITE3_VERSION >= 3032000: |
| 516 |
_ffi.cdef(""" |
| 517 |
#define SQLITE_BUSY_TIMEOUT ... |
| 518 |
#define SQLITE_CORRUPT_INDEX ... |
| 519 |
#define SQLITE_IOERR_DATA ... |
| 520 |
""") |
| 521 |
|
| 522 |
if SQLITE3_VERSION >= 3034000: |
| 523 |
_ffi.cdef(""" |
| 524 |
#define SQLITE_IOERR_CORRUPTFS ... |
| 525 |
""") |
| 526 |
|
| 527 |
if SQLITE3_VERSION >= 3036000: |
| 528 |
_ffi.cdef(""" |
| 529 |
unsigned char *sqlite3_serialize( |
| 530 |
sqlite3 *db, |
| 531 |
const char *zSchema, |
| 532 |
sqlite3_int64 *piSize, |
| 533 |
unsigned int mFlags |
| 534 |
); |
| 535 |
int sqlite3_deserialize( |
| 536 |
sqlite3 *db, |
| 537 |
const char *zSchema, |
| 538 |
unsigned char *pData, |
| 539 |
sqlite3_int64 szDb, |
| 540 |
sqlite3_int64 szBuf, |
| 541 |
unsigned mFlags |
| 542 |
); |
| 543 |
""") |
| 544 |
|
| 545 |
|
| 546 |
libraries=['sqlite3'] |
| 547 |
if sys.platform.startswith('freebsd'): |
| 548 |
_localbase = os.environ.get('LOCALBASE', '/usr/local') |
| 549 |
extra_args = dict( |
| 550 |
libraries=libraries, |
| 551 |
include_dirs=[os.path.join(_localbase, 'include')], |
| 552 |
library_dirs=[os.path.join(_localbase, 'lib')] |
| 553 |
) |
| 554 |
else: |
| 555 |
extra_args = dict( |
| 556 |
libraries=libraries, |
| 557 |
) |
| 558 |
|
| 559 |
SOURCE = """ |
| 560 |
#include <sqlite3.h> |
| 561 |
|
| 562 |
#ifndef SQLITE_OPEN_URI |
| 563 |
static const long SQLITE_OPEN_URI = 0; |
| 564 |
#endif |
| 565 |
#ifndef SQLITE_OPEN_READWRITE |
| 566 |
static const long SQLITE_OPEN_READWRITE = 0; |
| 567 |
#endif |
| 568 |
#ifndef SQLITE_OPEN_CREATE |
| 569 |
static const long SQLITE_OPEN_CREATE = 0; |
| 570 |
#endif |
| 571 |
""" |
| 572 |
|
| 573 |
_ffi.set_source("_sqlite3_cffi", SOURCE, **extra_args) |
| 574 |
|
| 575 |
|
| 576 |
if __name__ == "__main__": |
| 577 |
_ffi.compile() |
| 578 |
if sys.platform == 'win32': |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
import os, glob, shutil |
| 583 |
path_parts = os.environ['PATH'].split(';') |
| 584 |
candidates = [x for x in path_parts if 'externals' in x] |
| 585 |
|
| 586 |
def copy_from_path(dll): |
| 587 |
for c in candidates: |
| 588 |
files = glob.glob(os.path.join(c, dll + '*.dll')) |
| 589 |
if files: |
| 590 |
for fname in files: |
| 591 |
print('copying', fname) |
| 592 |
shutil.copy(fname, '.') |
| 593 |
|
| 594 |
if candidates: |
| 595 |
for lib in libraries: |
| 596 |
copy_from_path(lib) |