aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_opt_unlock_notify.c
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2018-10-21 09:58:17 +0900
committerGitHub <noreply@github.com>2018-10-21 09:58:17 +0900
commitf3aa5ce89995fab8c7777f7821f689d9ac81c80f (patch)
treef02ec47154c3cd4f0f04204345e87870bd21e180 /sqlite3_opt_unlock_notify.c
parentMerge pull request #616 from jung-kurt/patch-1 (diff)
parentRename the wrapper functions to not pollute the sqlite3_* namespace (diff)
downloadgolite-f3aa5ce89995fab8c7777f7821f689d9ac81c80f.tar.gz
golite-f3aa5ce89995fab8c7777f7821f689d9ac81c80f.tar.xz
Merge pull request #439 from typeless/add-unlock-notify
Add support for sqlite3_unlock_notify
Diffstat (limited to 'sqlite3_opt_unlock_notify.c')
-rw-r--r--sqlite3_opt_unlock_notify.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/sqlite3_opt_unlock_notify.c b/sqlite3_opt_unlock_notify.c
new file mode 100644
index 0000000..1af1726
--- /dev/null
+++ b/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