This commit is contained in:
Bubblegumdrop 2021-03-11 13:25:53 -05:00
parent 823330dde9
commit 542e8395ef
2 changed files with 9 additions and 9 deletions

7
db.c
View File

@ -106,7 +106,7 @@ int run_script(sqlite3 * db, const char *script_filename) {
} }
int run_one(sqlite3 * db, const char *query) { int run_one(sqlite3 * db, const char *query) {
int i, rc; int i, n, rc;
sqlite3_stmt *stmt = NULL; sqlite3_stmt *stmt = NULL;
printf("> %s\n", query); printf("> %s\n", query);
@ -115,13 +115,14 @@ int run_one(sqlite3 * db, const char *query) {
return SQLITE_ERROR; return SQLITE_ERROR;
} }
while (SQLITE_ROW == (rc = sqlite3_step(stmt))) { 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(" => "); printf(" => ");
print_col(stmt, i); print_col(stmt, i);
puts(""); puts("");
} }
} }
if (SQLITE_DONE != (rc = sqlite3_step(stmt))) { if (SQLITE_DONE != rc) {
fprintf(stderr, errmsg_update, sqlite3_errmsg(db)); fprintf(stderr, errmsg_update, sqlite3_errmsg(db));
} }
if (SQLITE_OK != (rc = sqlite3_reset(stmt))) { if (SQLITE_OK != (rc = sqlite3_reset(stmt))) {

11
main.c
View File

@ -149,14 +149,13 @@ int main(int argc, char **argv) {
} }
if (NULL != db_name) { if (NULL != db_name) {
rc = sqlite3_open(db_name, &db); if (SQLITE_OK == (rc = sqlite3_open(db_name, &db))) {
if (SQLITE_OK != rc) { printf("Open database successfully: ");
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); sqlite_version(db);
return -1;
} }
} else { } else {
printf("Open database successfully: "); fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite_version(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)"); 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)");