diff options
author | xengineering <me@xengineering.eu> | 2023-12-27 12:16:35 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-12-27 12:21:33 +0100 |
commit | aaf2bad8d3ab2a4f825c2d3db3f2d17de68e08b4 (patch) | |
tree | 31fb3197934eec3bbaca89871b5c095b59f96892 /vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c | |
parent | 318f00c5d496296e45311ea81e8b80d9bd03b1d5 (diff) | |
download | ceres-aaf2bad8d3ab2a4f825c2d3db3f2d17de68e08b4.tar ceres-aaf2bad8d3ab2a4f825c2d3db3f2d17de68e08b4.tar.zst ceres-aaf2bad8d3ab2a4f825c2d3db3f2d17de68e08b4.zip |
Add github.com/mattn/go-sqlite3
This can be used to implement the `database/sql` interface from the Go
standard library for sqlite databases. This is the currently preferred
method to store user data for Ceres.
Diffstat (limited to 'vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c')
-rw-r--r-- | vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c b/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c new file mode 100644 index 0000000..fc37b33 --- /dev/null +++ b/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_unlock_notify.c @@ -0,0 +1,85 @@ +// Copyright (C) 2018 Yasuhiro Matsumoto <mattn.jp@gmail.com>. +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file. + +#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY +#include <stdio.h> +#include "sqlite3-binding.h" + +extern int unlock_notify_wait(sqlite3 *db); + +int +_sqlite3_step_blocking(sqlite3_stmt *stmt) +{ + int rv; + sqlite3* db; + + db = sqlite3_db_handle(stmt); + for (;;) { + rv = sqlite3_step(stmt); + if (rv != SQLITE_LOCKED) { + break; + } + if (sqlite3_extended_errcode(db) != SQLITE_LOCKED_SHAREDCACHE) { + break; + } + rv = unlock_notify_wait(db); + if (rv != SQLITE_OK) { + break; + } + sqlite3_reset(stmt); + } + + return rv; +} + +int +_sqlite3_step_row_blocking(sqlite3_stmt* stmt, long long* rowid, long long* changes) +{ + int rv; + sqlite3* db; + + db = sqlite3_db_handle(stmt); + for (;;) { + rv = sqlite3_step(stmt); + if (rv!=SQLITE_LOCKED) { + break; + } + if (sqlite3_extended_errcode(db) != SQLITE_LOCKED_SHAREDCACHE) { + break; + } + rv = unlock_notify_wait(db); + if (rv != SQLITE_OK) { + break; + } + sqlite3_reset(stmt); + } + + *rowid = (long long) sqlite3_last_insert_rowid(db); + *changes = (long long) sqlite3_changes(db); + return rv; +} + +int +_sqlite3_prepare_v2_blocking(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail) +{ + int rv; + + for (;;) { + rv = sqlite3_prepare_v2(db, zSql, nBytes, ppStmt, pzTail); + if (rv!=SQLITE_LOCKED) { + break; + } + if (sqlite3_extended_errcode(db) != SQLITE_LOCKED_SHAREDCACHE) { + break; + } + rv = unlock_notify_wait(db); + if (rv != SQLITE_OK) { + break; + } + } + + return rv; +} +#endif |