diff options
Diffstat (limited to 'src/actions.c')
-rw-r--r-- | src/actions.c | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/src/actions.c b/src/actions.c index 4620c0d..882fa30 100644 --- a/src/actions.c +++ b/src/actions.c @@ -27,8 +27,8 @@ int run_INIT(UserOpt * opt, Conf *conf) { sERR("Cound not create config file."); return -1; } - DB db = init_make_DB(opt); - if (db.error == SQL_NO_ERR) { + DB db; + if (!init_make_DB(&db, opt)) { init_make_tables(&db); } sqlite3_close(db.ptr); @@ -36,12 +36,9 @@ int run_INIT(UserOpt * opt, Conf *conf) { } int run_ADD(UserOpt * opt, Conf *conf) { - DB db = open_DB(opt); - if (db.ptr == NULL) { - if (db.error == SQL_ERR_NO_TABLES) { - ERR("The database file is currupted. Run ck init anew."); - } - goto error; + DB db; + if (open_DB(&db, opt)) { + return -1; } AddOpt addOpt = add_make_options(opt->args); switch (addOpt.err) { @@ -74,11 +71,7 @@ int run_ADD(UserOpt * opt, Conf *conf) { int run_DEL(UserOpt * opt, Conf *conf) { UNUSED(conf); DB db; - db = open_DB(opt); - if (db.ptr == NULL) { - if (db.error == SQL_ERR_NO_TABLES) { - ERR("The database file is currupted. Run ck init anew."); - } + if (open_DB(&db, opt)) { return -1; } @@ -109,11 +102,8 @@ int run_DEL(UserOpt * opt, Conf *conf) { } int run_EDIT(UserOpt *opt, Conf *conf) { - DB db = open_DB(opt); - if (db.ptr == NULL) { - if (db.error == SQL_ERR_NO_TABLES) { - ERR("The database file is currupted. Run ck init anew."); - } + DB db; + if (open_DB(&db, opt)) { return -1; } @@ -183,11 +173,8 @@ int run_EDIT(UserOpt *opt, Conf *conf) { } int run_LIST(UserOpt *opt, Conf *conf) { - DB db = open_DB(opt); - if (db.ptr == NULL) { - if (db.error == SQL_ERR_NO_TABLES) { - ERR("The database file is currupted. Run ck init anew."); - } + DB db; + if (open_DB(&db, opt)) { return -1; } @@ -257,11 +244,8 @@ int run_SEARCH(UserOpt *opt, Conf *conf) { ERR("No grep avaliable. Please make sure you have grep installed."); return -1; } - DB db = open_DB(opt); - if (db.ptr == NULL) { - if (db.error == SQL_ERR_NO_TABLES) { - ERR("The database file is currupted. Run ck init anew."); - } + DB db; + if (open_DB(&db, opt)) { return -1; } @@ -319,11 +303,8 @@ int run_HELP(UserOpt *opt, Conf *conf) { } int run_RESTORE(UserOpt *opt, Conf *conf) { - DB db = open_DB(opt); - if (db.ptr == NULL) { - if (db.error == SQL_ERR_NO_TABLES) { - ERR("The database file is currupted. Run ck init anew."); - } + DB db; + if (open_DB(&db, opt)) { return -1; } cklist *from = list_make_new(); |