diff options
Diffstat (limited to 'cd.c')
-rw-r--r-- | cd.c | 34 |
1 files changed, 7 insertions, 27 deletions
@@ -33,35 +33,23 @@ int main(int argc, char* argv[]) { /* Connect to db */ sqlite3 *db; - int rc = sqlite3_open(file, &db); - if (rc) { - fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); - abort(); - } + sqlite3_open(file, &db); /* Get number of cards */ sqlite3_stmt *stmt; - rc = sqlite3_prepare_v3(db, "SELECT COUNT(*) FROM cards", -1, 0, &stmt, NULL); - if (rc) { - fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); - abort(); - } + sqlite3_prepare_v3(db, "SELECT COUNT(*) FROM cards", -1, 0, &stmt, NULL); sqlite3_step(stmt); int N = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); /* Get card weights */ - rc = sqlite3_prepare_v3(db, "SELECT weight FROM cards", -1, 0, &stmt, NULL); - if (rc) { - fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); - abort(); - } - seg = malloc(4 * N * sizeof(int)); + sqlite3_prepare_v3(db, "SELECT weight FROM cards", -1, 0, &stmt, NULL); + seg = (int*)malloc(4 * N * sizeof(int)); build(stmt, 0, N - 1, 1); sqlite3_finalize(stmt); if (verbose) { - for (int i = 0; i < N; i++) { + for (int i = 0; i < 4 * N; i++) { printf("%d ", seg[i]); } printf("\n"); @@ -82,11 +70,7 @@ int main(int argc, char* argv[]) { } /* Get card contents from database */ - rc = sqlite3_prepare_v3(db, "SELECT key, val FROM cards WHERE idx=?", -1, 0, &stmt, NULL); - if (rc) { - fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); - abort(); - } + sqlite3_prepare_v3(db, "SELECT key, val FROM cards WHERE idx=?", -1, 0, &stmt, NULL); sqlite3_bind_int(stmt, 1, i); sqlite3_step(stmt); char *key, *val; @@ -114,11 +98,7 @@ int main(int argc, char* argv[]) { /* Update segment tree and database */ update(i, w, 0, N - 1, 1); - rc = sqlite3_prepare_v3(db, "UPDATE cards SET weight=? WHERE idx=?", -1, 0, &stmt, NULL); - if (rc) { - fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); - abort(); - } + sqlite3_prepare_v3(db, "UPDATE cards SET weight=? WHERE idx=?", -1, 0, &stmt, NULL); sqlite3_bind_int(stmt, 1, w); sqlite3_bind_int(stmt, 2, i); sqlite3_step(stmt); |