aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-16 00:04:51 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-16 00:04:51 +0200
commit97e14c73be6684259e235a92cc575ea39a04fc7e (patch)
tree6aa652453a118b9863687ba80b5c3c3c425ed1cd /src/actions.c
parent967ad7898243e083f485a03414fce0018bfce881 (diff)
downloadck-97e14c73be6684259e235a92cc575ea39a04fc7e.tar.gz
ck-97e14c73be6684259e235a92cc575ea39a04fc7e.tar.bz2
ck-97e14c73be6684259e235a92cc575ea39a04fc7e.zip
[ckdb] simplify open_DB and make_DB
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c47
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();