Permalink
Browse files

now we always set names "utf8" for every connection.

  • Loading branch information...
1 parent a00a637 commit 68dcfef195d5d976d1ef1166cf2f7a698deacbc1 @agentzh agentzh committed Oct 19, 2010
@@ -13,7 +13,7 @@
#endif
#define ngx_http_drizzle_module_version 11
-#define ngx_http_drizzle_module_version_string "0.0.11"
+#define ngx_http_drizzle_module_version_string "0.0.14"
extern ngx_module_t ngx_http_drizzle_module;
@@ -54,10 +54,36 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,
size_t size;
uint16_t errstr_len;
uint16_t col_count;
+ uint16_t errcode;
unsigned last_buf;
ngx_http_upstream_drizzle_peer_data_t *dp = u->peer.data;
+ dd("enter output header XXX");
+
+ errcode = drizzle_result_error_code(res);
+ if (! dp->has_set_names) {
+ if (errcode != 0) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "drizzle: FATAL: failed to set names 'utf8' (error %d)", (int) errcode);
+ return NGX_ERROR;
+ }
+
+ if (dp->drizzle_con && dp->drizzle_res.con) {
+ dd("before drizzle result free");
+
+ dd("%p vs. %p", dp->drizzle_res.con, dp->drizzle_con);
+
+ drizzle_result_free(&dp->drizzle_res);
+
+ dd("after drizzle result free");
+ }
+
+ /* ngx_http_upstream_drizzle_done(r, u, dp, NGX_OK); */
+ dd("returning DONE when set names");
+ return NGX_DONE;
+ }
+
errstr = drizzle_result_error(res);
errstr_len = (uint16_t) strlen(errstr);
@@ -102,7 +128,7 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,
/* standard error code
* FIXME: define the standard error code set and map
* libdrizzle's to it. */
- *(uint16_t *) last = drizzle_result_error_code(res);
+ *(uint16_t *) last = errcode;
last += sizeof(uint16_t);
/* driver-specific error code */
@@ -137,6 +163,8 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,
}
if (col_count == 0) {
+ dd("Col count is ZERO");
+
/* we suppress row terminator here when there's no columns */
dp->seen_stream_end = 1;
@@ -152,7 +180,9 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,
return NGX_ERROR;
}
+ dd("about to be done...");
ngx_http_upstream_drizzle_done(r, u, dp, NGX_OK);
+ dd("i am returning DONE");
return NGX_DONE;
}
@@ -162,11 +162,21 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
ngx_http_upstream_t *u = r->upstream;
drizzle_return_t ret;
ngx_int_t rc;
+ char *query_data;
+ size_t query_len;
- dd("drizzle send query");
+ if (! dp->has_set_names) {
+ query_data = "set names 'utf8'";
+ query_len = sizeof("set names 'utf8'") - 1;
+ } else {
+ query_data = (char *) dp->query.data;
+ query_len = dp->query.len;
+ }
+
+ dd("drizzle send query: %.*s", (int) query_len, query_data);
- (void) drizzle_query(dc, &dp->drizzle_res, (const char *) dp->query.data,
- dp->query.len, &ret);
+ (void) drizzle_query(dc, &dp->drizzle_res, (const char *) query_data,
+ query_len, &ret);
if (ret == DRIZZLE_RETURN_IO_WAIT) {
@@ -201,6 +211,13 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
drizzle_error(dc->drizzle),
&u->peer.name);
+ if (! dp->has_set_names) {
+ c->log->action = "sending query to drizzle upstream";
+ dp->has_set_names = 1;
+
+ return ngx_http_upstream_drizzle_send_query(r, c, dp, dc);
+ }
+
ngx_http_upstream_drizzle_done(r, u, dp, NGX_HTTP_GONE);
return NGX_DONE;
@@ -222,13 +239,28 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
dd_drizzle_result(&dp->drizzle_res);
+ dd("after drizzle restult");
+
rc = ngx_http_drizzle_output_result_header(r, &dp->drizzle_res);
+ dd("after output result header YYY");
+
+ dd("output result header ret %d", (int) rc);
+
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}
if (rc == NGX_DONE) {
+ if (! dp->has_set_names) {
+ c->log->action = "connecting to drizzle upstream";
+ dp->has_set_names = 1;
+
+ dp->state = state_db_send_query;
+
+ return ngx_http_upstream_drizzle_send_query(r, c, dp, dc);
+ }
+
/* no data set following the header */
return rc;
}
@@ -284,6 +316,7 @@ ngx_http_upstream_drizzle_recv_cols(ngx_http_request_t *r,
if (col) {
rc = ngx_http_drizzle_output_col(r, col);
+
drizzle_column_free(col);
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
@@ -363,6 +396,13 @@ ngx_http_upstream_drizzle_recv_rows(ngx_http_request_t *r,
ngx_del_timer(c->read);
}
+ if (! dp->has_set_names) {
+ c->log->action = "sending query to drizzle upstream";
+ dp->has_set_names = 1;
+
+ return ngx_http_upstream_drizzle_send_query(r, c, dp, dc);
+ }
+
ngx_http_upstream_drizzle_done(r, u, dp, NGX_DONE);
return NGX_DONE;
}
@@ -443,8 +483,12 @@ ngx_http_upstream_drizzle_done(ngx_http_request_t *r,
{
ngx_connection_t *c;
+ dd("enter");
+
(void) ngx_http_drizzle_output_bufs(r, dp);
+ dd("after output bufs");
+
/* to persuade Maxim Dounin's ngx_http_upstream_keepalive
* module to cache the current connection */
@@ -466,6 +510,8 @@ ngx_http_upstream_drizzle_done(ngx_http_request_t *r,
/* reset the state machine */
dp->state = state_db_idle;
+ dd("about to finalize request...");
ngx_http_upstream_drizzle_finalize_request(r, u, rc);
+ dd("after finalize request...");
}
@@ -100,6 +100,8 @@ ngx_http_upstream_drizzle_finalize_request(ngx_http_request_t *r,
{
ngx_time_t *tp;
+ dd("enter");
+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);
@@ -127,9 +129,12 @@ ngx_http_upstream_drizzle_finalize_request(ngx_http_request_t *r,
}
if (u->peer.free) {
+ dd("before free peer");
u->peer.free(&u->peer, u->peer.data, 0);
+ dd("after free peer");
}
+ dd("about to free peer 2");
if (u->peer.connection) {
#if 0 /* libdrizzle doesn't support SSL, was: (NGX_HTTP_SSL) */
@@ -840,7 +840,9 @@ ngx_http_upstream_drizzle_free_connection(ngx_log_t *log,
dscf->active_conns--;
if (dc) {
+ dd("before con free");
drizzle_con_free(dc);
+ dd("after con free");
ngx_pfree(dscf->pool, dc);
}
@@ -116,6 +116,7 @@ typedef struct {
ngx_buf_t postponed;
size_t avail_out;
ngx_flag_t seen_stream_end;
+ ngx_flag_t has_set_names;
} ngx_http_upstream_drizzle_peer_data_t;

0 comments on commit 68dcfef

Please sign in to comment.