diff options
author | Mura Li <mura_li@example.com> | 2018-09-30 10:06:56 +0800 |
---|---|---|
committer | Mura Li <mura_li@example.com> | 2018-10-20 10:15:13 +0800 |
commit | eb08795f52358ce90e601fe964c564ad27cf73e0 (patch) | |
tree | 52f18afd7be0147ef31ba61acd633d40b990ac2c /sqlite3.go | |
parent | Merge pull request #616 from jung-kurt/patch-1 (diff) | |
download | golite-eb08795f52358ce90e601fe964c564ad27cf73e0.tar.gz golite-eb08795f52358ce90e601fe964c564ad27cf73e0.tar.xz |
Add support for sqlite3_unlock_notify
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 45 |
1 files changed, 41 insertions, 4 deletions
@@ -78,8 +78,38 @@ _sqlite3_exec(sqlite3* db, const char* pcmd, long long* rowid, long long* change return rv; } +#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY +extern int sqlite3_step_blocking(sqlite3_stmt *stmt); +extern int _sqlite3_step_blocking(sqlite3_stmt* stmt, long long* rowid, long long* changes); +extern int sqlite3_prepare_v2_blocking(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail); + +static int +sqlite3_step_internal(sqlite3_stmt *stmt) +{ + return sqlite3_step_blocking(stmt); +} + +static int +_sqlite3_step_internal(sqlite3_stmt* stmt, long long* rowid, long long* changes) +{ + return _sqlite3_step_blocking(stmt, rowid, changes); +} + static int -_sqlite3_step(sqlite3_stmt* stmt, long long* rowid, long long* changes) +sqlite3_prepare_v2_internal(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail) +{ + return sqlite3_prepare_v2_blocking(db, zSql, nBytes, ppStmt, pzTail); +} + +#else +static int +sqlite3_step_internal(sqlite3_stmt *stmt) +{ + return sqlite3_step(stmt); +} + +static int +_sqlite3_step_internal(sqlite3_stmt* stmt, long long* rowid, long long* changes) { int rv = sqlite3_step(stmt); sqlite3* db = sqlite3_db_handle(stmt); @@ -88,6 +118,13 @@ _sqlite3_step(sqlite3_stmt* stmt, long long* rowid, long long* changes) return rv; } +static int +sqlite3_prepare_v2_internal(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail) +{ + return sqlite3_prepare_v2(db, zSql, nBytes, ppStmt, pzTail); +} +#endif + void _sqlite3_result_text(sqlite3_context* ctx, const char* s) { sqlite3_result_text(ctx, s, -1, &free); } @@ -1637,7 +1674,7 @@ func (c *SQLiteConn) prepare(ctx context.Context, query string) (driver.Stmt, er defer C.free(unsafe.Pointer(pquery)) var s *C.sqlite3_stmt var tail *C.char - rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &tail) + rv := C.sqlite3_prepare_v2_internal(c.db, pquery, -1, &s, &tail) if rv != C.SQLITE_OK { return nil, c.lastError() } @@ -1871,7 +1908,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result } var rowid, changes C.longlong - rv := C._sqlite3_step(s.s, &rowid, &changes) + rv := C._sqlite3_step_internal(s.s, &rowid, &changes) if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE { err := s.c.lastError() C.sqlite3_reset(s.s) @@ -1943,7 +1980,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error { if rc.s.closed { return io.EOF } - rv := C.sqlite3_step(rc.s.s) + rv := C.sqlite3_step_internal(rc.s.s) if rv == C.SQLITE_DONE { return io.EOF } |