summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-02-15 08:49:14 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-02-15 08:51:50 (GMT)
commitd10bd129fc392283b60db2f0ef426f4e16ffd8bf (patch) (side-by-side diff)
treea354a8aac47213ed141a86923ad7cc90a0537fef
parent49ab7b5fa7843a77605b91adf8a3689794fc091a (diff)
downloadvmod-dbrw-d10bd129fc392283b60db2f0ef426f4e16ffd8bf.tar.gz
vmod-dbrw-d10bd129fc392283b60db2f0ef426f4e16ffd8bf.tar.bz2
Improve error handling in mysql.c
* src/mysql.c (check_errno): Always print the failed query in full. Don't treat ER_PARSE_ERROR and ER_EMPTY_QUERY as fatal errors.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--src/mysql.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/mysql.c b/src/mysql.c
index d97200a..1391743d 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -26,22 +26,23 @@ struct vmod_mysql_data
char *buffer;
size_t bufsize;
};
static void
-check_errno(struct dbrw_connection *conn)
+check_errno(struct dbrw_connection *conn, char const *query)
{
struct vmod_mysql_data *mp = conn->data;
+ dbrw_error("query failed: %s", query);
+ dbrw_error("%s", mysql_error(&mp->mysql));
switch (mysql_errno(&mp->mysql)) {
case CR_SERVER_GONE_ERROR:
case CR_SERVER_LOST:
case ER_SERVER_SHUTDOWN:
case ER_ABORTING_CONNECTION:
- dbrw_error("query failed: %s", mysql_error(&mp->mysql));
sql_disconnect(conn);
if (conn->state == state_error) {
conn->state = state_disabled;
dbrw_error("disabling MySQL connection");
}
break;
@@ -50,24 +51,23 @@ check_errno(struct dbrw_connection *conn)
case ER_BAD_DB_ERROR:
case ER_WRONG_DB_NAME:
case ER_BAD_FIELD_ERROR:
case ER_BAD_HOST_ERROR:
case ER_BAD_TABLE_ERROR:
case ER_WRONG_FIELD_SPEC:
- case ER_PARSE_ERROR:
- case ER_EMPTY_QUERY:
case ER_FIELD_SPECIFIED_TWICE:
case ER_NO_SUCH_TABLE:
case ER_NOT_ALLOWED_COMMAND:
- dbrw_error("query failed: %s", mysql_error(&mp->mysql));
dbrw_error("disabling MySQL connection");
sql_disconnect(conn);
conn->state = state_disabled;
break;
+ case ER_EMPTY_QUERY:
+ case ER_PARSE_ERROR:
default:
- dbrw_error("query failed: %s", mysql_error(&mp->mysql));
+ break;
}
}
/* ************************************************************************* */
/* Interface routines */
@@ -157,13 +157,13 @@ s_mysql_query(struct dbrw_connection *conn, const char *query)
int i;
MYSQL *mysql;
for (i = 0; i < 10; i++) {
rc = mysql_query(&mp->mysql, query);
if (rc) {
- check_errno(conn);
+ check_errno(conn, query);
if (conn->state != state_init)
return -1;
sql_connect(conn);
if (conn->state != state_connected)
return -1;
continue;

Return to:

Send suggestions and report system problems to the System administrator.