Project

General

Profile

Bug #9210

delete + insert instead of "insert or replace"

Added by Pascal Obry almost 7 years ago. Updated about 6 years ago.

Status:
Fixed
Priority:
Low
Assignee:
Category:
General
Target version:
Start date:
01/27/2013
Due date:
% Done:

100%

Estimated time:
Affected Version:
git development version
System:
all
bitness:
64-bit
hardware architecture:
amd64/x86

Description

For example in dt_gui_presets_add_generic we have:

DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "delete from presets where name=?1 and operation=?2 and op_version=?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, strlen(name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, op, strlen(op), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, version);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "insert into presets (name, description, operation, op_version, op_params, enabled, " 
"blendop_params, blendop_version, multi_priority, multi_name, model, maker, lens, "
"iso_min, iso_max, exposure_min, exposure_max, aperture_min, aperture_max, focal_length_min, focal_length_max, "
"writeprotect, autoapply, filter, def, isldr) "
"values (?1, '', ?2, ?3, ?4, ?5, ?6, ?7, 0, '', '%', '%', '%', 0, 51200, 0, 10000000, 0, 100000000, 0, 1000, 1, 0, 0, 0, 0)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, strlen(name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, op, strlen(op), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, version);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 4, params, params_size, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 5, enabled);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 6, &default_blendop_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 7, dt_develop_blend_version());
sqlite3_step(stmt);
sqlite3_finalize(stmt);

But I suppose this can be written with a simple "insert or replace":

DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "insert or replace into presets (name, description, operation, op_version, op_params, enabled, " 
"blendop_params, blendop_version, multi_priority, multi_name, model, maker, lens, "
"iso_min, iso_max, exposure_min, exposure_max, aperture_min, aperture_max, focal_length_min, focal_length_max, "
"writeprotect, autoapply, filter, def, isldr) "
"values (?1, '', ?2, ?3, ?4, ?5, ?6, ?7, 0, '', '%', '%', '%', 0, 51200, 0, 10000000, 0, 100000000, 0, 1000, 1, 0, 0, 0, 0)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, strlen(name), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, op, strlen(op), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, version);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 4, params, params_size, SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 5, enabled);
DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 6, &default_blendop_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 7, dt_develop_blend_version());
sqlite3_step(stmt);
sqlite3_finalize(stmt);

This will remove an SQL statement. Possible gaining some CPU cycles and removing some code, so an easier maintenance.

What do you think?

Did I miss something?

History

#1 Updated by Pascal Obry about 6 years ago

  • bitness set to 64-bit
  • System set to all
  • % Done changed from 0 to 100
  • Status changed from New to Fixed

Also available in: Atom PDF

Go to top