diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -963,17 +963,19 @@ static void ftag_sync(int argc, char **argv) parse_args(argc - 1, argv + 1, sync_commands, sync_command_count); } -/* 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, char **cols, char **) +/* Check whether the entry we are querying exists or not. _SHALL_EXIST is a + * boolean indicating whether it is supposed to exist or not. If this callback + * is ever called, then the entry exists. */ +static int +ftag_tag_shall_exist_callback(void *_shall_exist, int, char **cols, char **) { + int shall_exist = (intptr_t)_shall_exist; assert(cols[0]); - assert(cols[1]); - fprintf(stderr, - "ftag tag add: error: tag \"%s\" already exists, " - "its description is:\n%s\n", - cols[0], cols[1]); - return 1; + if (!shall_exist) { + fprintf(stderr, + "ftag: error: entry \"%s\" already exists", cols[0]); + } + return !shall_exist; } static void ftag_tag_add(int argc, char **argv) @@ -994,7 +996,8 @@ static void ftag_tag_add(int argc, char **argv) strbuild(sql, "SELECT name, description FROM tags WHERE name = '%s';", new_tag_name); - rc = sqlite3_exec(db, sql, ftag_tag_check, NULL, NULL); + rc = sqlite3_exec(db, sql, + ftag_tag_shall_exist_callback, (intptr_t)0, NULL); sqlite3_check(rc, db); int next_id = table_next_id(db, "tags"); |
