Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
collection_query.c File Reference
#include <string.h>
#include "database/collection_query.h"
#include "database/database.h"
#include "database/sql_debug.h"
#include "metadata/colorlabels.h"
#include "common/datetime.h"
#include "metadata/map_locations.h"
#include "common/image.h"
#include "common/utility.h"
#include "system/dtpthread.h"
#include "system/macros.h"
#include "system/mem_alloc.h"
+ Include dependency graph for collection_query.c:

Go to the source code of this file.

Macros

#define LIMIT_QUERY   "LIMIT ?1, ?2"
 
#define and_operator_initial()   (0)
 
#define or_operator_initial()   (0)
 

Functions

static char * and_operator (int *term)
 
static char * or_operator (int *term)
 
void dt_collection_query_set_order_resolver (dt_collection_query_order_resolver_t fn)
 
void dt_collection_query_set_order_names (const char *const *names, const int count)
 
static int _store (gchar *query)
 
static gchar * get_query_string (const dt_collection_properties_t property, const gchar *text, const gboolean recursive)
 
static dt_collection_name_value_t_name_value_new (char *name, int id, int count, int status)
 
static gchar * _extended_where_excluding (const int exclude, const gboolean apply_exclude)
 
static gchar * _extended_where (void)
 
static void _set_selq_pre_sort (char **selq_pre)
 
static gchar * _sort_query (void)
 
static int _recompose (void)
 
static uint32_t _compute_count (void)
 
static const gchar * _ensure_query (void)
 
static gchar ** _compose_where_ext (const dt_collection_rule_t *rules, const int n_rules)
 
int dt_collection_query_set_rules (const dt_collection_params_t *params, const dt_collection_rule_t *rules, const int n_rules, const uint32_t tagid)
 
int dt_collection_query_recompose (void)
 
uint32_t dt_collection_query_count (void)
 
void dt_collection_query_set_iop_names (const dt_iop_name_row_t *rows, const size_t count)
 Fill memory.darktable_iop_names, the table the module-name rules join against.
 
uint64_t dt_collection_query_get_generation (void)
 
GListdt_collection_query_get_group_members (const int32_t group_id, const int32_t exclude_imgid)
 
GListdt_collection_query_get_property_values (const dt_collection_values_request_t *req)
 
void dt_collection_query_get_makermodels (const gchar *filter, GList **sanitized, GList **exif)
 
GListdt_collection_query_get_images_for_rule (const dt_collection_properties_t property, const char *text, gboolean recursive)
 
int32_t dt_collection_query_find_neighbour (GList *imgids)
 
void dt_collection_query_cleanup (void)
 
void dt_collection_query_refresh_memory_table (void)
 
GListdt_collection_query_get_images (const uint32_t limit)
 
int32_t dt_collection_query_get_nth (const int nth)
 
int dt_collection_query_image_offset (const int32_t imgid)
 
void dt_collection_query_pop (void)
 
void dt_collection_query_push (void)
 
void dt_collection_query_restrict_to_selection (void)
 

Variables

static dt_collection_params_t _params
 
static gchar ** _where_ext = NULL
 
static uint32_t _tagid = 0
 
static gchar * _query = NULL
 
static uint32_t _count = 0
 
static uint64_t _generation = 0
 
static dt_collection_query_order_resolver_t _order_resolver = NULL
 
static const char *const_order_names = NULL
 
static int _order_names_count = 0
 

Macro Definition Documentation

◆ and_operator_initial

#define and_operator_initial ( )    (0)

Definition at line 57 of file collection_query.c.

◆ LIMIT_QUERY

#define LIMIT_QUERY   "LIMIT ?1, ?2"

Definition at line 53 of file collection_query.c.

◆ or_operator_initial

#define or_operator_initial ( )    (0)

Definition at line 74 of file collection_query.c.

Function Documentation

◆ _compose_where_ext()

static gchar ** _compose_where_ext ( const dt_collection_rule_t rules,
const int  n_rules 
)
static

Turn the rules into the array of WHERE fragments the query is built from.

One fragment per rule, each prefixed by its conjunction, exactly as the caller used to assemble them before handing the array over. An empty rule contributes " OR 1=1" in OR mode and nothing otherwise, which is what makes a blank OR row mean "everything".

Definition at line 1085 of file collection_query.c.

References dt_free, get_query_string(), i, IS_NULL_PTR, L, and r.

Referenced by dt_collection_query_set_rules().

◆ _compute_count()

◆ _ensure_query()

◆ _extended_where()

static gchar * _extended_where ( void  )
static

Definition at line 682 of file collection_query.c.

References _where_ext, dt_free, and L.

Referenced by _recompose().

◆ _extended_where_excluding()

static gchar * _extended_where_excluding ( const int  exclude,
const gboolean  apply_exclude 
)
static

The WHERE for every rule except exclude – or NO restriction at all when apply_exclude is FALSE. The caller decides whether the exclusion applies (that used to be a conf read of "plugins/lighttable/collect/mode<N>", and conf is not this module's to read), and FALSE means the rule being edited is an OR rule: an OR rule does not limit the collection, so nothing may limit its value list either. The original spelled this "don't limit the collection for OR" and appended no rule whatsoever.

Definition at line 666 of file collection_query.c.

References _where_ext, dt_free, dt_util_dstrcat(), i, IS_NULL_PTR, and L.

Referenced by dt_collection_query_get_property_values().

◆ _name_value_new()

static dt_collection_name_value_t * _name_value_new ( char *  name,
int  id,
int  count,
int  status 
)
static

Definition at line 650 of file collection_query.c.

References L, name, and v.

Referenced by dt_collection_query_get_property_values().

◆ _recompose()

◆ _set_selq_pre_sort()

static void _set_selq_pre_sort ( char **  selq_pre)
static

Definition at line 690 of file collection_query.c.

References _tagid, dt_util_dstrcat(), and L.

Referenced by _recompose().

◆ _sort_query()

◆ _store()

static int _store ( gchar *  query)
static

Definition at line 103 of file collection_query.c.

References _generation, _query, dt_free, and L.

Referenced by _recompose().

◆ and_operator()

static char * and_operator ( int *  term)
static

Definition at line 58 of file collection_query.c.

References IS_NULL_PTR, and L.

Referenced by _recompose().

◆ dt_collection_query_cleanup()

void dt_collection_query_cleanup ( void  )

Finalise the cached statements and release the stored rules. Must run before the connection closes.

Definition at line 1595 of file collection_query.c.

References _params, _query, _where_ext, dt_free, L, and dt_collection_params_t::text_filter.

Referenced by dt_collection_free(), and testdb_teardown().

◆ dt_collection_query_count()

uint32_t dt_collection_query_count ( void  )

How many images the collection currently holds.

Definition at line 1132 of file collection_query.c.

References _count.

Referenced by dt_collection_get_count(), and dt_collection_query_get_nth().

◆ dt_collection_query_find_neighbour()

int32_t dt_collection_query_find_neighbour ( GList imgids)

The first collected image that is not in imgids, looked for after the list and then before it; -1 if there is none.

Definition at line 1529 of file collection_query.c.

References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, dt_util_dstrcat(), i, IS_NULL_PTR, and L.

Referenced by dt_collection_update_query().

◆ dt_collection_query_get_generation()

uint64_t dt_collection_query_get_generation ( void  )

A number that advances on every recomposition.

Callers that need to notice "the collection changed" compare this. It replaces hashing the query string, which required the text to leave the module.

Definition at line 1161 of file collection_query.c.

References _generation.

Referenced by _dt_collection_get_hash().

◆ dt_collection_query_get_group_members()

GList * dt_collection_query_get_group_members ( const int32_t  group_id,
const int32_t  exclude_imgid 
)

Members of image group group_id that are IN the current collection, exclude_imgid left out. Lives here rather than in image_repository because it is scoped by the collection query, and that text does not leave this file.

Definition at line 1168 of file collection_query.c.

References _ensure_query(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, IS_NULL_PTR, and L.

Referenced by dt_grouping_add_grouped_images().

◆ dt_collection_query_get_images()

GList * dt_collection_query_get_images ( const uint32_t  limit)

The first limit image ids of the collection, in collection order (-1 for all of them).

Definition at line 1648 of file collection_query.c.

References _ensure_query(), _params, COLLECTION_QUERY_USE_LIMIT, dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, L, and dt_collection_params_t::query_flags.

Referenced by dt_collection_get().

◆ dt_collection_query_get_images_for_rule()

GList * dt_collection_query_get_images_for_rule ( const dt_collection_properties_t  property,
const char *  text,
gboolean  recursive 
)

Image ids matching ONE rule, independent of the active collection – what batch operations enumerate over.

Definition at line 1503 of file collection_query.c.

References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, get_query_string(), IS_NULL_PTR, and L.

Referenced by dt_collection_get_images_for_rule().

◆ dt_collection_query_get_makermodels()

void dt_collection_query_get_makermodels ( const gchar *  filter,
GList **  sanitized,
GList **  exif 
)

Camera maker/model pairs present in the library, sanitised and as EXIF recorded them.

Definition at line 1442 of file collection_query.c.

References dt_collection_get_makermodel(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, FALSE, IS_NULL_PTR, key, L, and TRUE.

Referenced by dt_collection_get_makermodels().

◆ dt_collection_query_get_nth()

int32_t dt_collection_query_get_nth ( const int  nth)

◆ dt_collection_query_get_property_values()

◆ dt_collection_query_image_offset()

int dt_collection_query_image_offset ( const int32_t  imgid)

The position of imgid within the collection, or 0 if it is not in it – the original's convention, which callers use to land at the start rather than error out.

Definition at line 1694 of file collection_query.c.

References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, IS_NULL_PTR, L, TRUE, and UNKNOWN_IMAGE.

Referenced by dt_collection_image_offset_with_collection().

◆ dt_collection_query_pop()

void dt_collection_query_pop ( void  )

Definition at line 1723 of file collection_query.c.

References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, and L.

Referenced by dt_pop_collection().

◆ dt_collection_query_push()

void dt_collection_query_push ( void  )

Save / restore memory.collected_images, for code that needs to collect something else for a moment and put the user's collection back afterwards.

Definition at line 1732 of file collection_query.c.

References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, and L.

Referenced by dt_push_collection().

◆ dt_collection_query_recompose()

int dt_collection_query_recompose ( void  )

Recompose from the rules already held – what a caller does after changing something the query text depends on without changing the rules themselves.

Definition at line 1127 of file collection_query.c.

References _recompose().

◆ dt_collection_query_refresh_memory_table()

void dt_collection_query_refresh_memory_table ( void  )

◆ dt_collection_query_restrict_to_selection()

void dt_collection_query_restrict_to_selection ( void  )

Drop from memory.collected_images everything that is not in main.selected_images.

Definition at line 1741 of file collection_query.c.

References _compute_count(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, and L.

Referenced by dt_selection_to_culling_mode().

◆ dt_collection_query_set_iop_names()

void dt_collection_query_set_iop_names ( const dt_iop_name_row_t rows,
const size_t  count 
)

Fill memory.darktable_iop_names, the table the module-name rules join against.

Must run before any collection query naming a module. The table lives here because these queries are its only readers; the localised names come from the module objects, which the caller owns.

Definition at line 1137 of file collection_query.c.

References dt_database_get_sqlite3_global(), dt_database_release_transaction, dt_database_start_transaction, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, i, IS_NULL_PTR, L, and name.

Referenced by dt_iop_set_darktable_iop_table().

◆ dt_collection_query_set_order_names()

void dt_collection_query_set_order_names ( const char *const names,
const int  count 
)

Supply the user-visible module-order names, index-aligned with the versions stored in main.module_order. The value list for that property interpolates them into its query, so the module needs the strings themselves – but not the ability to translate. Borrowed.

Definition at line 96 of file collection_query.c.

References _order_names, _order_names_count, and L.

Referenced by dt_collection_new().

◆ dt_collection_query_set_order_resolver()

void dt_collection_query_set_order_resolver ( dt_collection_query_order_resolver_t  fn)

Definition at line 91 of file collection_query.c.

References _order_resolver, and L.

Referenced by dt_collection_new().

◆ dt_collection_query_set_rules()

int dt_collection_query_set_rules ( const dt_collection_params_t params,
const dt_collection_rule_t rules,
const int  n_rules,
const uint32_t  tagid 
)

Replace the rules and recompose.

The rules arrive as rules – property, mode, text – not as SQL. Turning them into WHERE fragments and assembling the query is this module's whole job. Everything is copied, so the caller keeps ownership of what it passed.

Definition at line 1109 of file collection_query.c.

References _compose_where_ext(), _params, _recompose(), _tagid, _where_ext, dt_free, IS_NULL_PTR, L, and dt_collection_params_t::text_filter.

Referenced by dt_collection_update().

◆ get_query_string()

static gchar * get_query_string ( const dt_collection_properties_t  property,
const gchar *  text,
const gboolean  recursive 
)
static

The WHERE built from the rules the caller handed in, as "(1=1<rule><rule>...)".

The original took an exclude index and, for exclude >= 0, read "plugins/lighttable/collect/mode<N>" from conf to decide whether to honour it. That branch serves dt_collection_get_images_for_rule() and stays in common/collection.c with the conf it needs; only the plain join is composition.

Definition at line 123 of file collection_query.c.

References _order_resolver, color, dt_collection_get_makermodels(), DT_COLLECTION_PROP_APERTURE, DT_COLLECTION_PROP_CAMERA, DT_COLLECTION_PROP_CHANGE_TIMESTAMP, DT_COLLECTION_PROP_COLORLABEL, DT_COLLECTION_PROP_DAY, DT_COLLECTION_PROP_EXPORT_TIMESTAMP, DT_COLLECTION_PROP_EXPOSURE, DT_COLLECTION_PROP_FILENAME, DT_COLLECTION_PROP_FILMROLL, DT_COLLECTION_PROP_FOCAL_LENGTH, DT_COLLECTION_PROP_FOLDERS, DT_COLLECTION_PROP_GEOTAGGING, DT_COLLECTION_PROP_GROUPING, DT_COLLECTION_PROP_HISTORY, DT_COLLECTION_PROP_IMPORT_TIMESTAMP, DT_COLLECTION_PROP_ISO, DT_COLLECTION_PROP_LENS, DT_COLLECTION_PROP_LOCAL_COPY, DT_COLLECTION_PROP_METADATA, DT_COLLECTION_PROP_MODULE, DT_COLLECTION_PROP_ORDER, DT_COLLECTION_PROP_PRINT_TIMESTAMP, DT_COLLECTION_PROP_QUERY, DT_COLLECTION_PROP_RATING, DT_COLLECTION_PROP_TAG, DT_COLLECTION_PROP_TIME, dt_collection_split_operator_datetime(), dt_collection_split_operator_exposure(), dt_collection_split_operator_number(), dt_datetime_exif_to_gtimespan(), dt_free, dt_free_gpointer(), DT_IMAGE_LOCAL_COPY, dt_map_location_data_tag_root(), dt_metadata_get_keyid_by_display_order(), DT_METADATA_NUMBER, dt_util_dstrcat(), dt_util_glist_to_str(), dt_util_str_to_glist(), i, IS_NULL_PTR, L, and name.

Referenced by _compose_where_ext(), and dt_collection_query_get_images_for_rule().

◆ or_operator()

static char * or_operator ( int *  term)
static

Definition at line 75 of file collection_query.c.

References IS_NULL_PTR, and L.

Referenced by _recompose().

Variable Documentation

◆ _count

uint32_t _count = 0
static

Definition at line 46 of file collection_query.c.

Referenced by _compute_count(), and dt_collection_query_count().

◆ _generation

uint64_t _generation = 0
static

Definition at line 47 of file collection_query.c.

Referenced by _store(), and dt_collection_query_get_generation().

◆ _order_names

const char* const* _order_names = NULL
static

◆ _order_names_count

int _order_names_count = 0
static

◆ _order_resolver

dt_collection_query_order_resolver_t _order_resolver = NULL
static

Definition at line 48 of file collection_query.c.

Referenced by dt_collection_query_set_order_resolver(), and get_query_string().

◆ _params

◆ _query

gchar* _query = NULL
static

Definition at line 45 of file collection_query.c.

Referenced by _ensure_query(), _store(), and dt_collection_query_cleanup().

◆ _tagid

uint32_t _tagid = 0
static

◆ _where_ext

gchar** _where_ext = NULL
static