From b95cdd56c2124f7545898e194ee8ad740b161678 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 19 Apr 2022 13:04:37 -0500 Subject: Actually modify db --- cd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cd.c b/cd.c index 7d0cb0b..9b87512 100644 --- a/cd.c +++ b/cd.c @@ -42,7 +42,7 @@ int main(int argc, char* argv[]) { /* Get number of cards */ sqlite3_stmt *stmt; rc = sqlite3_prepare_v3(db, "SELECT COUNT(*) FROM cards", -1, 0, &stmt, NULL); - if (rc != SQLITE_OK) { + if (rc) { fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); abort(); } @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) { /* Get card weights */ rc = sqlite3_prepare_v3(db, "SELECT weight FROM cards", -1, 0, &stmt, NULL); - if (rc != SQLITE_OK) { + if (rc) { fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); abort(); } @@ -83,7 +83,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 != SQLITE_OK) { + if (rc) { fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); abort(); } @@ -115,12 +115,13 @@ 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 != SQLITE_OK) { + if (rc) { fprintf(stderr, "Database error: %s\n", sqlite3_errmsg(db)); abort(); } sqlite3_bind_int(stmt, 1, w); sqlite3_bind_int(stmt, 2, i); + sqlite3_step(stmt); sqlite3_finalize(stmt); } -- cgit v1.2.3-70-g09d2