|
Lines 1-154
Link Here
|
| 1 |
--- a/src/charset.c 23 Jun 2005 22:39:55 -0000 1.32 |
|
|
| 2 |
+++ b/src/charset.c 4 Jul 2005 18:41:20 -0000 1.33 |
| 3 |
@@ -25,7 +25,9 @@ |
| 4 |
|
| 5 |
#include "charset.h" |
| 6 |
#include "convert_charset.h" |
| 7 |
+#ifndef DISABLE_UNICODE |
| 8 |
#include "convert_unicode.h" |
| 9 |
+#endif |
| 10 |
#include "xmalloc.h" |
| 11 |
#include "xstrdup.h" |
| 12 |
|
| 13 |
--- a/src/datastore_sqlite.c 21 May 2005 03:39:21 -0000 1.38 |
| 14 |
+++ b/src/datastore_sqlite.c 10 Jul 2005 00:21:03 -0000 1.40 |
| 15 |
@@ -152,6 +152,16 @@ |
| 16 |
return rc; |
| 17 |
} |
| 18 |
|
| 19 |
+static sqlite3_stmt *sqlprep(dbh_t *dbh, const char *cmd) { |
| 20 |
+ const char *tail; /* dummy */ |
| 21 |
+ sqlite3_stmt *ptr; |
| 22 |
+ if (sqlite3_prepare(dbh->db, cmd, strlen(cmd), &ptr, &tail) != SQLITE_OK) { |
| 23 |
+ print_error(__FILE__, __LINE__, "cannot compile %s: %s\n", cmd, sqlite3_errmsg(dbh->db)); |
| 24 |
+ exit(EX_ERROR); |
| 25 |
+ } |
| 26 |
+ return ptr; |
| 27 |
+} |
| 28 |
+ |
| 29 |
/** Short trace handler function, passed to SQLite if debugging is |
| 30 |
* enabled. */ |
| 31 |
static void db_trace(void *userdata /** unused */, |
| 32 |
@@ -236,6 +246,31 @@ |
| 33 |
return 1; |
| 34 |
} |
| 35 |
|
| 36 |
+static void check_sqlite_version(void) |
| 37 |
+{ |
| 38 |
+#if SIZEOF_LONG > 4 |
| 39 |
+ unsigned int vmaj, vmin, vpl; |
| 40 |
+ int count; |
| 41 |
+ static int complained; |
| 42 |
+ const char *v; |
| 43 |
+ |
| 44 |
+ if (complained) |
| 45 |
+ return; |
| 46 |
+ complained = 1; |
| 47 |
+ v = sqlite3_libversion(); |
| 48 |
+ sscanf(v, "%u.%u.%u", &vmaj, &vmin, &vpl); |
| 49 |
+ if (vmaj > 3) return; |
| 50 |
+ if (vmaj == 3 && vmin > 2) return; |
| 51 |
+ if (vmaj == 3 && vmin == 2 && vpl >= 2) return; |
| 52 |
+ fprintf(stderr, |
| 53 |
+ "\n" |
| 54 |
+ "WARNING: sqlite %s is not supported on %u-bit machines!\n" |
| 55 |
+ "WARNING: If you see bus errors, update sqlite to 3.2.2 or newer.\n" |
| 56 |
+ "\n", |
| 57 |
+ v, SIZEOF_LONG * 8); |
| 58 |
+#endif |
| 59 |
+} |
| 60 |
+ |
| 61 |
void *db_open(void *dummyenv, bfpath *bfp, dbmode_t mode) |
| 62 |
{ |
| 63 |
int rc; |
| 64 |
@@ -244,6 +279,8 @@ |
| 65 |
|
| 66 |
(void)dummyenv; |
| 67 |
|
| 68 |
+ check_sqlite_version(); |
| 69 |
+ |
| 70 |
dbh = dbh_init(bfp); |
| 71 |
|
| 72 |
/* open database file */ |
| 73 |
@@ -320,16 +357,8 @@ |
| 74 |
* dbh->insert is not here as it's needed earlier, |
| 75 |
* so it sets itself up lazily |
| 76 |
*/ |
| 77 |
-#define PREP(cmd, ptr) \ |
| 78 |
- { const char *tail; /* dummy */ \ |
| 79 |
- if (sqlite3_prepare(dbh->db, cmd, strlen(cmd), ptr, &tail) != SQLITE_OK) { \ |
| 80 |
- print_error(__FILE__, __LINE__, "cannot compile %s: %s\n", cmd, sqlite3_errmsg(dbh->db)); \ |
| 81 |
- exit(EX_ERROR); \ |
| 82 |
- } \ |
| 83 |
- } |
| 84 |
- |
| 85 |
- PREP("SELECT value FROM bogofilter WHERE key=? LIMIT 1;", &dbh->select); |
| 86 |
- PREP("DELETE FROM bogofilter WHERE(key = ?);", &dbh->delete); |
| 87 |
+ dbh->select = sqlprep(dbh, "SELECT value FROM bogofilter WHERE key=? LIMIT 1;"); |
| 88 |
+ dbh->delete = sqlprep(dbh, "DELETE FROM bogofilter WHERE(key = ?);"); |
| 89 |
|
| 90 |
/* check if byteswapped */ |
| 91 |
{ |
| 92 |
@@ -398,7 +427,7 @@ |
| 93 |
static char buf[80]; |
| 94 |
|
| 95 |
if (!buf[0]) |
| 96 |
- snprintf(buf, sizeof(buf), "SQLite %s", sqlite3_version); |
| 97 |
+ snprintf(buf, sizeof(buf), "SQLite %s", sqlite3_libversion()); |
| 98 |
return buf; |
| 99 |
} |
| 100 |
|
| 101 |
@@ -426,8 +455,8 @@ |
| 102 |
dbh_t *dbh, /**< database handle */ |
| 103 |
const char *func, /**< function name to report in errors */ |
| 104 |
sqlite3_stmt *stmt, /**< SQLite3 statement to execute/reset */ |
| 105 |
- int retnotfound, /**< return value if no rows found */ |
| 106 |
- dbv_t *val /** OUT value from first row, NULL ok */ |
| 107 |
+ dbv_t *val, /**< OUT value from first row, NULL ok */ |
| 108 |
+ int retnotfound /** return value if no rows found */ |
| 109 |
) |
| 110 |
{ |
| 111 |
int rc; |
| 112 |
@@ -468,25 +497,25 @@ |
| 113 |
dbh_t *dbh = vhandle; |
| 114 |
|
| 115 |
sqlite3_bind_blob(dbh->delete, 1, key->data, key->leng, SQLITE_STATIC); |
| 116 |
- return sql_fastpath(dbh, "db_delete", dbh->delete, 0, NULL); |
| 117 |
+ return sql_fastpath(dbh, "db_delete", dbh->delete, NULL, 0); |
| 118 |
} |
| 119 |
|
| 120 |
int db_set_dbvalue(void *vhandle, const dbv_t *key, const dbv_t *val) { |
| 121 |
dbh_t *dbh = vhandle; |
| 122 |
|
| 123 |
if (!dbh->insert) |
| 124 |
- PREP("INSERT OR REPLACE INTO bogofilter VALUES(?,?);", &dbh->insert); |
| 125 |
+ dbh->insert = sqlprep(dbh, "INSERT OR REPLACE INTO bogofilter VALUES(?,?);"); |
| 126 |
|
| 127 |
sqlite3_bind_blob(dbh->insert, 1, key->data, key->leng, SQLITE_STATIC); |
| 128 |
sqlite3_bind_blob(dbh->insert, 2, val->data, val->leng, SQLITE_STATIC); |
| 129 |
- return sql_fastpath(dbh, "db_set_dbvalue", dbh->insert, 0, NULL); |
| 130 |
+ return sql_fastpath(dbh, "db_set_dbvalue", dbh->insert, NULL, 0); |
| 131 |
} |
| 132 |
|
| 133 |
int db_get_dbvalue(void *vhandle, const dbv_t* key, /*@out@*/ dbv_t *val) { |
| 134 |
dbh_t *dbh = vhandle; |
| 135 |
|
| 136 |
sqlite3_bind_blob(dbh->select, 1, key->data, key->leng, SQLITE_STATIC); |
| 137 |
- return sql_fastpath(dbh, "db_get_dbvalue", dbh->select, DS_NOTFOUND, val); |
| 138 |
+ return sql_fastpath(dbh, "db_get_dbvalue", dbh->select, val, DS_NOTFOUND); |
| 139 |
} |
| 140 |
|
| 141 |
ex_t db_foreach(void *vhandle, db_foreach_t hook, void *userdata) { |
| 142 |
--- a/src/maint.c 25 Jun 2005 16:42:44 -0000 1.64 |
| 143 |
+++ b/src/maint.c 4 Jul 2005 18:41:20 -0000 1.65 |
| 144 |
@@ -19,8 +19,10 @@ |
| 145 |
#include "datastore.h" |
| 146 |
#include "error.h" |
| 147 |
#include "charset.h" |
| 148 |
+#ifndef DISABLE_UNICODE |
| 149 |
#include "convert_unicode.h" |
| 150 |
#include "iconvert.h" |
| 151 |
+#endif |
| 152 |
#include "maint.h" |
| 153 |
#include "transaction.h" |
| 154 |
#include "wordlists.h" |