mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
The difficulty is that system <sqlite3.h> does not contain the expected declarations, even when SQLite is compiled with SQLITE_ENABLE_SNAPSHOT :-( Since snapshots are not exposed in any public API, we don't bother dealing with availability checks. We just add the missing declarations, and rely on the linker in order to spot eventual errors. This commit is likely to break Linux builds, though.
53 lines
1.9 KiB
C
53 lines
1.9 KiB
C
#include <sqlite3.h>
|
|
|
|
typedef void(*errorLogCallback)(void *pArg, int iErrCode, const char *zMsg);
|
|
|
|
/// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic
|
|
/// function that can't be used from Swift.
|
|
static inline void registerErrorLogCallback(errorLogCallback callback) {
|
|
sqlite3_config(SQLITE_CONFIG_LOG, callback, 0);
|
|
}
|
|
|
|
#if SQLITE_VERSION_NUMBER >= 3029000
|
|
/// Wrapper around sqlite3_db_config() which is a variadic function that can't
|
|
/// be used from Swift.
|
|
static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) {
|
|
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, (void *)0);
|
|
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, (void *)0);
|
|
}
|
|
|
|
/// Wrapper around sqlite3_db_config() which is a variadic function that can't
|
|
/// be used from Swift.
|
|
static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) {
|
|
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 1, (void *)0);
|
|
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 1, (void *)0);
|
|
}
|
|
#else
|
|
static inline void disableDoubleQuotedStringLiterals(sqlite3 *db) { }
|
|
static inline void enableDoubleQuotedStringLiterals(sqlite3 *db) { }
|
|
#endif
|
|
|
|
/* Expose missing APIs for easier GRDB development*/
|
|
#ifndef SQLITE_ENABLE_SNAPSHOT
|
|
/* Expose APIs that are missing from system <sqlite3.h> */
|
|
typedef struct sqlite3_snapshot {
|
|
unsigned char hidden[48];
|
|
} sqlite3_snapshot;
|
|
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
|
|
sqlite3 *db,
|
|
const char *zSchema,
|
|
sqlite3_snapshot **ppSnapshot
|
|
);
|
|
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
|
|
sqlite3 *db,
|
|
const char *zSchema,
|
|
sqlite3_snapshot *pSnapshot
|
|
);
|
|
SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
|
|
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
|
|
sqlite3_snapshot *p1,
|
|
sqlite3_snapshot *p2
|
|
);
|
|
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
|
|
#endif /* SQLITE_ENABLE_SNAPSHOT */
|