![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include "system/atomic.h"#include "common/paths.h"#include "system/dtpthread.h"#include "common/image.h"#include "database/database.h"#include "database/sql_debug.h"#include "common/datetime.h"#include "common/file_location.h"#include "develop/iop_order.h"#include "database/legacy_presets.h"#include <gio/gio.h>#include <glib.h>#include <glib/gstdio.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <sys/stat.h>#include <sys/types.h>#include "common/utility.h"
Include dependency graph for database.c:Go to the source code of this file.
Data Structures | |
| struct | dt_database_t |
Macros | |
| #define | CURRENT_DATABASE_VERSION_LIBRARY 36 |
| #define | CURRENT_DATABASE_VERSION_DATA 9 |
| #define | MAX_NESTED_TRANSACTIONS 0 |
| #define | _db_print(...) |
| #define | _SQLITE3_EXEC(a, b, c, d, e) |
| #define | TRY_EXEC(_query, _message) |
| #define | TRY_STEP(_stmt, _expected, _message) |
| #define | TRY_PREPARE(_stmt, _query, _message) |
| #define | FINALIZE |
| #define | FINALIZE |
| #define | FINALIZE |
| #define | FINALIZE |
| #define | TRY_EXEC(_query, _message) |
| #define | TRY_STEP(_stmt, _expected, _message) |
| #define | TRY_PREPARE(_stmt, _query, _message) |
| #define | FINALIZE |
| #define | ERRCHECK {if (err!=NULL) {_db_print("[db maintenance] maintenance error: '%s'\n",err); sqlite3_free(err); err=NULL;}} |
Typedefs | |
| typedef struct dt_database_t | dt_database_t |
Variables | |
| static dt_atomic_int | _trxid |
| static dt_atomic_int | _trx_batch_level |
| static gpointer | _trx_owner = NULL |
| static gpointer | _trx_batch_owner = NULL |
| static dt_database_t * | _db = NULL |
| static dt_pthread_rwlock_t | _db_lock |
| static gboolean | _db_lock_inited = FALSE |
| static dt_database_settings_t | _settings = { NULL, 0, NULL, 0 } |
| static dt_pthread_mutex_t | _settings_lock |
| static gboolean | _settings_lock_inited = FALSE |
| static gboolean | _has_gui = FALSE |
| static gboolean | _verbose = FALSE |
| static dt_database_renamed_handler_t | _renamed_handler = NULL |
| static dt_database_prompt_handler_t | _prompt_handler = NULL |
| #define _db_print | ( | ... | ) |
Trace gate. A statement, so that a bare if(_verbose) dt_print(...) cannot swallow a following else – which is exactly what happened in caches/image_cache.c and was only caught by -Wdangling-else in the Debug builds.
Definition at line 161 of file database.c.
| #define _SQLITE3_EXEC | ( | a, | |
| b, | |||
| c, | |||
| d, | |||
| e | |||
| ) |
Definition at line 177 of file database.c.
| #define CURRENT_DATABASE_VERSION_DATA 9 |
Definition at line 90 of file database.c.
| #define CURRENT_DATABASE_VERSION_LIBRARY 36 |
Definition at line 89 of file database.c.
| #define ERRCHECK {if (err!=NULL) {_db_print("[db maintenance] maintenance error: '%s'\n",err); sqlite3_free(err); err=NULL;}} |
Definition at line 3882 of file database.c.
| #define FINALIZE |
Definition at line 537 of file database.c.
| #define FINALIZE |
Definition at line 537 of file database.c.
| #define FINALIZE |
Definition at line 537 of file database.c.
| #define FINALIZE |
Definition at line 537 of file database.c.
| #define FINALIZE |
Definition at line 537 of file database.c.
| #define MAX_NESTED_TRANSACTIONS 0 |
Definition at line 93 of file database.c.
| #define TRY_EXEC | ( | _query, | |
| _message | |||
| ) |
Definition at line 497 of file database.c.
| #define TRY_EXEC | ( | _query, | |
| _message | |||
| ) |
Definition at line 497 of file database.c.
| #define TRY_PREPARE | ( | _stmt, | |
| _query, | |||
| _message | |||
| ) |
Definition at line 523 of file database.c.
| #define TRY_PREPARE | ( | _stmt, | |
| _query, | |||
| _message | |||
| ) |
Definition at line 523 of file database.c.
| #define TRY_STEP | ( | _stmt, | |
| _expected, | |||
| _message | |||
| ) |
Definition at line 510 of file database.c.
| #define TRY_STEP | ( | _stmt, | |
| _expected, | |||
| _message | |||
| ) |
Definition at line 510 of file database.c.
| typedef struct dt_database_t dt_database_t |
|
static |
Definition at line 3085 of file database.c.
References _ask_user(), DT_DATABASE_PROMPT_CORRUPTED, and dt_database_prompt_context_t::prompt.
Referenced by _database_init().
|
static |
Definition at line 3946 of file database.c.
References _ask_user(), _db, _has_gui, dt_database_t::dbfilename_library, DT_DATABASE_PROMPT_MAINTENANCE, DT_DATABASE_RESPONSE_PROCEED, FALSE, dt_database_prompt_context_t::prompt, and size.
Referenced by dt_database_maybe_maintenance().
|
static |
Definition at line 3095 of file database.c.
References _ask_user(), DT_DATABASE_PROMPT_READONLY, and dt_database_prompt_context_t::prompt.
Referenced by _database_init().
|
static |
Definition at line 3102 of file database.c.
References _ask_user(), DT_DATABASE_PROMPT_UPGRADE, and dt_database_prompt_context_t::prompt.
Referenced by ask_for_upgrade().
|
static |
Definition at line 3070 of file database.c.
References _prompt_handler, dt_database_prompt_context_t::dbfilename, DT_DATABASE_RESPONSE_CLOSE, and IS_NULL_PTR.
Referenced by _ask_corrupted(), _ask_for_maintenance(), _ask_readonly(), and _ask_upgrade().
|
static |
Definition at line 4068 of file database.c.
References _db_print, _get_pragma_int_val(), dt_free, MAX, MIN, and void().
Referenced by dt_database_snapshot().
|
static |
Definition at line 2519 of file database.c.
References CURRENT_DATABASE_VERSION_DATA, and dt_database_t::handle.
Referenced by _database_init().
|
static |
Definition at line 2413 of file database.c.
References CURRENT_DATABASE_VERSION_LIBRARY, and dt_database_t::handle.
Referenced by _database_init().
|
static |
Definition at line 2572 of file database.c.
References dt_database_t::handle, and i.
Referenced by _database_init().
|
static |
Definition at line 3840 of file database.c.
References dt_concat_path_file(), dt_loc_get_user_cache_dir(), and DT_PATH_MAX.
Referenced by _database_init().
|
static |
Definition at line 3727 of file database.c.
References dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_free, dt_database_t::error_dbfilename, dt_database_t::error_message, dt_database_t::handle, IS_NULL_PTR, dt_database_t::lockfile_data, and dt_database_t::lockfile_library.
Referenced by _database_init(), and dt_database_close().
|
static |
Definition at line 3109 of file database.c.
References _ask_corrupted(), _ask_readonly(), _create_data_schema(), _create_library_schema(), _create_memory_schema(), _database_delete_mipmaps_files(), _database_free(), _database_migrate_to_xdg_structure(), _db_print, _get_pragma_string_val(), _lock_databases(), _migrate_schema(), _sanitize_db(), _trx_batch_level, _trx_batch_owner, _trxid, _upgrade_data_schema(), _upgrade_library_schema(), ask_for_upgrade(), CURRENT_DATABASE_VERSION_DATA, CURRENT_DATABASE_VERSION_LIBRARY, dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_atomic_set_int(), dt_concat_path_file(), dt_database_backup(), dt_database_get_most_recent_snap(), DT_DATABASE_RESPONSE_DELETE, DT_DATABASE_RESPONSE_RESTORE, dt_free, dt_legacy_presets_create(), dt_loc_get_datadir(), dt_loc_get_user_config_dir(), DT_PATH_MAX, error(), FALSE, dt_database_t::handle, IS_NULL_PTR, dt_database_t::lock_acquired, dt_database_t::lockfile_data, dt_database_t::lockfile_library, sqlite3IcuInit(), and TRUE.
Referenced by dt_database_open().
|
static |
Definition at line 3797 of file database.c.
References _renamed_handler, dt_concat_path_file(), dt_loc_get_user_config_dir(), DT_PATH_MAX, and IS_NULL_PTR.
Referenced by _database_init().
|
static |
Definition at line 4355 of file database.c.
References _get_iso8601_int(), day, and IS_NULL_PTR.
Referenced by dt_database_snaps_to_remove().
|
static |
Definition at line 4335 of file database.c.
References FALSE, i, TRUE, v, and value.
Referenced by _db_snap_sort().
| int _get_pragma_int_val | ( | sqlite3 * | db, |
| const char * | pragma | ||
| ) |
Definition at line 3020 of file database.c.
References dt_free.
Referenced by _backup_db(), dt_database_maybe_maintenance(), and dt_database_perform_maintenance().
| gchar * _get_pragma_string_val | ( | sqlite3 * | db, |
| const char * | pragma | ||
| ) |
|
inlinestatic |
Definition at line 3965 of file database.c.
References _db, dt_database_t::dbfilename_data, and dt_database_t::dbfilename_library.
Referenced by dt_database_maybe_maintenance(), dt_database_maybe_snapshot(), dt_database_optimize(), dt_database_snaps_to_remove(), and dt_database_snapshot().
|
static |
Definition at line 2935 of file database.c.
References _lock_single_database(), dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_free, FALSE, dt_database_t::lockfile_data, dt_database_t::lockfile_library, and TRUE.
Referenced by _database_init().
|
static |
Definition at line 2831 of file database.c.
References dt_free, dt_database_t::error_dbfilename, dt_database_t::error_message, dt_database_t::error_other_pid, FALSE, pid_is_alive(), and TRUE.
Referenced by _lock_databases().
|
static |
Definition at line 186 of file database.c.
References _SQLITE3_EXEC, dt_free, FALSE, dt_database_t::handle, i, IS_NULL_PTR, name, and TRUE.
Referenced by _database_init().
|
static |
Definition at line 4062 of file database.c.
References _db_print.
Referenced by dt_database_snapshot().
|
static |
Definition at line 2644 of file database.c.
References dt_free, dt_util_foo_to_utf8(), and dt_database_t::handle.
Referenced by _database_init().
|
static |
Definition at line 4180 of file database.c.
References _db_print, dt_database_settings_t::create_snapshot, dt_database_get_settings(), dt_database_settings_free(), FALSE, and TRUE.
Referenced by dt_database_maybe_snapshot().
|
static |
Definition at line 2399 of file database.c.
References _upgrade_data_schema_step(), CURRENT_DATABASE_VERSION_DATA, FALSE, and TRUE.
Referenced by _database_init().
|
static |
Definition at line 2165 of file database.c.
References CURRENT_DATABASE_VERSION_DATA, dt_free_gpointer(), DT_IOP_ORDER_LEGACY, dt_ioppr_get_iop_order_list_version(), dt_database_t::handle, dt_iop_order_entry_t::iop_order_f, dt_iop_order_entry_t::o, dt_iop_order_entry_t::operation, TRY_EXEC, TRY_PREPARE, and TRY_STEP.
Referenced by _upgrade_data_schema().
|
static |
Definition at line 2384 of file database.c.
References _upgrade_library_schema_step(), CURRENT_DATABASE_VERSION_LIBRARY, FALSE, and TRUE.
Referenced by _database_init().
|
static |
Definition at line 540 of file database.c.
References CURRENT_DATABASE_VERSION_LIBRARY, dt_datetime_exif_to_gdatetime(), dt_datetime_gdatetime_to_gtimespan(), dt_datetime_utc_tz(), dt_free, dt_free_gpointer(), dt_image_flags_from_extension(), DT_IMAGE_HDR, DT_IMAGE_LDR, DT_IMAGE_RAW, DT_IOP_ORDER_ANSEL_RAW, DT_IOP_ORDER_CUSTOM, DT_IOP_ORDER_LEGACY, dt_ioppr_get_iop_order_list_kind(), dt_ioppr_get_iop_order_list_version(), dt_ioppr_serialize_text_iop_order_list(), dt_sort_iop_list_by_order_f(), FALSE, FINALIZE, flags, dt_database_t::handle, i, dt_iop_order_entry_t::instance, dt_iop_order_entry_t::iop_order_f, IS_NULL_PTR, kind, n, name, dt_iop_order_entry_t::o, dt_iop_order_entry_t::operation, TRUE, TRY_EXEC, TRY_PREPARE, TRY_STEP, and UNKNOWN_IMAGE.
Referenced by _upgrade_library_schema().
| void ask_for_upgrade | ( | const gchar * | dbname, |
| const gboolean | has_gui | ||
| ) |
Definition at line 2957 of file database.c.
References _ask_upgrade(), and DT_DATABASE_RESPONSE_PROCEED.
Referenced by _database_init().
| void dt_database_backup | ( | const char * | filename | ) |
Definition at line 2976 of file database.c.
References darktable_package_version, dt_free, FALSE, k, and TRUE.
Referenced by _database_init().
Definition at line 4934 of file database.c.
References _db, _db_lock, _trx_batch_level, _trx_batch_owner, _trx_owner, dt_atomic_add_int(), DT_DEBUG_SQLITE3_EXEC, dt_pthread_rwlock_wrlock(), and dt_database_t::handle.
Referenced by dt_iop_load_modules_so().
cleanup busy statements on closing dt, just before performing maintenance
Definition at line 3861 of file database.c.
References _db, _db_print, dt_database_t::handle, and IS_NULL_PTR.
Referenced by dt_cleanup().
Close the connection and release the lock files. Safe to call when nothing is open.
src/database expose a *_cleanup() each. A connection cannot be closed out from under a sqlite3_stmt still held elsewhere – and that is the reason this pair is not yet a dt_database_swap(). See src/database/README.md. Definition at line 3749 of file database.c.
References _database_free(), _db, _db_lock, _db_lock_inited, dt_pthread_rwlock_unlock(), dt_pthread_rwlock_wrlock(), and IS_NULL_PTR.
Referenced by dt_cleanup(), dt_init(), and testdb_teardown().
| int dt_database_delete_lock_files | ( | const char * | dbfilename | ) |
Delete data.db.lock and library.db.lock beside dbfilename. Returns 0 when every lock file that existed was removed. Call only once the user has agreed.
Definition at line 2760 of file database.c.
References dt_free, i, IS_NULL_PTR, names, and status.
Referenced by dt_database_show_error().
Definition at line 4956 of file database.c.
References _db, _db_lock, _db_print, _trx_batch_level, _trx_batch_owner, _trx_owner, dt_atomic_set_int(), dt_atomic_sub_int(), DT_DEBUG_SQLITE3_EXEC, dt_pthread_rwlock_unlock(), and dt_database_t::handle.
Referenced by dt_iop_load_modules_so().
| void dt_database_error_free | ( | dt_database_error_t * | error | ) |
Release the strings owned by error.
Definition at line 2751 of file database.c.
References dt_free, error(), and IS_NULL_PTR.
Referenced by dt_database_show_error().
| const char * dt_database_get_last_error | ( | void | ) |
The message for the most recent failed call on the connection.
Exists so that reporting an error does not require the handle. Valid until the next call into the database from any thread – copy it if you keep it.
Definition at line 3776 of file database.c.
References _db, dt_database_t::handle, and IS_NULL_PTR.
Referenced by dt_exif_xmp_read(), and dt_film_new().
| gchar * dt_database_get_most_recent_snap | ( | const char * | db_filename | ) |
get possibly the freshest snapshot to restore
Definition at line 4699 of file database.c.
References _db_print, dt_free, error(), and IS_NULL_PTR.
Referenced by _database_init().
| const gchar * dt_database_get_path | ( | void | ) |
Absolute path of the library file currently open, or NULL. Valid until the next dt_database_close(); copy it if you need to outlive that.
Definition at line 3787 of file database.c.
References _db, and dt_database_t::dbfilename_library.
Referenced by dt_mipmap_cache_get_filename().
| void dt_database_get_settings | ( | dt_database_settings_t * | settings | ) |
Take a copy of the policy. Strings are newly allocated – release with dt_database_settings_free(). Read as one snapshot under the module's lock: the GUI thread can replace these while a maintenance decision is being made, and four fields read one at a time can be a mix of old and new.
Definition at line 3685 of file database.c.
References _settings, _settings_lock, _settings_lock_inited, dt_database_settings_t::create_snapshot, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, dt_database_settings_t::keep_snapshots, dt_database_settings_t::maintenance_check, and dt_database_settings_t::maintenance_freepage_ratio.
Referenced by _snapshot_policy_decides(), dt_database_maybe_maintenance(), and dt_database_snaps_to_remove().
| sqlite3 * dt_database_get_sqlite3_global | ( | void | ) |
The connection itself.
sqlite3 * that the module cannot account for, cannot serialise against a close, and cannot trace. tools/check_module_boundaries.sh ratchets the number of call sites downwards and it is deleted at zero – at which point the private lock below actually guarantees something and swapping workspaces at runtime becomes implementable.Do not call it from new code: put the query in a repository under src/database and give it a name. See src/database/README.md.
Definition at line 3782 of file database.c.
References _db, and dt_database_t::handle.
Referenced by _clear_similar_tags(), _columns_of(), _compute_count(), _fill_similar_tags(), _first_id_for_text(), _image_get_stmt(), _image_write_history_hash(), _next_id(), _prepared(), _run(), _run_for_id(), _run_snap_imgid(), _scalar(), dt_collection_query_find_neighbour(), dt_collection_query_get_group_members(), dt_collection_query_get_images(), dt_collection_query_get_images_for_rule(), dt_collection_query_get_makermodels(), dt_collection_query_get_nth(), dt_collection_query_get_property_values(), dt_collection_query_image_offset(), dt_collection_query_pop(), dt_collection_query_push(), dt_collection_query_refresh_memory_table(), dt_collection_query_restrict_to_selection(), dt_collection_query_set_iop_names(), dt_colorlabel_repository_foreach(), dt_colorlabel_repository_get_list(), dt_colorlabel_repository_has(), dt_film_repository_delete(), dt_film_repository_find_by_folder(), dt_film_repository_folder_status_clear(), dt_film_repository_folder_status_set(), dt_film_repository_foreach(), dt_film_repository_foreach_empty(), dt_film_repository_foreach_under(), dt_film_repository_get_folder(), dt_film_repository_get_image_ids(), dt_film_repository_has_images(), dt_film_repository_insert(), dt_film_repository_set_folder(), dt_film_repository_touch_access(), dt_history_repository_count_items(), dt_history_repository_count_mask_items(), dt_history_repository_delete_all_for_image(), dt_history_repository_delete_history(), dt_history_repository_delete_masks_history(), dt_history_repository_find_version_for_params(), dt_history_repository_foreach_active_module(), dt_history_repository_foreach_auto_preset_row(), dt_history_repository_foreach_item(), dt_history_repository_foreach_last_item(), dt_history_repository_foreach_mask_item(), dt_history_repository_foreach_row(), dt_history_repository_get_autoapply_ioporder_params(), dt_history_repository_get_end(), dt_history_repository_get_last_enabled_params(), dt_history_repository_get_module_order(), dt_history_repository_get_module_order_version(), dt_history_repository_get_next_num(), dt_history_repository_module_exists(), dt_history_repository_set_end(), dt_history_repository_set_module_order(), dt_history_repository_shift_nums(), dt_history_repository_write_item(), dt_history_repository_write_mask_item(), dt_history_snapshot_repository_next_id(), dt_image_repository_clear_flag_among(), dt_image_repository_copy_to_film(), dt_image_repository_count_distinct_fields(), dt_image_repository_count_in_id_range(), dt_image_repository_count_others_with_flag(), dt_image_repository_delete(), dt_image_repository_duplicate(), dt_image_repository_find_by_film_and_filename(), dt_image_repository_find_by_folder_and_filename(), dt_image_repository_find_group_for_pattern(), dt_image_repository_foreach_collected(), dt_image_repository_foreach_in_id_range(), dt_image_repository_foreach_with_path(), dt_image_repository_get_collected_geo_bounds(), dt_image_repository_get_collected_geo_points(), dt_image_repository_get_duplicate_ids(), dt_image_repository_get_full_paths(), dt_image_repository_get_group_member_rows(), dt_image_repository_get_group_members(), dt_image_repository_get_ids_with_flag(), dt_image_repository_get_ids_with_flag_among(), dt_image_repository_get_ratings(), dt_image_repository_get_timestamps(), dt_image_repository_get_version(), dt_image_repository_get_versions(), dt_image_repository_get_write_timestamp(), dt_image_repository_get_xmp_row(), dt_image_repository_insert_import(), dt_image_repository_load(), dt_image_repository_reassign_group(), dt_image_repository_set_flag_among(), dt_image_repository_set_flags(), dt_image_repository_set_flags_masked(), dt_image_repository_set_group(), dt_image_repository_set_version(), dt_image_repository_set_write_timestamp(), dt_image_repository_store(), dt_image_repository_touch_write_timestamp(), dt_location_repository_delete(), dt_location_repository_find_images_for_location(), dt_location_repository_find_locations_for_image(), dt_location_repository_get_data(), dt_location_repository_get_image_locations(), dt_location_repository_get_in_bbox(), dt_location_repository_get_polygon(), dt_location_repository_set_data(), dt_metadata_repository_add(), dt_metadata_repository_find_image_by_value(), dt_metadata_repository_foreach(), dt_metadata_repository_foreach_selected(), dt_metadata_repository_get_all(), dt_metadata_repository_get_values(), dt_metadata_repository_remove(), dt_preset_repository_add_iop_preset(), dt_preset_repository_add_module_preset(), dt_preset_repository_add_shipped_preset(), dt_preset_repository_delete_all_for_module(), dt_preset_repository_delete_by_rowid(), dt_preset_repository_delete_by_rowid_unprotected(), dt_preset_repository_delete_module_preset(), dt_preset_repository_delete_shipped(), dt_preset_repository_duplicate_module_preset(), dt_preset_repository_find_autoapply(), dt_preset_repository_find_rowid(), dt_preset_repository_get_by_rowid(), dt_preset_repository_get_conditions(), dt_preset_repository_get_identity(), dt_preset_repository_get_iop_preset(), dt_preset_repository_get_module_preset(), dt_preset_repository_insert(), dt_preset_repository_insert_with_conditions(), dt_preset_repository_list_all(), dt_preset_repository_list_all_versions(), dt_preset_repository_list_editable(), dt_preset_repository_list_for_iop(), dt_preset_repository_list_for_menu(), dt_preset_repository_list_for_module(), dt_preset_repository_list_for_upgrade(), dt_preset_repository_list_for_version(), dt_preset_repository_module_preset_exists(), dt_preset_repository_rename_module_preset(), dt_preset_repository_set_blend_params(), dt_preset_repository_set_module_version(), dt_preset_repository_update_camera(), dt_preset_repository_update_conditions(), dt_preset_repository_update_flag(), dt_preset_repository_update_iop_params(), dt_preset_repository_update_module_params(), dt_preset_repository_update_params_by_rowid(), dt_preset_repository_update_range(), dt_removed_image_repository_restore(), dt_selection_repository_clear(), dt_selection_repository_deselect(), dt_selection_repository_deselect_list(), dt_selection_repository_drop_uncollected(), dt_selection_repository_get_all(), dt_selection_repository_get_lowest_id(), dt_selection_repository_pop(), dt_selection_repository_push(), dt_selection_repository_select(), dt_selection_repository_select_list(), dt_style_repository_append_item_from_history(), dt_style_repository_copy_items_from_history(), dt_style_repository_copy_items_from_style(), dt_style_repository_delete(), dt_style_repository_delete_items_except(), dt_style_repository_foreach_apply_item(), dt_style_repository_foreach_item(), dt_style_repository_foreach_item_against_image(), dt_style_repository_foreach_item_for_export(), dt_style_repository_foreach_item_with_params(), dt_style_repository_foreach_style(), dt_style_repository_get_description(), dt_style_repository_get_id_by_name(), dt_style_repository_get_iop_list(), dt_style_repository_get_style(), dt_style_repository_insert_header(), dt_style_repository_insert_item(), dt_style_repository_normalize_multi_priority(), dt_style_repository_set_iop_list(), dt_style_repository_update_header(), dt_style_repository_update_item_from_history(), dt_tag_repository_attach(), dt_tag_repository_attach_batch(), dt_tag_repository_count_attachments(), dt_tag_repository_count_distinct_images(), dt_tag_repository_delete_batch(), dt_tag_repository_detach_batch(), dt_tag_repository_get_agreement(), dt_tag_repository_get_attached(), dt_tag_repository_get_attached_for_export(), dt_tag_repository_get_attached_names(), dt_tag_repository_get_by_path_with_counts(), dt_tag_repository_get_collection_tags(), dt_tag_repository_get_flags(), dt_tag_repository_get_ids_for_images(), dt_tag_repository_get_images(), dt_tag_repository_get_images_in_list(), dt_tag_repository_get_name(), dt_tag_repository_get_names_under(), dt_tag_repository_get_similar(), dt_tag_repository_get_suggestions(), dt_tag_repository_get_synonyms(), dt_tag_repository_get_with_usage(), dt_tag_repository_insert(), dt_tag_repository_is_attached(), dt_tag_repository_rebuild_internal(), dt_tag_repository_rename(), dt_tag_repository_set_flags(), dt_tag_repository_set_synonyms(), dt_tag_repository_update_flags(), imported_style_name(), max_style_id(), print_enabled_state_summary(), print_module_order_summary(), and sql_int_for_bound_images().
| gboolean dt_database_is_open | ( | void | ) |
TRUE between a successful dt_database_open() and dt_database_close().
Definition at line 3771 of file database.c.
References _db, and IS_NULL_PTR.
Referenced by _remove_undo_data_free(), and dt_collection_query_refresh_memory_table().
| gboolean dt_database_maybe_maintenance | ( | const gboolean | closing_time | ) |
Ask the user whether to VACUUM, if the policy and the free-page ratio both say it is worth it. closing_time distinguishes the startup check from the shutdown one.
Definition at line 3970 of file database.c.
References _ask_for_maintenance(), _db, _db_print, _get_pragma_int_val(), _is_mem_db(), dt_database_get_settings(), dt_database_settings_free(), FALSE, dt_database_t::handle, IS_NULL_PTR, dt_database_settings_t::maintenance_check, dt_database_settings_t::maintenance_freepage_ratio, and TRUE.
Referenced by dt_cleanup(), and dt_init().
| gboolean dt_database_maybe_snapshot | ( | void | ) |
check if creating database snapshot is recommended
Definition at line 4227 of file database.c.
References _db, _db_print, _is_mem_db(), _snapshot_policy_decides(), dt_database_t::dbfilename_library, dt_free, error(), FALSE, and IS_NULL_PTR.
Referenced by dt_cleanup().
| dt_database_open_result_t dt_database_open | ( | const dt_database_params_t * | params | ) |
Open the one connection. Fails if one is already open – call dt_database_close() first.
Definition at line 3632 of file database.c.
References _database_init(), _db, _db_lock, _db_lock_inited, _has_gui, _settings_lock, _settings_lock_inited, _verbose, DT_DATABASE_OPEN_FAILED, DT_DATABASE_OPEN_LOCKED, DT_DATABASE_OPEN_OK, dt_pthread_mutex_init(), dt_pthread_rwlock_init(), IS_NULL_PTR, dt_database_t::lock_acquired, and TRUE.
Referenced by dt_init(), and testdb_setup().
perform pre-db-close optimizations (always call when quiting darktable)
Definition at line 4050 of file database.c.
References _db, _is_mem_db(), DT_DEBUG_SQLITE3_EXEC, dt_database_t::handle, and IS_NULL_PTR.
Referenced by dt_cleanup().
Definition at line 3883 of file database.c.
References _db, _db_print, _get_pragma_int_val(), DT_DEBUG_SQLITE3_EXEC, ERRCHECK, dt_database_t::handle, and IS_NULL_PTR.
Referenced by dt_cleanup(), dt_init(), and optimize_database_callback().
Definition at line 4857 of file database.c.
References _db, _db_lock, _trx_batch_level, _trx_batch_owner, _trx_owner, _trxid, dt_atomic_get_int(), dt_atomic_sub_int(), DT_DEBUG_SQLITE3_EXEC, dt_pthread_rwlock_unlock(), and dt_database_t::handle.
Definition at line 4899 of file database.c.
References _db, _db_lock, _trx_batch_level, _trx_batch_owner, _trx_owner, _trxid, dt_atomic_set_int(), dt_atomic_sub_int(), DT_DEBUG_SQLITE3_EXEC, dt_pthread_rwlock_unlock(), and dt_database_t::handle.
Referenced by _history_snapshot_undo_restore(), dt_exif_xmp_read(), dt_history_snapshot_repository_create(), dt_removed_image_repository_create(), and dt_removed_image_repository_restore().
| void dt_database_set_prompt_handler | ( | dt_database_prompt_handler_t | handler | ) |
Install the handler the module asks through. NULL removes it.
Must be registered BEFORE dt_database_open() runs – which is before dt_gui_gtk_init(), so this one cannot go where the film/collection/folder-survey handlers go. darktable.c registers it, being the only thing that knows this early whether there will be a GUI.
With no handler, every prompt answers CLOSE: a corrupt database is not deleted or restored, and a schema is not migrated, on the strength of a question nobody was asked. That is also what makes a headless run safe – these dialogs used to be built unconditionally, with no has_gui guard, on a GTK that ansel-cli never initialises.
Definition at line 3062 of file database.c.
References _prompt_handler.
Referenced by dt_database_gui_register_handlers().
| void dt_database_set_renamed_handler | ( | dt_database_renamed_handler_t | handler | ) |
| void dt_database_set_settings | ( | const dt_database_settings_t * | settings | ) |
Replace the policy. Strings are copied; the caller keeps ownership of what it passed.
Definition at line 3666 of file database.c.
References _settings, _settings_lock, _settings_lock_inited, dt_database_settings_t::create_snapshot, dt_free, dt_pthread_mutex_init(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, dt_database_settings_t::keep_snapshots, dt_database_settings_t::maintenance_check, dt_database_settings_t::maintenance_freepage_ratio, and TRUE.
Referenced by _database_settings_from_conf().
| void dt_database_settings_free | ( | dt_database_settings_t * | settings | ) |
Release the strings owned by settings (not settings itself).
Definition at line 3711 of file database.c.
References dt_database_settings_t::create_snapshot, dt_free, IS_NULL_PTR, and dt_database_settings_t::maintenance_check.
Referenced by _snapshot_policy_decides(), dt_database_maybe_maintenance(), and dt_database_snaps_to_remove().
| char ** dt_database_snaps_to_remove | ( | void | ) |
get list of snapshot files to remove after successful snapshot
Definition at line 4408 of file database.c.
References _db, _db_print, _db_snap_sort(), _is_mem_db(), dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_database_get_settings(), dt_database_settings_free(), dt_free, error(), FALSE, IS_NULL_PTR, and dt_database_settings_t::keep_snapshots.
Referenced by dt_cleanup().
| gboolean dt_database_snapshot | ( | void | ) |
simply create db snapshot of both library and data
Definition at line 4118 of file database.c.
References _backup_db(), _db, _is_mem_db(), _print_backup_progress(), dt_database_t::dbfilename_data, dt_database_t::dbfilename_library, dt_free, FALSE, dt_database_t::handle, IS_NULL_PTR, and TRUE.
Referenced by backup_database_callback(), and dt_cleanup().
Definition at line 4805 of file database.c.
References _db, _db_lock, _trx_batch_level, _trx_batch_owner, _trx_owner, _trxid, dt_atomic_add_int(), dt_atomic_get_int(), DT_DEBUG_SQLITE3_EXEC, dt_pthread_rwlock_wrlock(), dt_database_t::handle, and MAX_NESTED_TRANSACTIONS.
| void dt_database_take_error | ( | dt_database_error_t * | error | ) |
Move the pending error out of the module into error, clearing it. Consumes it: a second call reports no error.
Definition at line 2734 of file database.c.
References _db, error(), dt_database_t::error_dbfilename, dt_database_t::error_message, dt_database_t::error_other_pid, IS_NULL_PTR, and dt_database_t::lock_acquired.
Referenced by dt_database_show_error().
|
static |
Definition at line 2784 of file database.c.
References dt_free, FALSE, pid_is_alive(), and TRUE.
Referenced by _lock_single_database(), and pid_is_alive().
|
static |
The one connection. NULL when nothing is open.
Definition at line 123 of file database.c.
Referenced by _ask_for_maintenance(), _is_mem_db(), dt_database_begin_transaction_batch(), dt_database_cleanup_busy_statements(), dt_database_close(), dt_database_end_transaction_batch(), dt_database_get_last_error(), dt_database_get_path(), dt_database_get_sqlite3_global(), dt_database_is_open(), dt_database_maybe_maintenance(), dt_database_maybe_snapshot(), dt_database_open(), dt_database_optimize(), dt_database_perform_maintenance(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), dt_database_snaps_to_remove(), dt_database_snapshot(), dt_database_start_transaction_debug(), and dt_database_take_error().
|
static |
Serialises the module's own work against dt_database_close().
It is a reader/writer lock rather than a mutex because that is the shape the workspace swap needs: every query takes it for reading and they proceed concurrently (sqlite is opened SERIALIZED and does its own internal locking), while closing takes it for writing and therefore waits for every in-flight query to finish.
It used to live on darktable_t as database_threadsafe, reachable through common/global_mutexes.h by anything that cared to take it. Two functions in this file were its only users.
Definition at line 141 of file database.c.
Referenced by dt_database_begin_transaction_batch(), dt_database_close(), dt_database_end_transaction_batch(), dt_database_open(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 142 of file database.c.
Referenced by dt_database_close(), and dt_database_open().
|
static |
Session constants, read once by the orchestrator and handed to dt_database_open().
Definition at line 152 of file database.c.
Referenced by _ask_for_maintenance(), and dt_database_open().
|
static |
Definition at line 3060 of file database.c.
Referenced by _ask_user(), and dt_database_set_prompt_handler().
|
static |
Told when the XDG migration renames the library out from under the configured name.
Definition at line 156 of file database.c.
Referenced by _database_migrate_to_xdg_structure(), and dt_database_set_renamed_handler().
|
static |
Maintenance and snapshot policy, told to us by the orchestrator. Guarded by _settings_lock, because the GUI thread replaces it while a maintenance decision may be reading it.
Definition at line 147 of file database.c.
Referenced by dt_database_get_settings(), and dt_database_set_settings().
|
static |
Definition at line 148 of file database.c.
Referenced by dt_database_get_settings(), dt_database_open(), and dt_database_set_settings().
|
static |
Definition at line 149 of file database.c.
Referenced by dt_database_get_settings(), dt_database_open(), and dt_database_set_settings().
|
static |
Definition at line 96 of file database.c.
Referenced by _database_init(), dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 98 of file database.c.
Referenced by _database_init(), dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 97 of file database.c.
Referenced by dt_database_begin_transaction_batch(), dt_database_end_transaction_batch(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 95 of file database.c.
Referenced by _database_init(), dt_database_release_transaction_debug(), dt_database_rollback_transaction(), and dt_database_start_transaction_debug().
|
static |
Definition at line 153 of file database.c.
Referenced by dt_database_open().