/* */ #include /* assert */ #include #include /* size_t */ #include /* malloc */ #include /* strdup */ /* TODO: libircclient for basic IRC functionality. * Perhaps a database backend and a client frontend that's separate. */ #ifndef UNUSED #define UNUSED(x) (void)(x) #endif #include "io.c" static int callback(void *NotUsed, int argc, char **argv, char **azColName) { int i; UNUSED(NotUsed); for (i = 0; i < argc; i++) { printf(" => %s = %s\n", azColName[i], (argv[i] ? argv[i] : "NULL")); } return 0; } int test_db(char *script_filename) { char *orig_statements; char *saveptr1; char *statements; char *str1, *token; char *zErrMsg; const char *db_name; int j; int rc; int nstatements; sqlite3 *db; nstatements = 0; zErrMsg = 0; orig_statements = file_read(script_filename); if (orig_statements) { statements = strndup(orig_statements, 4096); } else { fprintf(stderr, "Error reading file: %s\n", script_filename); return -1; } db_name = "familyGuy.db"; rc = sqlite3_open(db_name, &db); if (rc) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); } else { fprintf(stderr, "Open database successfully\n"); } for (j = 1, str1 = statements;; j++, str1 = NULL) { token = strtok_r(str1, "\n", &saveptr1); if (token == NULL) break; printf("%d: %s\n", j, token); rc = sqlite3_exec(db, token, callback, 0, &zErrMsg); if (rc != SQLITE_OK) { fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); sqlite3_free(zErrMsg); break; } nstatements++; /* Number of successfully executed statements */ } free(orig_statements); free(statements); sqlite3_close(db); fprintf(stderr, "Bye!\n"); return 0; } #ifdef TEST_DB int main(int argc, char **argv) { char *script_filename; if (argc > 1) { script_filename = argv[1]; } else { fprintf(stderr, "Usage: %s