aboutsummaryrefslogtreecommitdiffstats
path: root/src/dblayer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dblayer.c')
-rw-r--r--src/dblayer.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/dblayer.c b/src/dblayer.c
index 97a93db..a6e6193 100644
--- a/src/dblayer.c
+++ b/src/dblayer.c
@@ -79,37 +79,41 @@ void close_DB(DB *db) {
sqlite3_close(db->ptr);
}
-DB init_make_DB(const UserOpt *opt) {
- sqlite3 *db;
- char db_path[STR_L] = "";
+int open_DB(DB *db, const UserOpt *opt) {
+ if (!db || !opt) {
+ return -1;
+ }
int rc;
+ char db_path[STR_L] = "";
make_db_name(db_path, opt->confDir);
- rc = sqlite3_open(db_path, &db);
- if (rc != SQLITE_OK) {
- return empty_DB(SQL_ERR_NO_DB_FILE);
+ rc = sqlite3_open(db_path, &db->ptr);
+
+ if (rc) {
+ ERR("%s is not a path to an sqlite3 database.", db_path);
+ return -1;
+ }
+
+ if (check_initialized_DB(db->ptr)) {
+ ERR("The database file is currupted. Run ck init anew.");
+ return -1;
}
- return new_DB(db);
+ LOG("Opened %s", db_path);
+ return 0;
}
-DB open_DB(const UserOpt *opt) {
- sqlite3 *db;
- int rc;
+int init_make_DB(DB *db, const UserOpt *opt) {
char db_path[STR_L] = "";
+ int rc;
- make_db_name(db_path, opt->confDir);
- rc = sqlite3_open(db_path, &db);
-
- if (rc) {
- return empty_DB(SQL_ERR_NO_DB_FILE);
- }
-
- if (check_initialized_DB(db)) {
- return empty_DB(SQL_ERR_NO_TABLES);
+ make_db_name(db_path, opt->confDir);
+ rc = sqlite3_open(db_path, &db->ptr);
+ if (rc != SQLITE_OK) {
+ return -1;
}
- return new_DB(db);
+ return 0;
}
void init_make_tables(DB *db) {