Skip to content

Commit

Permalink
feature: we now convert the mysql newdecimal typed fields to Lua numb…
Browse files Browse the repository at this point in the history
…ers by default as requested by shedar in github issue #2.
  • Loading branch information
agentzh committed Dec 10, 2012
1 parent f52804d commit a7dff62
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/resty/mysql.lua
Expand Up @@ -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)
Expand Down
74 changes: 73 additions & 1 deletion t/sanity.t
Expand Up @@ -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();

Expand Down Expand Up @@ -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.