Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now we introduced the charset option for the "drizzle_server" diredct…

…ive which causes ngx_drizzle send "set names xxx" automatcially for every connection to that drizzle server.
  • Loading branch information...
commit fef1ffdf6b7824e82b97fcdbcad6906750007dc6 1 parent 30b7467
Yichun Zhang agentzh authored
2  src/ngx_http_drizzle_keepalive.h
View
@@ -17,7 +17,7 @@ typedef struct {
struct sockaddr_storage sockaddr;
drizzle_con_st *drizzle_con;
ngx_str_t name;
- ngx_flag_t has_set_names;
+ ngx_flag_t has_set_names:1;
} ngx_http_drizzle_keepalive_cache_t;
3  src/ngx_http_drizzle_output.c
View
@@ -62,7 +62,8 @@ ngx_http_drizzle_output_result_header(ngx_http_request_t *r,
dd("enter output header XXX");
errcode = drizzle_result_error_code(res);
- if (! dp->has_set_names) {
+
+ if (dp->enable_charset && ! 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);
27 src/ngx_http_drizzle_processor.c
View
@@ -161,15 +161,19 @@ 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;
+ u_char *query_data;
size_t query_len;
- ngx_flag_t has_set_names;
+ ngx_flag_t has_set_names = 0;
+ ngx_flag_t enable_charset = 0;
+
+ dd("enable charset: %d", (int) dp->enable_charset);
+
+ if (dp->enable_charset && ! dp->has_set_names) {
+ query_len = dp->set_names_query->len;
+ query_data = dp->set_names_query->data;
- 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_data = dp->query.data;
query_len = dp->query.len;
}
@@ -208,7 +212,7 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
(int) ret, drizzle_error_code(dc->drizzle),
drizzle_error(dc->drizzle));
- if (! dp->has_set_names) {
+ if (dp->enable_charset && ! dp->has_set_names) {
c->log->action = "sending query to drizzle upstream";
dp->has_set_names = 1;
@@ -236,7 +240,12 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
dd("after drizzle restult");
+ if (dp->enable_charset) {
+ enable_charset = 1;
+ }
+
has_set_names = dp->has_set_names;
+
rc = ngx_http_drizzle_output_result_header(r, &dp->drizzle_res);
dd("after output result header YYY");
@@ -248,7 +257,7 @@ ngx_http_upstream_drizzle_send_query(ngx_http_request_t *r,
}
if (rc == NGX_DONE) {
- if (! has_set_names) {
+ if (enable_charset && ! has_set_names) {
c->log->action = "sending query to drizzle upstream";
dp->has_set_names = 1;
@@ -387,7 +396,7 @@ ngx_http_upstream_drizzle_recv_rows(ngx_http_request_t *r,
ngx_del_timer(c->read);
}
- if (! dp->has_set_names) {
+ if (dp->enable_charset && ! dp->has_set_names) {
c->log->action = "sending query to drizzle upstream";
dp->has_set_names = 1;
55 src/ngx_http_upstream_drizzle.c
View
@@ -84,9 +84,12 @@ ngx_http_upstream_drizzle_server(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_upstream_drizzle_server_t *ds;
ngx_str_t *value;
ngx_url_t u;
- ngx_uint_t i;
+ ngx_uint_t i, j;
ngx_http_upstream_srv_conf_t *uscf;
ngx_str_t protocol;
+ ngx_str_t charset;
+ u_char *p;
+ size_t len;
dd("entered drizzle_server directive handler...");
@@ -231,8 +234,49 @@ ngx_http_upstream_drizzle_server(ngx_conf_t *cf, ngx_command_t *cmd,
continue;
}
+ if (ngx_strncmp(value[i].data, "charset=", sizeof("charset=") - 1)
+ == 0)
+ {
+ charset.len = value[i].len - (sizeof("charset=") - 1);
+ charset.data = &value[i].data[sizeof("charset=") - 1];
+
+ dd("charset: %.*s", (int) charset.len, charset.data);
+
+ if (charset.len == 0) {
+ continue;
+ }
+
+ for (j = 0; j < charset.len; j++) {
+ if (charset.data[j] == '\'') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "bad charste value \"%V\" in"
+ " drizzle_server", &charset);
+
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ len = sizeof("set names ''") - 1 + charset.len;
+
+ p = ngx_palloc(cf->pool, len);
+ if (p == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ ds->set_names_query.data = p;
+ ds->set_names_query.len = len;
+
+ dd("charset query len: %d", (int) len);
+
+ p = ngx_copy(p, "set names '", sizeof("set names '") - 1);
+ p = ngx_copy(p, charset.data, charset.len);
+ *p = '\'';
+
+ continue;
+ }
+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "drizzle: invalid parameter \"%V\" in"
+ "invalid parameter \"%V\" in"
" drizzle_server", &value[i]);
return NGX_CONF_ERROR;
@@ -307,6 +351,7 @@ ngx_http_upstream_drizzle_init(ngx_conf_t *cf,
peers->peer[n].password = server[i].password;
peers->peer[n].dbname = server[i].dbname;
peers->peer[n].protocol = server[i].protocol;
+ peers->peer[n].set_names_query = &server[i].set_names_query;
len = NGX_SOCKADDR_STRLEN + 1 /* for '\0' */;
@@ -532,6 +577,12 @@ ngx_http_upstream_drizzle_get_peer(ngx_peer_connection_t *pc, void *data)
dp->name = &peer->name;
+ dp->enable_charset = (peer->set_names_query->len > 0);
+ dp->set_names_query = peer->set_names_query;
+
+ dd("charset query: %s", dp->set_names_query->data);
+ dd("charset query: %d", (int) dp->set_names_query->len);
+
pc->name = &peer->name;
pc->sockaddr = peer->sockaddr;
pc->socklen = peer->socklen;
11 src/ngx_http_upstream_drizzle.h
View
@@ -33,6 +33,7 @@ typedef struct {
ngx_str_t user;
ngx_str_t password;
ngx_str_t dbname;
+ ngx_str_t set_names_query;
ngx_http_upstream_drizzle_protocol_t protocol;
@@ -47,6 +48,7 @@ typedef struct {
ngx_str_t user;
ngx_str_t password;
ngx_str_t dbname;
+ ngx_str_t *set_names_query;
u_char *host;
ngx_http_upstream_drizzle_protocol_t protocol;
@@ -108,15 +110,18 @@ typedef struct {
ngx_str_t *name;
- ngx_flag_t failed;
ngx_chain_t **last_out;
ngx_buf_t *out_buf;
ngx_buf_t cached;
ngx_buf_t postponed;
size_t avail_out;
- ngx_flag_t seen_stream_end;
- ngx_flag_t has_set_names;
+ ngx_str_t charset;
+ ngx_str_t *set_names_query;
+ ngx_flag_t failed:1;
+ ngx_flag_t seen_stream_end:1;
+ ngx_flag_t has_set_names:1;
+ ngx_flag_t enable_charset:1;
} ngx_http_upstream_drizzle_peer_data_t;
2  test/t/000_init.t
View
@@ -1,4 +1,4 @@
-# vi:filetype=perl
+# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
80 test/t/charset/000_init.t
View
@@ -0,0 +1,80 @@
+# vi:filetype=
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(1);
+
+plan tests => repeat_each() * blocks();
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+our $http_config = <<'_EOC_';
+ upstream database {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=utf8;
+ }
+_EOC_
+
+worker_connections(128);
+no_shuffle();
+run_tests();
+
+no_diff();
+
+__DATA__
+
+=== TEST 1: cats - drop table
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "DROP TABLE IF EXISTS cats";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
+
+
+
+=== TEST 2: cats - create table
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "CREATE TABLE cats (id integer, name text)";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
+
+
+
+=== TEST 3: cats - insert value
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "INSERT INTO cats (id) VALUES (2)";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
+
+
+
+=== TEST 4: cats - insert value
+--- http_config eval: $::http_config
+--- config
+ location = /init {
+ drizzle_pass database;
+ drizzle_query "INSERT INTO cats (id, name) VALUES (3, 'bob')";
+ }
+--- request
+GET /init
+--- error_code: 200
+--- timeout: 10
184 test/t/charset/errors.t
View
@@ -0,0 +1,184 @@
+# vi:filetype=
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#repeat_each(2);
+repeat_each(2);
+
+plan tests => repeat_each() * blocks() + 4;
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+our $http_config = <<'_EOC_';
+ upstream foo {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=utf8;
+ }
+_EOC_
+
+worker_connections(128);
+run_tests();
+
+no_diff();
+
+__DATA__
+
+=== TEST 1: bad query
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query "update table_that_doesnt_exist set name='bob'";
+ }
+--- request
+GET /mysql
+--- error_code: 410
+--- response_body_like: 410 Gone
+--- timeout: 5
+
+
+
+=== TEST 2: wrong credentials
+little-endian systems only
+
+--- timeout: 5
+--- http_config
+ upstream foo {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT dbname=test
+ password=wrong_pass user=monty protocol=mysql
+ charset=utf8;
+ drizzle_keepalive mode=single max=2 overflow=reject;
+ }
+--- config
+ location /mysql {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- error_code: 502
+
+
+
+=== TEST 3: no database
+little-endian systems only
+
+--- http_config
+ upstream foo {
+ drizzle_server 127.0.0.1:1 dbname=test
+ password=some_pass user=monty protocol=mysql
+ charset=utf8;
+ drizzle_keepalive mode=single max=2 overflow=reject;
+ }
+--- config
+ location /mysql {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- error_code: 502
+
+
+
+=== TEST 4: multiple queries
+little-endian systems only
+
+--- timeout: 5
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query "select * from cats; select * from cats";
+ }
+--- request
+GET /mysql
+--- error_code: 500
+
+
+
+=== TEST 5: missing query
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ }
+--- request
+GET /mysql
+--- error_code: 500
+
+
+
+=== TEST 6: empty query
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ set $query "";
+ drizzle_query $query;
+ }
+--- request
+GET /mysql
+--- error_code: 500
+--- timeout: 5
+
+
+
+=== TEST 7: empty pass
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $backend "";
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- error_code: 500
+
+
+
+=== TEST 8: empty pass
+little-endian systems only
+
+--- http_config
+ upstream foo {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=blah-blah;
+ }
+
+--- config
+ location /mysql {
+ drizzle_pass foo;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- error_code: 500
+--- response_body_like: 500 Internal Server Error
+
416 test/t/charset/keepalive.t
View
@@ -0,0 +1,416 @@
+# vi:filetype=perl
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(2);
+
+plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 6;
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+our $http_config = <<'_EOC_';
+ upstream backend {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=utf8;
+ drizzle_keepalive max=10 overflow=ignore mode=single;
+ }
+_EOC_
+
+worker_connections(128);
+run_tests();
+
+no_diff();
+
+__DATA__
+
+=== TEST 1: sanity
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 2: keep-alive
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+
+
+
+=== TEST 3: update
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
+=== TEST 4: select empty result
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ drizzle_query "select * from cats where name='tom'";
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{00}" # row list terminator
+
+
+
+=== TEST 5: update & no module header
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_headers
+X-Resty-DBD-Module:
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
+=== TEST 6: variables in drizzle_pass
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $foo backend;
+ drizzle_pass $foo;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_headers
+X-Resty-DBD-Module:
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
+=== TEST 7: sanity (using little bufs, size 1)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ drizzle_buffer_size 1;
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 8: sanity (using little bufs, size 2)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ drizzle_buffer_size 2;
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 9: sanity (using little bufs, size 3)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ drizzle_buffer_size 3;
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 10: update
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
358 test/t/charset/methods.t
View
@@ -0,0 +1,358 @@
+# vi:filetype=perl
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(2);
+
+plan tests => repeat_each() * (blocks() * 3 - 2 * 2);
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+our $http_config = <<'_EOC_';
+ upstream database {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=utf8;
+ }
+_EOC_
+
+worker_connections(128);
+run_tests();
+
+no_diff();
+
+__DATA__
+
+=== TEST 1: default query
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query "select 'default' as echo";
+ }
+--- request
+GET /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{07}\x{00}\x{00}\x{00}". # field len
+"default". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 2: method-specific query
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query LOCK GET UNLOCK "select 'GET' as echo";
+ }
+--- request
+GET /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"GET". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 3: method-specific complex query (check 1)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+ }
+--- request
+GET /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"GET". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 4: method-specific complex query (check 2)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+ }
+--- request
+LOCK /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{04}\x{00}\x{00}\x{00}". # field len
+"LOCK". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 5: method-specific complex query (using not allowed method)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+ }
+--- request
+HEAD /mysql
+--- error_code: 405
+--- timeout: 10
+
+
+
+=== TEST 6: method-specific query and default query (using defined method)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query "select 'default' as echo";
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+ }
+--- request
+GET /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"GET". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 7: method-specific query and default query (using other method)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query "select 'default' as echo";
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+ }
+--- request
+POST /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{07}\x{00}\x{00}\x{00}". # field len
+"default". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 8: inheritance
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ drizzle_query "select 'default' as echo";
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+
+ location /mysql {
+ drizzle_pass database;
+ }
+--- request
+GET /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"GET". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+
+
+
+=== TEST 9: inheritance (mixed, not inherited)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ drizzle_query "select 'default' as echo";
+
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query LOCK GET UNLOCK "select '$request_method' as echo";
+ }
+--- request
+HEAD /mysql
+--- error_code: 405
+--- timeout: 10
+
+
+
+=== TEST 10: default query
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass database;
+ drizzle_query "select '$request_method' as echo";
+ }
+--- request
+PATCH /mysql
+--- error_code: 200
+--- response_headers
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}". # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{01}\x{00}". # col count
+"\x{06}\x{80}". # std col type (varchar/str)
+"\x{fd}\x{00}". # driver col type
+"\x{04}\x{00}". # col name len
+"echo". # col name data
+"\x{01}". # valid row flag
+"\x{05}\x{00}\x{00}\x{00}". # field len
+"PATCH". # field data
+"\x{00}" # row list terminator
+--- timeout: 10
+--- skip_nginx: 3: < 0.8.41
417 test/t/charset/sanity.t
View
@@ -0,0 +1,417 @@
+# vi:filetype=perl
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+repeat_each(2);
+#repeat_each(1);
+
+plan tests => repeat_each() * 2 * blocks() + 2 * repeat_each() * 6;
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+our $http_config = <<'_EOC_';
+ upstream backend {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=utf8;
+ #drizzle_keepalive max=10 overflow=ignore mode=single;
+ }
+_EOC_
+
+worker_connections(128);
+run_tests();
+
+no_diff();
+
+__DATA__
+
+=== TEST 1: sanity
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 2: keep-alive
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+
+
+
+=== TEST 3: update
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
+=== TEST 4: select empty result
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ drizzle_query "select * from cats where name='tom'";
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{00}" # row list terminator
+
+
+
+=== TEST 5: update & no module header
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_headers
+X-Resty-DBD-Module:
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
+=== TEST 6: variables in drizzle_pass
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ set $foo backend;
+ drizzle_pass $foo;
+ drizzle_module_header off;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_headers
+X-Resty-DBD-Module:
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
+=== TEST 7: sanity (using little bufs, size 1)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ drizzle_buffer_size 1;
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 8: sanity (using little bufs, size 2)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ drizzle_buffer_size 2;
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 9: sanity (using little bufs, size 3)
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query 'select * from cats';
+ drizzle_buffer_size 3;
+ }
+--- request
+GET /mysql
+--- response_headers_like
+X-Resty-DBD-Module: ngx_drizzle \d+\.\d+\.\d+
+Content-Type: application/x-resty-dbd-stream
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{00}\x{00}". # driver errstr len
+"". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{02}\x{00}". # col count
+"\x{09}\x{00}". # std col type (integer)
+"\x{03}\x{00}". # drizzle col type
+"\x{02}\x{00}". # col name len
+"id". # col name data
+"\x{13}\x{80}". # std col type (blob/str)
+"\x{fc}\x{00}". # drizzle col type
+"\x{04}\x{00}". # col name len
+"name". # col name data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"2". # field data
+"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
+"". # field data
+"\x{01}". # valid row flag
+"\x{01}\x{00}\x{00}\x{00}". # field len
+"3". # field data
+"\x{03}\x{00}\x{00}\x{00}". # field len
+"bob". # field data
+"\x{00}" # row list terminator
+--- timeout: 60
+
+
+
+=== TEST 10: update
+little-endian systems only
+
+--- http_config eval: $::http_config
+--- config
+ location /mysql {
+ drizzle_pass backend;
+ #drizzle_dbname $dbname;
+ drizzle_query "update cats set name='bob' where name='bob'";
+ }
+--- request
+GET /mysql
+--- response_body eval
+"\x{00}". # endian
+"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
+"\x{00}". # result type
+"\x{00}\x{00}". # std errcode
+"\x{00}\x{00}" . # driver errcode
+"\x{28}\x{00}". # driver errstr len
+"Rows matched: 1 Changed: 0 Warnings: 0". # driver errstr data
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
+"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
+"\x{00}\x{00}" # col count
+
+
+
108 test/t/charset/timeout.t
View
@@ -0,0 +1,108 @@
+# vi:ft=
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#repeat_each(2);
+repeat_each(1);
+
+plan tests => repeat_each() * blocks() * 2;
+
+our $http_config = <<'_EOC_';
+ upstream foo {
+ drizzle_server www.taobao.com:1234;
+ }
+_EOC_
+
+worker_connections(128);
+#log_level('error');
+
+$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306;
+
+no_diff();
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: loc_config connect timeout
+--- http_config eval: $::http_config
+--- config
+ location /upstream {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query 'select * from xx';
+ drizzle_connect_timeout 10ms;
+ }
+--- request
+GET /upstream
+--- error_code: 504
+--- response_body_like: 504 Gateway Time-out
+--- timeout: 0.5
+
+
+
+=== TEST 2: http_config connect timeout
+--- http_config eval: $::http_config
+--- config
+ drizzle_connect_timeout 3;
+ location /upstream {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query 'select * from xx';
+ drizzle_connect_timeout 10ms;
+ }
+--- request
+GET /upstream
+--- error_code: 504
+--- response_body_like: 504 Gateway Time-out
+--- timeout: 0.5
+
+
+
+=== TEST 3: serv_config connect timeout
+--- http_config eval: $::http_config
+--- config
+ drizzle_connect_timeout 10ms;
+ location /upstream {
+ set $backend foo;
+ drizzle_pass $backend;
+ drizzle_module_header off;
+ drizzle_query 'select * from xx';
+ }
+--- request
+GET /upstream
+--- error_code: 504
+--- response_body_like: 504 Gateway Time-out
+--- timeout: 0.5
+
+
+
+=== TEST 4: serv_config connect timeout
+--- http_config
+ upstream backend {
+ drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
+ dbname=ngx_test user=ngx_test password=ngx_test
+ charset=utf8;
+ }
+
+--- config
+ #drizzle_connect_timeout 1;
+ drizzle_send_query_timeout 10ms;
+ #drizzle_recv_cols_timeout 10ms;
+ #drizzle_recv_rows_timeout 10ms;
+
+ location /upstream {
+ drizzle_pass backend;
+ drizzle_module_header off;
+ drizzle_query 'select sql_no_cache * from cats as a, cats as b, cats as c, cats as d, cats as e, cats as f, cats as g, cats as h, cats as i, cats as j order by a.id, b.id, c.id, d.id';
+ }
+--- request
+GET /upstream
+--- error_code: 504
+--- response_body_like: 504 Gateway Time-out
+--- timeout: 1
+--- SKIP
+
7 test/t/errors.t
View
@@ -1,4 +1,4 @@
-# vi:filetype=perl
+# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
@@ -39,13 +39,14 @@ little-endian systems only
GET /mysql
--- error_code: 410
--- response_body_like: 410 Gone
---- timeout: 3
+--- timeout: 5
=== TEST 2: wrong credentials
little-endian systems only
+--- timeout: 5
--- http_config
upstream foo {
drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT dbname=test
@@ -90,6 +91,7 @@ GET /mysql
=== TEST 4: multiple queries
little-endian systems only
+--- timeout: 5
--- http_config eval: $::http_config
--- config
location /mysql {
@@ -135,6 +137,7 @@ little-endian systems only
--- request
GET /mysql
--- error_code: 500
+--- timeout: 5
3  test/t/timeout.t
View
@@ -96,11 +96,12 @@ GET /upstream
location /upstream {
drizzle_pass backend;
drizzle_module_header off;
- drizzle_query 'select sleep(2)';
+ drizzle_query 'select sql_no_cache * from cats as a, cats as b, cats as c, cats as d, cats as e, cats as f, cats as g, cats as h, cats as i, cats as j order by a.id, b.id, c.id, d.id';
}
--- request
GET /upstream
--- error_code: 504
--- response_body_like: 504 Gateway Time-out
--- timeout: 1
+--- SKIP
Please sign in to comment.
Something went wrong with that request. Please try again.