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) (unidiff)
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) (ignore 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
@@ -29,16 +29,17 @@ struct vmod_mysql_data
29 29
30 30
31static void 31static void
32check_errno(struct dbrw_connection *conn) 32check_errno(struct dbrw_connection *conn, char const *query)
33{ 33{
34 struct vmod_mysql_data *mp = conn->data; 34 struct vmod_mysql_data *mp = conn->data;
35 35
36 dbrw_error("query failed: %s", query);
37 dbrw_error("%s", mysql_error(&mp->mysql));
36 switch (mysql_errno(&mp->mysql)) { 38 switch (mysql_errno(&mp->mysql)) {
37 case CR_SERVER_GONE_ERROR: 39 case CR_SERVER_GONE_ERROR:
38 case CR_SERVER_LOST: 40 case CR_SERVER_LOST:
39 case ER_SERVER_SHUTDOWN: 41 case ER_SERVER_SHUTDOWN:
40 case ER_ABORTING_CONNECTION: 42 case ER_ABORTING_CONNECTION:
41 dbrw_error("query failed: %s", mysql_error(&mp->mysql));
42 sql_disconnect(conn); 43 sql_disconnect(conn);
43 if (conn->state == state_error) { 44 if (conn->state == state_error) {
44 conn->state = state_disabled; 45 conn->state = state_disabled;
@@ -53,18 +54,17 @@ check_errno(struct dbrw_connection *conn)
53 case ER_BAD_HOST_ERROR: 54 case ER_BAD_HOST_ERROR:
54 case ER_BAD_TABLE_ERROR: 55 case ER_BAD_TABLE_ERROR:
55 case ER_WRONG_FIELD_SPEC: 56 case ER_WRONG_FIELD_SPEC:
56 case ER_PARSE_ERROR:
57 case ER_EMPTY_QUERY:
58 case ER_FIELD_SPECIFIED_TWICE: 57 case ER_FIELD_SPECIFIED_TWICE:
59 case ER_NO_SUCH_TABLE: 58 case ER_NO_SUCH_TABLE:
60 case ER_NOT_ALLOWED_COMMAND: 59 case ER_NOT_ALLOWED_COMMAND:
61 dbrw_error("query failed: %s", mysql_error(&mp->mysql));
62 dbrw_error("disabling MySQL connection"); 60 dbrw_error("disabling MySQL connection");
63 sql_disconnect(conn); 61 sql_disconnect(conn);
64 conn->state = state_disabled; 62 conn->state = state_disabled;
65 break; 63 break;
64 case ER_EMPTY_QUERY:
65 case ER_PARSE_ERROR:
66 default: 66 default:
67 dbrw_error("query failed: %s", mysql_error(&mp->mysql)); 67 break;
68 } 68 }
69} 69}
70 70
@@ -160,7 +160,7 @@ s_mysql_query(struct dbrw_connection *conn, const char *query)
160 for (i = 0; i < 10; i++) { 160 for (i = 0; i < 10; i++) {
161 rc = mysql_query(&mp->mysql, query); 161 rc = mysql_query(&mp->mysql, query);
162 if (rc) { 162 if (rc) {
163 check_errno(conn); 163 check_errno(conn, query);
164 if (conn->state != state_init) 164 if (conn->state != state_init)
165 return -1; 165 return -1;
166 sql_connect(conn); 166 sql_connect(conn);

Return to:

Send suggestions and report system problems to the System administrator.