From 542e8395ef61f890461eaeb3bc45815d12b988c3 Mon Sep 17 00:00:00 2001 From: Bubblegumdrop Date: Thu, 11 Mar 2021 13:25:53 -0500 Subject: [PATCH] Bugs --- db.c | 7 ++++--- main.c | 11 +++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db.c b/db.c index 7bdbee3..949b635 100644 --- a/db.c +++ b/db.c @@ -106,7 +106,7 @@ int run_script(sqlite3 * db, const char *script_filename) { } int run_one(sqlite3 * db, const char *query) { - int i, rc; + int i, n, rc; sqlite3_stmt *stmt = NULL; printf("> %s\n", query); @@ -115,13 +115,14 @@ int run_one(sqlite3 * db, const char *query) { return SQLITE_ERROR; } while (SQLITE_ROW == (rc = sqlite3_step(stmt))) { - for (i = 0; i < sqlite3_column_count(stmt); ++i) { + n = sqlite3_column_count(stmt); + for (i = 0; i < n; ++i) { printf(" => "); print_col(stmt, i); puts(""); } } - if (SQLITE_DONE != (rc = sqlite3_step(stmt))) { + if (SQLITE_DONE != rc) { fprintf(stderr, errmsg_update, sqlite3_errmsg(db)); } if (SQLITE_OK != (rc = sqlite3_reset(stmt))) { diff --git a/main.c b/main.c index 6a53bfd..ac6afe6 100644 --- a/main.c +++ b/main.c @@ -149,14 +149,13 @@ int main(int argc, char **argv) { } if (NULL != db_name) { - rc = sqlite3_open(db_name, &db); - if (SQLITE_OK != rc) { - fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); - return -1; + if (SQLITE_OK == (rc = sqlite3_open(db_name, &db))) { + printf("Open database successfully: "); + sqlite_version(db); } } else { - printf("Open database successfully: "); - sqlite_version(db); + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + return -1; } run_one(db, "create table if not exists quotedb (date_added text not null, added_by text not null, channel text not null, subject text not null, words text not null)");