text stringlengths 0 357 |
|---|
return 0; |
} |
int ret = dc_sqlite3_set_config(sql, key, value_str); |
free(value_str); |
return ret; |
} |
/******************************************************************************* |
* Transactions |
******************************************************************************/ |
#undef USE_TRANSACTIONS |
void dc_sqlite3_begin_transaction(dc_sqlite3_t* sql) |
{ |
#ifdef USE_TRANSACTIONS |
// `BEGIN IMMEDIATE` ensures, only one thread may write. |
// all other calls to `BEGIN IMMEDIATE` will try over until sqlite3_busy_timeout() is reached. |
// CAVE: This also implies that transactions MUST NOT be nested. |
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, "BEGIN IMMEDIATE;"); |
if (sqlite3_step(stmt) != SQLITE_DONE) { |
dc_sqlite3_log_error(sql, "Cannot begin transaction."); |
} |
sqlite3_finalize(stmt); |
#endif |
} |
void dc_sqlite3_rollback(dc_sqlite3_t* sql) |
{ |
#ifdef USE_TRANSACTIONS |
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, "ROLLBACK;"); |
if (sqlite3_step(stmt) != SQLITE_DONE) { |
dc_sqlite3_log_error(sql, "Cannot rollback transaction."); |
} |
sqlite3_finalize(stmt); |
#endif |
} |
void dc_sqlite3_commit(dc_sqlite3_t* sql) |
{ |
#ifdef USE_TRANSACTIONS |
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql, "COMMIT;"); |
if (sqlite3_step(stmt) != SQLITE_DONE) { |
dc_sqlite3_log_error(sql, "Cannot commit transaction."); |
} |
sqlite3_finalize(stmt); |
#endif |
} |
/******************************************************************************* |
* Housekeeping |
******************************************************************************/ |
static void maybe_add_file(dc_hash_t* files_in_use, const char* file) |
{ |
#define PREFIX "$BLOBDIR/" |
#define PREFIX_LEN 9 |
if (strncmp(file, PREFIX, PREFIX_LEN)!=0) { |
return; |
} |
const char* raw_name = &file[PREFIX_LEN]; |
dc_hash_insert_str(files_in_use, raw_name, (void*)1); |
} |
static void maybe_add_from_param(dc_context_t* context, dc_hash_t* files_in_use, |
const char* query, int param_id) |
{ |
dc_param_t* param = dc_param_new(); |
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, query); |
while (sqlite3_step(stmt)==SQLITE_ROW) |
{ |
dc_param_set_packed(param, (const char*)sqlite3_column_text(stmt, 0)); |
char* file = dc_param_get(param, param_id, NULL); |
if (file!=NULL) { |
maybe_add_file(files_in_use, file); |
free(file); |
} |
} |
sqlite3_finalize(stmt); |
dc_param_unref(param); |
} |
static int is_file_in_use(dc_hash_t* files_in_use, const char* namespc, const char* name) |
{ |
char* name_to_check = dc_strdup(name); |
if (namespc) { |
int name_len = strlen(name); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.