Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
database.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2011 Henrik Andersson.
4 Copyright (C) 2010 johannes hanika.
5 Copyright (C) 2011-2012 Edouard Gomez.
6 Copyright (C) 2012 Richard Wonka.
7 Copyright (C) 2013-2017 Tobias Ellinghaus.
8 Copyright (C) 2019 Edgardo Hoszowski.
9 Copyright (C) 2020 Hubert Kowalski.
10 Copyright (C) 2020, 2022 Pascal Obry.
11 Copyright (C) 2022 Martin Bařinka.
12 Copyright (C) 2025 Alynx Zhou.
13 Copyright (C) 2025-2026 Aurélien PIERRE.
14 Copyright (C) 2025 Guillaume Stutin.
15
16 darktable is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 darktable is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with darktable. If not, see <http://www.gnu.org/licenses/>.
28*/
29
30#ifndef DT_DATABASE_DATABASE_H
31#define DT_DATABASE_DATABASE_H
32
33/* DT_DEBUG_TRACE_WRAPPER, used by the transaction macros at the bottom of this file. It
34 * used to arrive the other way round -- common/debug.h included this header, so anything
35 * that reached here through it already had the wrapper. */
36#include "common/debug.h"
37
38#include <glib.h>
39#include <sqlite3.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/* ---------------------------------------------------------------------------------------
46 * Lifecycle
47 *
48 * There is exactly one connection, and the module owns it. `dt_database_t` used to be an
49 * opaque struct the caller held and passed back into all 20 functions below -- but every
50 * caller filled that argument with `dt_database_get_global()`, the module's own accessor,
51 * so it was never a parameter anybody chose. It is gone, along with the accessor and the
52 * entry on `darktable_t`.
53 * ------------------------------------------------------------------------------------- */
54
58{
60 const char *alternative;
63 const char *library;
65 gboolean load_data;
67 gboolean has_gui;
70 gboolean verbose;
72
84
87
94void dt_database_close(void);
95
97gboolean dt_database_is_open(void);
98
101const gchar *dt_database_get_path(void);
102
113sqlite3 *dt_database_get_sqlite3_global(void);
114
119const char *dt_database_get_last_error(void);
120
121/* ---------------------------------------------------------------------------------------
122 * Maintenance and snapshot policy
123 *
124 * User preferences, read from conf by the orchestrator and told to the module -- the same
125 * arrangement as `dt_mipmap_cache_settings_t`. They used to be read with `dt_conf_*` from
126 * five places inside the maintenance and snapshot paths, which put `common/conf.h` in the
127 * SQL layer and made "when does this take effect" a question you answered by reading
128 * call sites.
129 * ------------------------------------------------------------------------------------- */
130
142
145
151
154
158typedef void (*dt_database_renamed_handler_t)(const char *new_library_name);
160
161/* Why the database would not open, handed to whoever can report it.
162 *
163 * Reporting used to live here as dt_database_show_error(), a stack of modal dialogs inside
164 * a SQL file. The backend now only says what went wrong; the dialogs, and the decision to
165 * retry or delete lock files, are gui/common/database_gui.c's business. */
173
177
180
181/* Questions the module must ask before it can continue.
182 *
183 * These are NOT the dt_database_error_t path above. That one records what went wrong for
184 * whoever can report it afterwards; these happen mid-operation and the answer decides
185 * whether init aborts, restores from a snapshot, starts over, or spends a minute
186 * vacuuming -- there is no "afterwards" to report to. So the backend states the question
187 * and takes back a value, and every trace of how it is put to the user lives in
188 * gui/common/database_gui.c.
189 *
190 * The module passes FACTS, never prose. Composing a sentence -- and translating it, and
191 * escaping it into markup -- is the handler's business, because only the handler knows
192 * what it will be rendered into.
193 */
207
220
243
246
258
261int dt_database_delete_lock_files(const char *dbfilename);
263void dt_database_optimize(void);
266gboolean dt_database_maybe_maintenance(const gboolean closing_time);
271gboolean dt_database_snapshot(void);
273gboolean dt_database_maybe_snapshot(void);
275char **dt_database_snaps_to_remove(void);
277gchar *dt_database_get_most_recent_snap(const char* db_filename);
278
279
280/* Nested transactions.
281 *
282 * These took a `const dt_database_t *` that all 50 call sites filled with
283 * dt_database_get_global(). They do not any more, and that accessor is gone with them. */
289
290#define dt_database_start_transaction() DT_DEBUG_TRACE_WRAPPER_VOID(DT_DEBUG_SQL, dt_database_start_transaction_debug)
291#define dt_database_release_transaction() DT_DEBUG_TRACE_WRAPPER_VOID(DT_DEBUG_SQL, dt_database_release_transaction_debug)
292
293#ifdef __cplusplus
294}
295#endif
296
297#endif // DT_DATABASE_DATABASE_H
298
299// clang-format off
300// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
301// vim: shiftwidth=2 expandtab tabstop=2 cindent
302// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
303// clang-format on
static void error(char *msg)
Definition ashift_lsd.c:202
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_database_set_renamed_handler(dt_database_renamed_handler_t handler)
Definition database.c:3627
void dt_database_settings_free(dt_database_settings_t *settings)
Definition database.c:3711
dt_database_response_t(* dt_database_prompt_handler_t)(const dt_database_prompt_context_t *context)
Definition database.h:245
void dt_database_optimize(void)
Definition database.c:4050
void dt_database_start_transaction_debug(void)
Definition database.c:4805
gchar * dt_database_get_most_recent_snap(const char *db_filename)
Definition database.c:4699
void dt_database_set_settings(const dt_database_settings_t *settings)
Definition database.c:3666
void dt_database_begin_transaction_batch(void)
Definition database.c:4934
void dt_database_release_transaction_debug(void)
Definition database.c:4857
char ** dt_database_snaps_to_remove(void)
Definition database.c:4408
void dt_database_take_error(dt_database_error_t *error)
Definition database.c:2734
void dt_database_error_free(dt_database_error_t *error)
Definition database.c:2751
void dt_database_get_settings(dt_database_settings_t *settings)
Definition database.c:3685
sqlite3 * dt_database_get_sqlite3_global(void)
Definition database.c:3782
const char * dt_database_get_last_error(void)
Definition database.c:3776
void(* dt_database_renamed_handler_t)(const char *new_library_name)
Definition database.h:158
void dt_database_set_prompt_handler(dt_database_prompt_handler_t handler)
Definition database.c:3062
void dt_database_close(void)
Definition database.c:3749
gboolean dt_database_snapshot(void)
Definition database.c:4118
const gchar * dt_database_get_path(void)
Definition database.c:3787
dt_database_response_t
Definition database.h:209
@ DT_DATABASE_RESPONSE_CLOSE
Definition database.h:212
@ DT_DATABASE_RESPONSE_PROCEED
Definition database.h:218
@ DT_DATABASE_RESPONSE_RESTORE
Definition database.h:214
@ DT_DATABASE_RESPONSE_DELETE
Definition database.h:216
void dt_database_perform_maintenance(void)
Definition database.c:3883
void dt_database_cleanup_busy_statements(void)
Definition database.c:3861
void dt_database_rollback_transaction(void)
Definition database.c:4899
dt_database_open_result_t
Definition database.h:74
@ DT_DATABASE_OPEN_FAILED
Definition database.h:76
@ DT_DATABASE_OPEN_LOCKED
Definition database.h:82
@ DT_DATABASE_OPEN_OK
Definition database.h:78
gboolean dt_database_maybe_maintenance(const gboolean closing_time)
Definition database.c:3970
gboolean dt_database_is_open(void)
Definition database.c:3771
dt_database_open_result_t dt_database_open(const dt_database_params_t *params)
Definition database.c:3632
dt_database_prompt_t
Definition database.h:195
@ DT_DATABASE_PROMPT_UPGRADE
Definition database.h:202
@ DT_DATABASE_PROMPT_MAINTENANCE
Definition database.h:205
@ DT_DATABASE_PROMPT_CORRUPTED
Definition database.h:199
@ DT_DATABASE_PROMPT_READONLY
Definition database.h:197
gboolean dt_database_maybe_snapshot(void)
Definition database.c:4227
int dt_database_delete_lock_files(const char *dbfilename)
Definition database.c:2760
void dt_database_end_transaction_batch(void)
Definition database.c:4956
Call tracing for functions you do not want to edit every caller of.
gboolean lock_acquired
Definition database.h:168
const char * library
Definition database.h:63
const char * alternative
Definition database.h:60
dt_database_prompt_t prompt
Definition database.h:225