summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-09-13 10:56:32 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-09-13 11:03:14 (GMT)
commit0b7dd9ce3d77e4d99de006f3a3a86134e2d7f809 (patch) (side-by-side diff)
tree69bf78aaa7dc871c6efdb755b7aae2da6d69e7ce
parent3b6a737cd2fb7a523dd63109f86c88b2996cdc3a (diff)
downloadvmod-dbrw-0b7dd9ce3d77e4d99de006f3a3a86134e2d7f809.tar.gz
vmod-dbrw-0b7dd9ce3d77e4d99de006f3a3a86134e2d7f809.tar.bz2
Bugfixes.
* src/mysql.c (check_errno): Improve diagnostics. (s_mysql_query): Set state depending on the result of the operation and on whether it is supposed to return tuples. * src/pgsql.c (s_pgsql_query): Likewise. * src/sql.c (sql_query): Backend is responsible for switching states. * src/vmod_dbrw.c (vmod_config): Don't call atoi with NULL argument.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/mysql.c18
-rw-r--r--src/pgsql.c37
-rw-r--r--src/sql.c4
-rw-r--r--src/vmod_dbrw.c2
4 files changed, 34 insertions, 27 deletions
diff --git a/src/mysql.c b/src/mysql.c
index c777ac6..acef21c 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -38,11 +38,11 @@ check_errno(struct dbrw_connection *conn)
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;
- syslog(LOG_DAEMON|LOG_NOTICE,
- "disabling MySQL connection");
+ dbrw_error("disabling MySQL connection");
}
break;
case ER_UNKNOWN_COM_ERROR:
@@ -58,9 +58,10 @@ check_errno(struct dbrw_connection *conn)
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;
- syslog(LOG_DAEMON|LOG_NOTICE, "disabling MySQL connection");
}
}
@@ -173,12 +174,17 @@ s_mysql_query(struct dbrw_connection *conn, const char *query)
return -1;
continue;
}
- if (!(mp->result = mysql_store_result(mp->mysql))) {
+ mp->result = mysql_store_result(mp->mysql);
+ if (mp->result) {
+ conn->state = state_result;
+ rc = 0;
+ } else if (mysql_field_count(mp->mysql)) {
dbrw_error("cannot store result: %s",
- mysql_error (mp->mysql));
+ mysql_error(mp->mysql));
conn->state = state_error;
rc = 1;
- }
+ } else
+ rc = 0;
break;
}
return rc;
diff --git a/src/pgsql.c b/src/pgsql.c
index 4e3642e..d06f243 100644
--- a/src/pgsql.c
+++ b/src/pgsql.c
@@ -92,23 +92,26 @@ s_pgsql_disconnect(struct dbrw_connection *conn)
static int
s_pgsql_query(struct dbrw_connection *conn, const char *query)
{
- struct vmod_pgsql_data *dp = conn->data;
- ExecStatusType stat;
-
- dp->res = PQexec(dp->pgconn, query);
- stat = PQresultStatus(dp->res);
-
- if (stat != PGRES_COMMAND_OK && stat != PGRES_TUPLES_OK) {
- dbrw_error("query failed: %s", PQerrorMessage(dp->pgconn));
- dbrw_error("the failed query was: %s", query);
- if (dp->res) {
- PQclear(dp->res);
- dp->res = NULL;
- }
- return 1;
- }
-
- return 0;
+ struct vmod_pgsql_data *dp = conn->data;
+ ExecStatusType stat;
+
+ dp->res = PQexec(dp->pgconn, query);
+ stat = PQresultStatus(dp->res);
+
+ if (stat == PGRES_TUPLES_OK)
+ conn->state = state_result;
+ else if (stat != PGRES_COMMAND_OK) {
+ dbrw_error("query failed: %s", PQerrorMessage(dp->pgconn));
+ dbrw_error("the failed query was: %s", query);
+ if (dp->res) {
+ PQclear(dp->res);
+ dp->res = NULL;
+ }
+ PQfinish(dp->pgconn);
+ conn->state = state_disabled;
+ return 1;
+ }
+ return 0;
}
static int
diff --git a/src/sql.c b/src/sql.c
index 3a6cbe4..f56ec13 100644
--- a/src/sql.c
+++ b/src/sql.c
@@ -143,10 +143,8 @@ sql_query(struct dbrw_connection *conn, const char *input)
return 1;
}
} while (conn->state != state_connected);
- if (conn->conf->backend->sql_query(conn, input) == 0) {
- conn->state = state_result;
+ if (conn->conf->backend->sql_query(conn, input) == 0)
return 0;
- }
return 1;
}
diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c
index 4085157..f7723a2 100644
--- a/src/vmod_dbrw.c
+++ b/src/vmod_dbrw.c
@@ -244,7 +244,7 @@ vmod_config(struct sess *sp, struct vmod_priv *priv, const char *bkname,
}
s = findparam(conf->param, "debug");
- conf->debug_level = atoi(s);
+ conf->debug_level = s ? atoi(s) : 0;
conf->qdisp = QDISP_NONE;
conf->regflags = REG_EXTENDED;

Return to:

Send suggestions and report system problems to the System administrator.