我有一个MYSQL服务器和MYSQL-PROXY,我试图操纵我发送给客户端的结果作为对SELECT查询的响应。我在lua中写了这段代码:
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
function read_query_result(inj)
local fn = 1
local fields = inj.resultset.fields
while fields[fn] do
fn = fn + 1
end
fn = fn - 1
print("FIELD NUMBER: " .. fn)
for row in inj.resultset.rows do
print ("--------------")
for i = 1, fn do
if (string.starts(fields[i].name,"TEST")) then
row[i]="TESTED"
end
print ("DATA: " .. fields[i].name .. " -> " .. row[i])
end
end
return proxy.PROXY_SEND_RESULT
end
我可以正确读取字段名称和值。我可以检测到我想要修改结果的条件,但我无法将数据发送到客户端。
我看到两个问题:
return proxy.PROXY_SEND_RESULT
有问题,因为我看到每当我评论该句子时,我都会看到结果,如果我取消注释,我会收到错误。我没有找到示例代码作为参考。
答案 0 :(得分:0)
确定。解决。
这是正确的模块:
function read_query_result(inj)
local fn = 1
local fields = inj.resultset.fields
proxy.response.resultset = {fields = {}, rows = {}}
while fields[fn] do
table.insert(proxy.response.resultset.fields, {type = proxy.MYSQL_TYPE_STRING, name = fields[fn].name})
fn = fn + 1
end
fn = fn - 1
for row in inj.resultset.rows do
for i = 1, fn do
if (string.starts(fields[i].name,"TEST")) then
row[i]="TESTED"
end
end
table.insert(proxy.response.resultset.rows, row )
end
proxy.response.type = proxy.MYSQLD_PACKET_OK
return proxy.PROXY_SEND_RESULT
end