Fork of github.com/mattn/go-sqlite3 v1.14.47, rebranded to package csqlite and vendored in-tree (SQLite amalgamation sqlite3-binding.c/.h + cgo driver + callback trampolines + optional-feature files) so the Hanzo stack depends on no external go-sqlite3 module. Registers the "sqlite3" database/sql driver name from this repo. SQLCipher at-rest encryption unchanged: link system libsqlcipher via -tags libsqlite3. Preserves upstream MIT license (LICENSE) with Hanzo-first NOTICE attribution. Verified: CGO_ENABLED=1 build+test (amalgamation) green; -tags libsqlite3 + libsqlcipher build+test green; CGO_ENABLED=0 build green; zero mattn in deps.
90 lines
1.7 KiB
C
90 lines
1.7 KiB
C
// 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>
|
|
#ifndef USE_LIBSQLITE3
|
|
#include "sqlite3-binding.h"
|
|
#else
|
|
#include <sqlite3.h>
|
|
#endif
|
|
|
|
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
|