80 if(imgid <= 0)
return 0;
88 "SELECT history_end FROM main.images WHERE id=?1", -1,
104 if(imgid <= 0)
return FALSE;
111 "UPDATE main.images SET history_end = ?1 WHERE id = ?2", -1,
126 if(imgid <= 0)
return 0;
135 "SELECT IFNULL(MAX(num)+1, 0) FROM main.history"
152 if(imgid <= 0 ||
delta == 0)
return TRUE;
159 "UPDATE main.history SET num = num + ?2 WHERE imgid = ?1", -1,
173 const int op_params_size,
const int module_version,
const gboolean enabled,
174 const void *blendop_params,
const int blendop_params_size,
175 const int blendop_version,
const int multi_priority,
const char *multi_name)
186 "SELECT num FROM main.history WHERE imgid = ?1 AND num = ?2", -1,
197 "INSERT INTO main.history (imgid, num) VALUES (?1, ?2)", -1,
210 "UPDATE main.history"
211 " SET operation = ?1, op_params = ?2, module = ?3, enabled = ?4, "
212 " blendop_params = ?7, blendop_version = ?8, multi_priority = ?9, multi_name = ?10"
213 " WHERE imgid = ?5 AND num = ?6",
237 if(imgid <= 0)
return FALSE;
243 "DELETE FROM main.history WHERE imgid = ?1", -1,
256 if(imgid <= 0)
return FALSE;
262 "DELETE FROM main.masks_history WHERE imgid = ?1", -1,
275 if(imgid <= 0)
return FALSE;
292 "SELECT imgid, num, module, operation,"
293 " op_params, enabled, blendop_params,"
294 " blendop_version, multi_priority, multi_name"
323 blendop_params,
bl_length, blendop_version, multi_priority, multi_name,
"");
345 " SELECT ?1, 0, op_version, operation, op_params,"
346 " enabled, blendop_params, blendop_version, multi_priority, multi_name, name"
348 " WHERE ( (autoapply=1"
349 " AND ((?2 LIKE model AND ?3 LIKE maker) OR (?4 LIKE model AND ?5 LIKE maker))"
350 " AND ?6 LIKE lens AND ?7 BETWEEN iso_min AND iso_max"
351 " AND ?8 BETWEEN exposure_min AND exposure_max"
352 " AND ?9 BETWEEN aperture_min AND aperture_max"
353 " AND ?10 BETWEEN focal_length_min AND focal_length_max"
354 " AND (format = 0 OR (format & ?11 != 0 AND ~format & ?12 != 0)))"
356 " AND operation NOT IN"
357 " ('ioporder', 'metadata', 'modulegroups', 'export', 'tagging', 'collect', 'basecurve')"
358 " ORDER BY writeprotect DESC, LENGTH(model), LENGTH(maker), LENGTH(lens)",
400 blendop_params,
bl_length, blendop_version, multi_priority, multi_name, preset_name);
407 const int iformat,
const int excluded,
void **params,
424 " AND ((?2 LIKE model AND ?3 LIKE maker) OR (?4 LIKE model AND ?5 LIKE maker))"
425 " AND ?6 LIKE lens AND ?7 BETWEEN iso_min AND iso_max"
426 " AND ?8 BETWEEN exposure_min AND exposure_max"
427 " AND ?9 BETWEEN aperture_min AND aperture_max"
428 " AND ?10 BETWEEN focal_length_min AND focal_length_max"
429 " AND (format = 0 OR (format & ?11 != 0 AND ~format & ?12 != 0))"
430 " AND operation = 'ioporder'"
431 " ORDER BY writeprotect DESC, LENGTH(model), LENGTH(maker), LENGTH(lens)",
479 "SELECT COUNT(imgid) FROM main.history WHERE imgid = ?1", -1,
495 void **params, int32_t *params_len)
508 "SELECT op_params, enabled"
510 " WHERE imgid=?1 AND operation=?2"
511 " ORDER BY num DESC LIMIT 1", -1,
525 memcpy(*params, blob, len);
536 gboolean result =
FALSE;
546 " WHERE imgid= ?1 AND operation = ?2",
564 if(imgid <= 0)
return FALSE;
572 "DELETE FROM main.history WHERE imgid = ?1",
579 "DELETE FROM main.module_order WHERE imgid = ?1",
588 " SET history_end = 0, aspect_ratio = 0.0"
597 "DELETE FROM main.masks_history WHERE imgid = ?1",
604 "DELETE FROM main.history_hash WHERE imgid = ?1",
623 "SELECT num, operation, enabled, multi_name"
626 " AND num IN (SELECT MAX(num)"
627 " FROM main.history hst2"
628 " WHERE hst2.imgid=?1"
629 " AND hst2.operation=main.history.operation"
630 " GROUP BY multi_priority)"
631 " AND enabled in (1, ?2)"
632 " ORDER BY num DESC",
654 "SELECT operation, enabled, multi_name"
656 " WHERE imgid=?1 ORDER BY num DESC", -1, &
stmt,
NULL);
668 const int form,
const char *
name,
const int version,
670 const int points_count,
const void *source,
677 "INSERT INTO main.masks_history (imgid, num, formid, form, name, version, points, points_count, source) "
678 "VALUES (?1, ?9, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
701 "SELECT COUNT(*) FROM main.masks_history WHERE imgid = ?1", -1,
719 "SELECT imgid, formid, form, name, version, points, points_count, source, num"
720 " FROM main.masks_history"
737 const int op_params_size)
741 "SELECT module FROM main.history WHERE operation = ?1 AND op_params = ?2",
763 "SELECT MIN(num) AS num, operation, multi_name "
765 "WHERE imgid = ?1 AND enabled = 1 "
766 "GROUP BY operation, multi_name "
767 "ORDER BY MIN(num) ASC", -1, &
stmt,
NULL);
789 "SELECT version FROM main.module_order WHERE imgid = ?1", -1,
815 if(imgid <= 0)
return FALSE;
823 "SELECT version, iop_list"
824 " FROM main.module_order"
866 const char *iop_list)
868 if(imgid <= 0)
return FALSE;
876 "INSERT OR REPLACE INTO main.module_order VALUES (?1, 0, NULL)",
890 "UPDATE main.module_order SET version = ?2, iop_list = ?3"
909 "UPDATE main.module_order SET version = ?2, iop_list = NULL"
sqlite3 * dt_database_get_sqlite3_global(void)
static int dt_pthread_mutex_unlock(dt_pthread_mutex_t *mutex) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
static int dt_pthread_mutex_lock(dt_pthread_mutex_t *mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS
void dt_history_repository_foreach_auto_preset_row(const int32_t imgid, const dt_image_t *image, const char *workflow_preset, const int iformat, const int excluded, dt_history_repository_row_cb cb, void *user_data)
static sqlite3_stmt * _module_order_select_stmt
static sqlite3_stmt * _history_check_module_exists_stmt
static sqlite3_stmt * _history_select_history_stmt
static sqlite3_stmt * _history_get_next_num_stmt
static sqlite3_stmt * _history_update_item_stmt
static void _history_stmt_mutex_ensure(void)
gboolean dt_history_repository_get_module_order(const int32_t imgid, dt_module_order_row_t *row)
Read imgid's row. FALSE when there is none, and row is then left zeroed.
static gsize _history_stmt_mutex_inited
void dt_history_repository_foreach_last_item(const int32_t imgid, const gboolean enabled, dt_history_repository_item_cb cb, void *user_data)
void dt_history_repository_foreach_mask_item(const int32_t imgid, dt_history_repository_mask_cb cb, void *user_data)
gboolean dt_history_repository_get_last_enabled_params(const int32_t imgid, const char *operation, void **params, int32_t *params_len)
gboolean dt_history_repository_delete_dev_history(const int32_t imgid)
gboolean dt_history_repository_shift_nums(const int32_t imgid, const int delta)
gboolean dt_history_repository_write_item(const int32_t imgid, const int num, const char *operation, const void *op_params, const int op_params_size, const int module_version, const gboolean enabled, const void *blendop_params, const int blendop_params_size, const int blendop_version, const int multi_priority, const char *multi_name)
static sqlite3_stmt * _history_shift_history_nums_stmt
static sqlite3_stmt * _module_order_update_list_stmt
static sqlite3_stmt * _history_count_items_stmt
gboolean dt_history_repository_write_mask_item(const int32_t imgid, const int num, const int formid, const int form, const char *name, const int version, const void *points, const int points_len, const int points_count, const void *source, const int source_len)
static sqlite3_stmt * _history_delete_history_stmt
int dt_history_repository_count_mask_items(const int32_t imgid)
static sqlite3_stmt * _history_insert_num_stmt
static sqlite3_stmt * _history_auto_presets_legacy_stmt
void dt_history_repository_cleanup(void)
gboolean dt_history_repository_module_exists(const int32_t imgid, const char *operation)
static sqlite3_stmt * _module_order_select_version_stmt
static sqlite3_stmt * _history_delete_masks_stmt
gboolean dt_history_repository_delete_masks_history(const int32_t imgid)
static sqlite3_stmt * _module_order_insert_stmt
gboolean dt_history_repository_delete_all_for_image(const int32_t imgid)
void dt_module_order_row_cleanup(dt_module_order_row_t *row)
Release what dt_history_repository_get_module_order() allocated.
gboolean dt_history_repository_get_autoapply_ioporder_params(const int32_t imgid, const dt_image_t *image, const int iformat, const int excluded, void **params, int32_t *params_len)
static sqlite3_stmt * _history_set_end_stmt
gboolean dt_history_repository_set_module_order(const int32_t imgid, const int version, const char *iop_list)
Store imgid's order: version, and iop_list serialized or NULL.
static sqlite3_stmt * _history_auto_ioporder_stmt
void dt_history_repository_foreach_item(const int32_t imgid, dt_history_repository_item_cb cb, void *user_data)
int dt_history_repository_find_version_for_params(const char *operation, const void *op_params, const int op_params_size)
The module version some image's history recorded for this exact parameter blob.
gboolean dt_history_repository_delete_history(const int32_t imgid)
static sqlite3_stmt * _history_get_end_stmt
static dt_pthread_mutex_t _history_stmt_mutex
int dt_history_repository_count_items(const int32_t imgid)
static sqlite3_stmt * _module_order_update_null_stmt
gboolean dt_history_repository_set_end(const int32_t imgid, const int32_t history_end)
gboolean dt_history_repository_has_custom_module_order(const int32_t imgid)
Whether imgid's row stores a serialized list, i.e. iop_list IS NOT NULL.
gboolean dt_history_repository_get_module_order_version(const int32_t imgid, int *version)
imgid's stored order version.
static sqlite3_stmt * _history_select_num_stmt
gboolean dt_history_repository_has_module_order(const int32_t imgid)
Whether imgid has a main.module_order row at all, whatever it says.
static sqlite3_stmt * _history_auto_presets_stmt
int32_t dt_history_repository_get_end(const int32_t imgid)
int32_t dt_history_repository_get_next_num(const int32_t imgid)
void dt_history_repository_foreach_active_module(const int32_t imgid, dt_history_repository_active_module_cb cb, void *user_data)
Every module an image has enabled, once each, in the order they run.
void dt_history_repository_foreach_row(const int32_t imgid, dt_history_repository_row_cb cb, void *user_data)
void(* dt_history_repository_active_module_cb)(void *user_data, const int num, const char *operation, const char *multi_name)
void(* dt_history_repository_item_cb)(void *user_data, const int num, const char *operation, const gboolean enabled, const char *multi_name)
void(* dt_history_repository_mask_cb)(void *user_data, const int num, const int formid, const int form, const char *name, const int version, const void *points, const int points_len, const int points_count, const void *source, const int source_len)
void(* dt_history_repository_row_cb)(void *user_data, const int32_t imgid, const int num, const int module_version, const char *operation, const void *op_params, const int op_params_len, const gboolean enabled, const void *blendop_params, const int blendop_params_len, const int blendop_version, const int multi_priority, const char *multi_name, const char *preset_name)
@ DT_IMAGE_NO_LEGACY_PRESETS
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Checked wrappers around the sqlite3_* calls: trace the statement, assert the return code,...
#define DT_DEBUG_SQLITE3_BIND_BLOB(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_BIND_TEXT(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_BIND_INT(a, b, c)
#define DT_DEBUG_SQLITE3_BIND_DOUBLE(a, b, c)
One main.module_order row.