aboutsummaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c98
1 files changed, 12 insertions, 86 deletions
diff --git a/data.c b/data.c
index 81ee9f3..2c3f3bb 100644
--- a/data.c
+++ b/data.c
@@ -11,14 +11,20 @@ Data* new_data(const char* con) {
Data* data = (Data*)malloc(sizeof(Data));
int v = sqlite3_open(con, &(data->db));
- if (v == SQLITE_OK) {
- return data;
+ if (v != SQLITE_OK) {
+ print_result_code(v);
+ return NULL;
}
- print_result_code(v);
- return NULL;
-}
+ sqlite3_enable_load_extension(data->db, 1);
+ v = sqlite3_load_extension(data->db, "ext/libsqlite3ext", "sqlite3_spellfix_init",0);
+ if (v != SQLITE_OK) {
+ print_result_code(v);
+ return NULL;
+ }
+ return data;
+}
void free_data(Data* data) {
sqlite3_close(data->db);
@@ -103,85 +109,5 @@ LIST* data_select(Data* data) {
}
void print_result_code(int code) {
- switch(code) {
- // Primary result code
- case SQLITE_ABORT:
- printf("SQLITE_ABORT");
- break;
- case SQLITE_AUTH:
- printf("SQLITE_AUTH");
- break;
- case SQLITE_BUSY:
- printf("SQLITE_BUSY");
- break;
- case SQLITE_CANTOPEN:
- printf("SQLITE_CANTOPEN");
- break;
- case SQLITE_CONSTRAINT:
- printf("SQLITE_CONSTRAINT");
- break;
- case SQLITE_CORRUPT:
- printf("SQLITE_CORRUPT");
- break;
- case SQLITE_DONE:
- printf("SQLITE_DONE");
- break;
- case SQLITE_EMPTY:
- printf("SQLITE_EMPTY");
- break;
- case SQLITE_ERROR:
- printf("SQLITE_ERROR");
- break;
- case SQLITE_FORMAT:
- printf("SQLITE_FORMAT");
- break;
- case SQLITE_INTERNAL:
- printf("SQLITE_INTERNAL");
- break;
- case SQLITE_INTERRUPT:
- printf("SQLITE_INTERRUPT");
- break;
- case SQLITE_IOERR:
- printf("SQLITE_IOERR");
- break;
- case SQLITE_LOCKED:
- printf("SQLITE_LOCKED");
- break;
- case SQLITE_MISMATCH:
- printf("SQLITE_MISMATCH");
- break;
- case SQLITE_MISUSE:
- printf("SQLITE_MISUSE");
- break;
- case SQLITE_NOLFS:
- printf("SQLITE_NOLFS");
- break;
- case SQLITE_NOMEM:
- printf("SQLITE_NOMEM");
- break;
- case SQLITE_NOTADB:
- printf("SQLITE_NOTADB");
- break;
- case SQLITE_NOTFOUND:
- printf("SQLITE_NOTFOUND");
- break;
- case SQLITE_NOTICE:
- printf("SQLITE_NOTICE");
- break;
- case SQLITE_OK:
- printf("SQLITE_OK");
- break;
- case SQLITE_PERM:
- printf("SQLITE_PERM");
- break;
- case SQLITE_SCHEMA:
- printf("SQLITE_SCHEMA");
- break;
- case SQLITE_TOOBIG:
- printf("SQLITE_TOOBIG");
- break;
- case SQLITE_WARNING:
- printf("SQLITE_WARNING");
- break;
- }
+ printf(sqlite3_errstr(code));
}