text stringlengths 0 357 |
|---|
} |
else if (state==SQLITE_ROW) { |
stmt = dc_sqlite3_prepare(sql, "UPDATE config SET value=? WHERE keyname=?;"); |
sqlite3_bind_text (stmt, 1, value, -1, SQLITE_STATIC); |
sqlite3_bind_text (stmt, 2, key, -1, SQLITE_STATIC); |
state = sqlite3_step(stmt); |
sqlite3_finalize(stmt); |
} |
else { |
dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Cannot read value."); |
return 0; |
} |
} |
else |
{ |
/* delete key */ |
stmt = dc_sqlite3_prepare(sql, "DELETE FROM config WHERE keyname=?;"); |
sqlite3_bind_text (stmt, 1, key, -1, SQLITE_STATIC); |
state = sqlite3_step(stmt); |
sqlite3_finalize(stmt); |
} |
if (state != SQLITE_DONE) { |
dc_log_error(sql->context, 0, "dc_sqlite3_set_config(): Cannot change value."); |
return 0; |
} |
return 1; |
} |
char* dc_sqlite3_get_config(dc_sqlite3_t* sql, const char* key, const char* def) /* the returned string must be free()'d, NULL is only returned if def is NULL */ |
{ |
sqlite3_stmt* stmt = NULL; |
if (!dc_sqlite3_is_open(sql) || key==NULL) { |
return dc_strdup_keep_null(def); |
} |
stmt = dc_sqlite3_prepare(sql, SELECT_v_FROM_config_k_STATEMENT); |
sqlite3_bind_text(stmt, 1, key, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)==SQLITE_ROW) |
{ |
const unsigned char* ptr = sqlite3_column_text(stmt, 0); /* Do not pass the pointers returned from sqlite3_column_text(), etc. into sqlite3_free(). */ |
if (ptr) |
{ |
/* success, fall through below to free objects */ |
char* ret = dc_strdup((const char*)ptr); |
sqlite3_finalize(stmt); |
return ret; |
} |
} |
/* return the default value */ |
sqlite3_finalize(stmt); |
return dc_strdup_keep_null(def); |
} |
int32_t dc_sqlite3_get_config_int(dc_sqlite3_t* sql, const char* key, int32_t def) |
{ |
char* str = dc_sqlite3_get_config(sql, key, NULL); |
if (str==NULL) { |
return def; |
} |
int32_t ret = atol(str); |
free(str); |
return ret; |
} |
int64_t dc_sqlite3_get_config_int64(dc_sqlite3_t* sql, const char* key, int64_t def) |
{ |
char* str = dc_sqlite3_get_config(sql, key, NULL); |
if (str==NULL) { |
return def; |
} |
int64_t ret = 0; |
sscanf(str, "%"SCNd64, &ret); |
free(str); |
return ret; |
} |
int dc_sqlite3_set_config_int(dc_sqlite3_t* sql, const char* key, int32_t value) |
{ |
char* value_str = dc_mprintf("%i", (int)value); |
if (value_str==NULL) { |
return 0; |
} |
int ret = dc_sqlite3_set_config(sql, key, value_str); |
free(value_str); |
return ret; |
} |
int dc_sqlite3_set_config_int64(dc_sqlite3_t* sql, const char* key, int64_t value) |
{ |
char* value_str = dc_mprintf("%"PRId64, (long)value); |
if (value_str==NULL) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.