diff -urN dspam-3.6.3.org/src/mysql_drv.c dspam-3.6.3/src/mysql_drv.c
--- dspam-3.6.3.org/src/mysql_drv.c 2006-01-18 17:48:53.000000000 +0100
-+++ dspam-3.6.3/src/mysql_drv.c 2006-02-01 21:09:20.000000000 +0100
-@@ -84,6 +84,7 @@
++++ dspam-3.6.3/src/mysql_drv.c 2006-02-01 21:46:52.000000000 +0100
+@@ -67,6 +67,8 @@
+ #include "config_shared.h"
+ #endif
+
++static int use_mysql40 = 0;
++
+ int test(MYSQL *, char *);
+
+ int test(MYSQL *dbh, char *query) {
+@@ -80,10 +82,20 @@
+ int
+ dspam_init_driver (DRIVER_CTX *DTX)
+ {
++
+ #if defined(MYSQL4_INITIALIZATION) && MYSQL_VERSION_ID >= 40001
const char *server_default_groups[]=
{ "server", "embedded", "mysql_SERVER", 0 };
++#endif
++
++ if (DTX == NULL)
++ return 0;
++
++#if defined(MYSQL4_INITIALIZATION) && MYSQL_VERSION_ID >= 40001
++ if (_ds_match_attribute(DTX->CTX->config->attributes, "MySQLVersion40", "on"))
++ use_mysql40 = 1;
-+ if (_ds_match_attribute(DTX->CTX->config->attributes, "MySQLVersion4", "on"))
++ if (!use_mysql40)
if (mysql_server_init(0, NULL, (char**) server_default_groups)) {
LOGDEBUG("dspam_init_driver() failed");
return EFAILURE;
-@@ -148,6 +149,7 @@
+@@ -148,6 +160,7 @@
}
#if defined(MYSQL4_INITIALIZATION) && MYSQL_VERSION_ID >= 40001
-+ if (_ds_match_attribute(DTX->CTX->config->attributes, "MySQLVersion4", "on"))
++ if (!use_mysql40)
mysql_server_end();
#endif
return 0;
-@@ -610,6 +612,7 @@
+@@ -610,6 +623,7 @@
}
#if MYSQL_VERSION_ID >= 40100
-+ if (_ds_match_attribute(CTX->config->attributes, "MySQLVersion4", "on")) {
++ if (!use_mysql40) {
insert = buffer_create(NULL);
if (insert == NULL)
{
-@@ -617,6 +620,7 @@
+@@ -617,6 +631,7 @@
LOG (LOG_CRIT, ERR_MEM_ALLOC);
return EUNKNOWN;
}
#endif
ds_diction_getstat(diction, s->control_token, &control);
-@@ -633,6 +637,7 @@
+@@ -633,6 +648,7 @@
buffer_cat (query, scratch);
#if MYSQL_VERSION_ID >= 40100
-+ if (_ds_match_attribute(CTX->config->attributes, "MySQLVersion4", "on"))
++ if (!use_mysql40)
buffer_copy (insert, "insert into dspam_token_data(uid, token, spam_hits, "
"innocent_hits, last_hit) values");
#endif
-@@ -679,6 +684,7 @@
+@@ -679,6 +695,7 @@
{
char ins[1024];
#if MYSQL_VERSION_ID >= 40100
-+ if (_ds_match_attribute(CTX->config->attributes, "MySQLVersion4", "on")) {
++ if (!use_mysql40) {
snprintf (ins, sizeof (ins),
"%s(%d, '%llu', %d, %d, current_date())",
(insert_any) ? ", " : "",
-@@ -689,6 +695,7 @@
+@@ -689,7 +706,8 @@
insert_any = 1;
buffer_cat(insert, ins);
+-#else
+ } else {
- #else
++#endif
snprintf(ins, sizeof (ins),
"insert into dspam_token_data(uid, token, spam_hits, "
-@@ -702,6 +709,9 @@
+ "innocent_hits, last_hit) values(%d, '%llu', %d, %d, "
+@@ -701,6 +719,8 @@
+
if (MYSQL_RUN_QUERY (s->dbh, ins))
stat.status |= TST_DISK;
- #endif
+#if MYSQL_VERSION_ID >= 40100
+ }
-+#endif
+ #endif
}
- if (stat.status & TST_DISK) {
-@@ -749,6 +759,7 @@
+@@ -749,6 +769,7 @@
}
#if MYSQL_VERSION_ID >= 40100
-+ if (_ds_match_attribute(CTX->config->attributes, "MySQLVersion4", "on"))
++ if (!use_mysql40) {
if (insert_any)
{
snprintf (scratch, sizeof (scratch),
+@@ -770,6 +791,7 @@
+ }
+
+ buffer_destroy(insert);
++ }
+ #endif
+
+ buffer_destroy (query);
+@@ -2701,6 +2723,9 @@
+ char db[64] = { 0 };
+ int port = 3306, i = 0, real_connect_flag = 0;
+
++ if (_ds_match_attribute(CTX->config->attributes, "MySQLVersion40", "on"))
++ use_mysql40 = 1;
++
+ /* Read storage attributes */
+ if (_ds_read_attribute(CTX->config->attributes, "MySQLServer")) {
+ char *p;