Skip to content

Commit

Permalink
Merge pull request #17359 from zisoft/fix-sql-texts
Browse files Browse the repository at this point in the history
fix sql text handling
  • Loading branch information
TurboGit authored Aug 24, 2024
2 parents 9c53167 + e314ac4 commit 95db78c
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/common/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -3171,30 +3171,46 @@ static int32_t _image_get_set_name_id(const char *table,

char *query = g_strdup_printf("SELECT id"
" FROM main.%s"
" WHERE LOWER(name) = LOWER('%s')",
table,
name);
" WHERE LOWER(name) = LOWER(?1)",
table);

DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
query, -1, &stmt, NULL);
query,
-1,
&stmt,
NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt,
1,
name,
-1,
SQLITE_TRANSIENT);

int32_t id = -1;

if(sqlite3_step(stmt) == SQLITE_ROW)
{
id = sqlite3_column_int(stmt, 0);
id = sqlite3_column_int(stmt,
0);
}
else
{
g_free(query);
query = g_strdup_printf("INSERT"
" INTO main.%s (name)"
" VALUES ('%s')",
table,
name);
" VALUES (?1)",
table);

DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db),
query, NULL, NULL, NULL);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
query,
-1,
&stmt,
NULL);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt,
1,
name,
-1,
SQLITE_TRANSIENT);
sqlite3_step(stmt);
id = dt_database_last_insert_rowid(darktable.db);
}

Expand Down

0 comments on commit 95db78c

Please sign in to comment.