[dovecot-cvs]
dovecot/src/auth db-mysql.c, 1.7, 1.8 db-mysql.h, 1.1, 1.2
cras at dovecot.org
cras at dovecot.org
Fri Jul 23 21:50:20 EEST 2004
Update of /home/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv14033
Modified Files:
db-mysql.c db-mysql.h
Log Message:
db_port and db_client_flags weren't integers. Reconnects now immediately if
mysql_query() failed because connection was lost.
Index: db-mysql.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/db-mysql.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- db-mysql.c 23 Jul 2004 03:23:18 -0000 1.7
+++ db-mysql.c 23 Jul 2004 18:50:18 -0000 1.8
@@ -4,7 +4,6 @@
#undef HAVE_CONFIG_H
#if defined(PASSDB_MYSQL) || defined(USERDB_MYSQL)
-
#include "common.h"
#include "network.h"
#include "str.h"
@@ -51,7 +50,7 @@
void db_mysql_query(struct mysql_connection *conn, const char *query,
struct mysql_request *request)
{
- MYSQL_RES *res;
+ MYSQL_RES *res = NULL;
int failed;
if (verbose_debug)
@@ -64,23 +63,38 @@
}
}
- if (mysql_query(conn->mysql, query) == 0) {
+ failed = mysql_query(conn->mysql, query) != 0;
+ if (failed) {
+ /* query failed */
+ switch (mysql_errno(conn->mysql)) {
+ case CR_SERVER_GONE_ERROR:
+ case CR_SERVER_LOST:
+ /* connection lost - try immediate reconnect */
+ if (!mysql_conn_open(conn))
+ break;
+ if (mysql_query(conn->mysql, query) == 0) {
+ failed = FALSE;
+ break;
+ }
+ /* query failed, fallback to error handler */
+ default:
+ i_error("MySQL: Error executing query \"%s\": %s",
+ query, mysql_error(conn->mysql));
+ break;
+ }
+ }
+
+ if (!failed) {
/* query succeeded */
- if ((res = mysql_store_result(conn->mysql)))
- failed = FALSE;
- else {
+ if ((res = mysql_store_result(conn->mysql)) == NULL) {
/* something went wrong on storing result */
+ failed = TRUE;
i_error("MySQL: Error retrieving results: %s",
mysql_error(conn->mysql));
}
- } else {
- /* query failed */
- i_error("MySQL: Error executing query \"%s\": %s", query,
- mysql_error(conn->mysql));
- failed = TRUE;
}
- request->callback(conn, request, failed ? NULL : res);
+ request->callback(conn, request, res);
if (!failed)
mysql_free_result(res);
i_free(request);
Index: db-mysql.h
===================================================================
RCS file: /home/cvs/dovecot/src/auth/db-mysql.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- db-mysql.h 10 May 2004 01:47:09 -0000 1.1
+++ db-mysql.h 23 Jul 2004 18:50:18 -0000 1.2
@@ -3,8 +3,10 @@
#ifdef HAVE_MYSQL_MYSQL_H
# include <mysql/mysql.h>
+# include <mysql/errmsg.h>
#else
# include <mysql.h>
+# include <errmsg.h>
#endif
struct mysql_connection;
@@ -16,12 +18,12 @@
struct mysql_settings {
const char *db_host;
- const char *db_port;
+ unsigned int db_port;
const char *db_unix_socket;
const char *db;
const char *db_user;
const char *db_passwd;
- const char *db_client_flags;
+ unsigned int db_client_flags;
const char *password_query;
const char *user_query;
const char *default_pass_scheme;
More information about the dovecot-cvs
mailing list