Skip to content

Commit 16477f3

Browse files
committed
Add grdb.h header to enable inclusion in GRDB
1 parent 81e2394 commit 16477f3

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ library (e.g., Android, Windows).
3333
[Schema query/migration]: Documentation/Index.md#querying-the-schema
3434
[See Documentation]: Documentation/Index.md#sqliteswift-documentation
3535

36-
## Usage
36+
## SQLiteDB
3737

3838
```swift
3939
import SQLiteDB
@@ -135,12 +135,6 @@ Swift code.
135135

136136
## Communication
137137

138-
[Read the contributing guidelines][]. The _TL;DR_ (but please; _R_):
139-
140-
- Found a **bug** or have a **feature request**? [Open an issue][].
141-
- Want to **contribute**? [Submit a pull request][].
142-
143-
[Read the contributing guidelines]: ./CONTRIBUTING.md#contributing
144138
[Open an issue]: https://github.com/skiptools/swift-sqlcipher/issues/new
145139
[Submit a pull request]: https://github.com/skiptools/swift-sqlcipher/pulls
146140

@@ -157,6 +151,7 @@ Here are a number of other popular SQLite alternative packages:
157151
- [swift-toolchain-sqlite](https://github.com/swiftlang/swift-toolchain-sqlite)
158152
- [FMDB]
159153

154+
[SQLiteDB]: #sqlitedb
160155
[SQLite3]: https://www.sqlite.org
161156
[SQLite.swift]: https://github.com/stephencelis/SQLite.swift
162157
[FMDB]: https://github.com/ccgus/fmdb

Sources/SQLCipher/sqlite/grdb.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <sqlite3.h>
2+
3+
// Support for GRDB-specific functions.
4+
// Duplicates https://github.com/groue/GRDB.swift/blob/development/Sources/GRDBSQLite/shim.h
5+
6+
typedef void(*_errorLogCallback)(void *pArg, int iErrCode, const char *zMsg);
7+
8+
/// Wrapper around sqlite3_config(SQLITE_CONFIG_LOG, ...) which is a variadic
9+
/// function that can't be used from Swift.
10+
static inline void _registerErrorLogCallback(_errorLogCallback callback) {
11+
sqlite3_config(SQLITE_CONFIG_LOG, callback, 0);
12+
}
13+
14+
#if SQLITE_VERSION_NUMBER >= 3029000
15+
/// Wrapper around sqlite3_db_config() which is a variadic function that can't
16+
/// be used from Swift.
17+
static inline void _disableDoubleQuotedStringLiterals(sqlite3 *db) {
18+
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, (void *)0);
19+
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, (void *)0);
20+
}
21+
22+
/// Wrapper around sqlite3_db_config() which is a variadic function that can't
23+
/// be used from Swift.
24+
static inline void _enableDoubleQuotedStringLiterals(sqlite3 *db) {
25+
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 1, (void *)0);
26+
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 1, (void *)0);
27+
}
28+
#else
29+
static inline void _disableDoubleQuotedStringLiterals(sqlite3 *db) { }
30+
static inline void _enableDoubleQuotedStringLiterals(sqlite3 *db) { }
31+
#endif
32+
33+
// Expose APIs that are missing from system <sqlite3.h>
34+
#ifdef GRDB_SQLITE_ENABLE_PREUPDATE_HOOK
35+
SQLITE_API void *sqlite3_preupdate_hook(
36+
sqlite3 *db,
37+
void(*xPreUpdate)(
38+
void *pCtx, /* Copy of third arg to preupdate_hook() */
39+
sqlite3 *db, /* Database handle */
40+
int op, /* SQLITE_UPDATE, DELETE or INSERT */
41+
char const *zDb, /* Database name */
42+
char const *zName, /* Table name */
43+
sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
44+
sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
45+
),
46+
void*
47+
);
48+
SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
49+
SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
50+
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
51+
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
52+
#endif /* GRDB_SQLITE_ENABLE_PREUPDATE_HOOK */
53+

0 commit comments

Comments
 (0)