mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
restore some styles as before.
This commit is contained in:
@@ -102,13 +102,10 @@ local function _from_cstring(data, i)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function _dumphex(bytes)
|
local function _dumphex(bytes)
|
||||||
return strgsub(
|
return strgsub(bytes, ".",
|
||||||
bytes,
|
|
||||||
".",
|
|
||||||
function(x)
|
function(x)
|
||||||
return strformat("%02x ", strbyte(x))
|
return strformat("%02x ", strbyte(x))
|
||||||
end
|
end)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _compute_token(password, scramble)
|
local function _compute_token(password, scramble)
|
||||||
@@ -123,9 +120,7 @@ local function _compute_token(password, scramble)
|
|||||||
local stage3 = sha1(scramble .. stage2)
|
local stage3 = sha1(scramble .. stage2)
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
return strgsub(
|
return strgsub(stage3, ".",
|
||||||
stage3,
|
|
||||||
".",
|
|
||||||
function(x)
|
function(x)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
-- ~ is xor in lua 5.3
|
-- ~ is xor in lua 5.3
|
||||||
@@ -258,7 +253,7 @@ local function _parse_err_packet(packet)
|
|||||||
local errno, pos = _get_byte2(packet, 2)
|
local errno, pos = _get_byte2(packet, 2)
|
||||||
local marker = sub(packet, pos, pos)
|
local marker = sub(packet, pos, pos)
|
||||||
local sqlstate
|
local sqlstate
|
||||||
if marker == "#" then
|
if marker == '#' then
|
||||||
-- with sqlstate
|
-- with sqlstate
|
||||||
pos = pos + 1
|
pos = pos + 1
|
||||||
sqlstate = sub(packet, pos, pos + 5 - 1)
|
sqlstate = sub(packet, pos, pos + 5 - 1)
|
||||||
@@ -413,9 +408,7 @@ local function _mysql_login(self, user, password, database, on_connect)
|
|||||||
local scramble = scramble1 .. scramble_part2
|
local scramble = scramble1 .. scramble_part2
|
||||||
local token = _compute_token(password, scramble)
|
local token = _compute_token(password, scramble)
|
||||||
local client_flags = 260047
|
local client_flags = 260047
|
||||||
local req =
|
local req = strpack("<I4I4c24zs1z",
|
||||||
strpack(
|
|
||||||
"<I4I4c24zs1z",
|
|
||||||
client_flags,
|
client_flags,
|
||||||
self._max_packet_size,
|
self._max_packet_size,
|
||||||
strrep("\0", 24), -- TODO: add support for charset encoding
|
strrep("\0", 24), -- TODO: add support for charset encoding
|
||||||
@@ -504,13 +497,13 @@ local function read_result(self, sock)
|
|||||||
local packet, typ, err = _recv_packet(self, sock)
|
local packet, typ, err = _recv_packet(self, sock)
|
||||||
if not packet then
|
if not packet then
|
||||||
return nil, err
|
return nil, err
|
||||||
--error( err )
|
--error( err )
|
||||||
end
|
end
|
||||||
|
|
||||||
if typ == "ERR" then
|
if typ == "ERR" then
|
||||||
local errno, msg, sqlstate = _parse_err_packet(packet)
|
local errno, msg, sqlstate = _parse_err_packet(packet)
|
||||||
return nil, msg, errno, sqlstate
|
return nil, msg, errno, sqlstate
|
||||||
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
||||||
end
|
end
|
||||||
|
|
||||||
if typ == "OK" then
|
if typ == "OK" then
|
||||||
@@ -523,7 +516,7 @@ local function read_result(self, sock)
|
|||||||
|
|
||||||
if typ ~= "DATA" then
|
if typ ~= "DATA" then
|
||||||
return nil, "packet type " .. typ .. " not supported"
|
return nil, "packet type " .. typ .. " not supported"
|
||||||
--error( "packet type " .. typ .. " not supported" )
|
--error( "packet type " .. typ .. " not supported" )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- typ == 'DATA'
|
-- typ == 'DATA'
|
||||||
@@ -534,7 +527,7 @@ local function read_result(self, sock)
|
|||||||
local col, err, errno, sqlstate = _recv_field_packet(self, sock)
|
local col, err, errno, sqlstate = _recv_field_packet(self, sock)
|
||||||
if not col then
|
if not col then
|
||||||
return nil, err, errno, sqlstate
|
return nil, err, errno, sqlstate
|
||||||
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
||||||
end
|
end
|
||||||
cols[i] = col
|
cols[i] = col
|
||||||
end
|
end
|
||||||
@@ -571,7 +564,7 @@ local function read_result(self, sock)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- if typ ~= 'DATA' then
|
-- if typ ~= 'DATA' then
|
||||||
-- return nil, 'bad row packet type: ' .. typ
|
-- return nil, 'bad row packet type: ' .. typ
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
-- typ == 'DATA'
|
-- typ == 'DATA'
|
||||||
@@ -809,13 +802,13 @@ local function read_execute_result(self, sock)
|
|||||||
local packet, typ, err = _recv_packet(self, sock)
|
local packet, typ, err = _recv_packet(self, sock)
|
||||||
if not packet then
|
if not packet then
|
||||||
return nil, err
|
return nil, err
|
||||||
--error( err )
|
--error( err )
|
||||||
end
|
end
|
||||||
|
|
||||||
if typ == "ERR" then
|
if typ == "ERR" then
|
||||||
local errno, msg, sqlstate = _parse_err_packet(packet)
|
local errno, msg, sqlstate = _parse_err_packet(packet)
|
||||||
return nil, msg, errno, sqlstate
|
return nil, msg, errno, sqlstate
|
||||||
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
||||||
end
|
end
|
||||||
|
|
||||||
if typ == "OK" then
|
if typ == "OK" then
|
||||||
@@ -828,7 +821,7 @@ local function read_execute_result(self, sock)
|
|||||||
|
|
||||||
if typ ~= "DATA" then
|
if typ ~= "DATA" then
|
||||||
return nil, "packet type " .. typ .. " not supported"
|
return nil, "packet type " .. typ .. " not supported"
|
||||||
--error( "packet type " .. typ .. " not supported" )
|
--error( "packet type " .. typ .. " not supported" )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- typ == 'DATA'
|
-- typ == 'DATA'
|
||||||
@@ -846,7 +839,7 @@ local function read_execute_result(self, sock)
|
|||||||
col = _parse_field_packet(packet)
|
col = _parse_field_packet(packet)
|
||||||
if not col then
|
if not col then
|
||||||
break
|
break
|
||||||
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
--error( strformat("errno:%d, msg:%s,sqlstate:%s",errno,msg,sqlstate))
|
||||||
end
|
end
|
||||||
table.insert(cols, col)
|
table.insert(cols, col)
|
||||||
end
|
end
|
||||||
@@ -921,7 +914,7 @@ end
|
|||||||
]]
|
]]
|
||||||
function _M.execute(self, stmt, ...)
|
function _M.execute(self, stmt, ...)
|
||||||
-- 检查参数,不能为nil
|
-- 检查参数,不能为nil
|
||||||
local p_n = select("#", ...)
|
local p_n = select('#', ...)
|
||||||
local p_v
|
local p_v
|
||||||
for i = 1, p_n do
|
for i = 1, p_n do
|
||||||
p_v = select(i, ...)
|
p_v = select(i, ...)
|
||||||
@@ -970,19 +963,19 @@ function _M.server_ver(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local escape_map = {
|
local escape_map = {
|
||||||
["\0"] = "\\0",
|
['\0'] = "\\0",
|
||||||
["\b"] = "\\b",
|
['\b'] = "\\b",
|
||||||
["\n"] = "\\n",
|
['\n'] = "\\n",
|
||||||
["\r"] = "\\r",
|
['\r'] = "\\r",
|
||||||
["\t"] = "\\t",
|
['\t'] = "\\t",
|
||||||
["\26"] = "\\Z",
|
['\26'] = "\\Z",
|
||||||
["\\"] = "\\\\",
|
['\\'] = "\\\\",
|
||||||
["'"] = "\\'",
|
["'"] = "\\'",
|
||||||
['"'] = '\\"'
|
['"'] = '\\"',
|
||||||
}
|
}
|
||||||
|
|
||||||
function _M.quote_sql_str(str)
|
function _M.quote_sql_str( str)
|
||||||
return strformat("'%s'", strgsub(str, '[\0\b\n\r\t\26\\\'"]', escape_map))
|
return strformat("'%s'", strgsub(str, "[\0\b\n\r\t\26\\\'\"]", escape_map))
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.set_compact_arrays(self, value)
|
function _M.set_compact_arrays(self, value)
|
||||||
|
|||||||
Reference in New Issue
Block a user