From afb8845d25eb4104150193be691d4b60a051ec82 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Tue, 11 Nov 2025 18:27:03 +0100 Subject: Change tag checking SQL query Also remove debug code. --- src/main.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/main.c b/src/main.c index f5cb938..4ea755c 100644 --- a/src/main.c +++ b/src/main.c @@ -66,36 +66,23 @@ static void ftag_help(int, char **) /* Check that the tag we are trying to create does not exist yet. If this * callback is ever called, then it already exist, this is a fatal error. */ -static int ftag_tag_check(void *, int count, char **cols, char **col_names) +static int ftag_tag_check(void *, int, char **cols, char **) { + assert(cols[0]); assert(cols[1]); - assert(cols[2]); fprintf(stderr, - "ftag tag add: error: tag %s already exists, its description is:\n", - cols[1]); - fprintf(stderr, "%s\n", cols[2]); + "ftag tag add: error: tag \"%s\" already exists, its description is:\n", + cols[0]); + fprintf(stderr, "%s\n", cols[1]); return 1; } -static int ftag_tag_last_id(void *_id, int count, char **cols, char **col_names) +static int ftag_tag_last_id(void *_id, int, char **cols, char **) { - printf("%s: count is %d\n", __func__, count); - printf("%s: ", __func__); - for (int i = 0; i < count; i++) { - printf("col_names[%d] = %s\t", i, col_names[i]); - } - printf("\n"); - printf("%s: ", __func__); - for (int i = 0; i < count; i++) { - printf("cols[%d] = %s\t", i, cols[i]); - } - printf("\n"); - - /* int *id = _id; */ - /* assert(count == 1); */ - /* assert(cols); */ - /* assert(cols[0]); */ - /* *id = atoi(cols[0]); */ + int *id = _id; + assert(cols); + assert(cols[0]); + *id = atoi(cols[0]); return 0; } @@ -120,7 +107,7 @@ static void ftag_tag_add(int argc, char **argv) memset(sql, 0, sizeof(sql)); snprintf(sql, sizeof(sql)-1, - "SELECT * FROM tags WHERE name = '%s';", new_tag_name); + "SELECT name, description FROM tags WHERE name = '%s';", new_tag_name); rc = sqlite3_exec(db, sql, ftag_tag_check, NULL, NULL); sqlite3_check(rc, db); -- cgit v1.2.3