Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

feature: we now convert the mysql newdecimal typed fields to Lua numb…

…ers by default as requested by shedar in github issue #2.
  • Loading branch information...
commit a7dff62ea2339240b791b8d159217b8f5269f739 1 parent f52804d
@agentzh agentzh authored
Showing with 74 additions and 1 deletion.
  1. +1 −0  lib/resty/mysql.lua
  2. +73 −1 t/sanity.t
View
1  lib/resty/mysql.lua
@@ -53,6 +53,7 @@ end
-- converters[0x08] = tonumber -- long long
converters[0x09] = tonumber -- int24
converters[0x0d] = tonumber -- year
+converters[0xf6] = tonumber -- newdecimal
local function _get_byte2(data, i)
View
74 t/sanity.t
@@ -5,7 +5,7 @@ use Cwd qw(cwd);
repeat_each(2);
-plan tests => repeat_each() * (3 * blocks() + 3);
+plan tests => repeat_each() * (3 * blocks() + 4);
my $pwd = cwd();
@@ -1114,3 +1114,75 @@ result: \[{"name":"Bob","id":"1"},{"name":"","id":"2"},{"name":null,"id":"3"}\],
qr/lua tcp socket keepalive create connection pool for key "my_pool"/
--- log_level: debug
+
+
+=== TEST 17: the mysql newdecimal type
+--- http_config eval: $::HttpConfig
+--- config
+ location /t {
+ content_by_lua '
+ local cjson = require "cjson"
+
+ local mysql = require "resty.mysql"
+ local db = mysql:new()
+
+ db:set_timeout(1000) -- 1 sec
+
+ local ok, err, errno, sqlstate = db:connect({
+ path = "$TEST_NGINX_MYSQL_PATH",
+ database = "ngx_test",
+ user = "ngx_test",
+ password = "ngx_test",
+ pool = "my_pool"})
+
+ if not ok then
+ ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
+ return
+ end
+
+ ngx.say("connected to mysql: ", db:get_reused_times())
+
+ local ok, err = db:set_keepalive()
+ if not ok then
+ ngx.say("failed to set keepalive: ", err)
+ return
+ end
+
+ ok, err, errno, sqlstate = db:connect({
+ host = "$TEST_NGINX_MYSQL_HOST",
+ port = $TEST_NGINX_MYSQL_PORT,
+ database = "ngx_test",
+ user = "ngx_test",
+ password = "ngx_test",
+ pool = "my_pool"})
+
+ ngx.say("connected to mysql: ", db:get_reused_times())
+
+ res, err, errno, sqlstate =
+ db:query("select sum(id) from cats")
+ if not res then
+ ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".")
+ return
+ end
+
+ ngx.say("result: ", cjson.encode(res), ", err:", err)
+
+ local ok, err = db:set_keepalive()
+ if not ok then
+ ngx.say("failed to set keepalive: ", err)
+ return
+ end
+ ';
+ }
+--- request
+GET /t
+--- response_body_like chop
+^connected to mysql: [02]
+connected to mysql: [13]
+result: \[\{"sum\(id\)":6\}\], err:nil$
+--- no_error_log
+[error]
+--- error_log eval
+qr/lua tcp socket keepalive create connection pool for key "my_pool"/
+--- log_level: debug
+

0 comments on commit a7dff62

Please sign in to comment.
Something went wrong with that request. Please try again.