sqlite thread safety and extended result codes, mainly.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4183 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-02-17 22:43:19 +00:00
parent 8e1461b3f1
commit 4bea8bb6ba
4 changed files with 9 additions and 0 deletions

View File

@ -221,6 +221,7 @@ $(SQLITE_OBJS): CFLAGS += \
-DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \ -DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \
-DSQLITE_ENABLE_FTS5 \ -DSQLITE_ENABLE_FTS5 \
-DSQLITE_ENABLE_JSON1 \ -DSQLITE_ENABLE_JSON1 \
-DSQLITE_THREADSAFE=1 \
-DSQLITE_MAX_LENGTH=5242880 \ -DSQLITE_MAX_LENGTH=5242880 \
-DSQLITE_MAX_SQL_LENGTH=100000 \ -DSQLITE_MAX_SQL_LENGTH=100000 \
-DSQLITE_MAX_COLUMN=100 \ -DSQLITE_MAX_COLUMN=100 \

View File

@ -2148,6 +2148,7 @@ sqlite3* tf_ssb_acquire_db_reader(tf_ssb_t* ssb)
else else
{ {
sqlite3_open_v2(ssb->db_path, &db, SQLITE_OPEN_READONLY, NULL); sqlite3_open_v2(ssb->db_path, &db, SQLITE_OPEN_READONLY, NULL);
tf_ssb_db_init_reader(db);
} }
uv_mutex_unlock(&ssb->db_readers_lock); uv_mutex_unlock(&ssb->db_readers_lock);
return db; return db;

View File

@ -53,10 +53,16 @@ static bool _tf_ssb_db_has_rows(sqlite3* db, const char* query)
static void _tf_ssb_db_init_internal(sqlite3* db) static void _tf_ssb_db_init_internal(sqlite3* db)
{ {
sqlite3_extended_result_codes(db, 1);
_tf_ssb_db_exec(db, "PRAGMA journal_mode = WAL"); _tf_ssb_db_exec(db, "PRAGMA journal_mode = WAL");
_tf_ssb_db_exec(db, "PRAGMA synchronous = NORMAL"); _tf_ssb_db_exec(db, "PRAGMA synchronous = NORMAL");
} }
void tf_ssb_db_init_reader(sqlite3* db)
{
_tf_ssb_db_init_internal(db);
}
void tf_ssb_db_init(tf_ssb_t* ssb) void tf_ssb_db_init(tf_ssb_t* ssb)
{ {
sqlite3* db = tf_ssb_get_db(ssb); sqlite3* db = tf_ssb_get_db(ssb);

View File

@ -8,6 +8,7 @@
typedef struct _tf_ssb_t tf_ssb_t; typedef struct _tf_ssb_t tf_ssb_t;
void tf_ssb_db_init(tf_ssb_t* ssb); void tf_ssb_db_init(tf_ssb_t* ssb);
void tf_ssb_db_init_reader(sqlite3* db);
bool tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, JSValue val, const char* signature, bool sequence_before_author); bool tf_ssb_db_store_message(tf_ssb_t* ssb, JSContext* context, const char* id, JSValue val, const char* signature, bool sequence_before_author);
bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size); bool tf_ssb_db_message_content_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_t* out_size);
bool tf_ssb_db_blob_has(tf_ssb_t* ssb, const char* id); bool tf_ssb_db_blob_has(tf_ssb_t* ssb, const char* id);