An unchanged value is not rewritten: the UPDATE would still fire the revision * trigger, so every `daemon start` on a UI build committed (journal + fsync) and * locked out concurrent readers although nothing changed. */
| 721 | * trigger, so every `daemon start` on a UI build committed (journal + fsync) and |
| 722 | * locked out concurrent readers although nothing changed. */ |
| 723 | static bool write_value(sqlite3 *db, const setting_t *setting, const char *value) { |
| 724 | const char *sql; |
| 725 | if (setting->storage == SET_CONFIG) |
| 726 | sql = value ? "INSERT INTO config(key,value) VALUES(?,?) ON CONFLICT(key) DO UPDATE SET " |
| 727 | "value=excluded.value WHERE value IS NOT excluded.value" |
| 728 | : "DELETE FROM config WHERE key=?"; |
| 729 | else |
| 730 | sql = value ? "INSERT INTO runtime_settings(key,value) VALUES(?,?) ON CONFLICT(key) DO " |
| 731 | "UPDATE SET value=excluded.value WHERE value IS NOT excluded.value" |
| 732 | : "DELETE FROM runtime_settings WHERE key=?"; |
| 733 | sqlite3_stmt *statement = NULL; |
| 734 | if (sqlite3_prepare_v2(db, sql, -1, &statement, NULL) != SQLITE_OK) |
| 735 | return false; |
| 736 | sqlite3_bind_text(statement, 1, setting->key, -1, SQLITE_STATIC); |
| 737 | if (value) |
| 738 | sqlite3_bind_text(statement, 2, value, -1, SQLITE_TRANSIENT); |
| 739 | bool ok = sqlite3_step(statement) == SQLITE_DONE; |
| 740 | sqlite3_finalize(statement); |
| 741 | return ok; |
| 742 | } |
| 743 | |
| 744 | char *cbm_runtime_settings_apply_json(const char *cache, const char *body, size_t length, |
| 745 | int *status) { |
no outgoing calls
no test coverage detected