Skip to content

Commit 41929b0

Browse files
Added: debug script without colors
1 parent 71760bc commit 41929b0

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ Colors are also used to denote slow queries: time displayed in red instead of
3737
green. When a query returns no rows nor affect records, "<NONE>" is displayed
3838
using red in reverse video.
3939

40+
### debug-blind.lua
41+
42+
Same as debug.lua, but without shell colors.
43+
4044
[mysql-proxy]: http://forge.mysql.com/wiki/MySQL_Proxy

debug-blind.lua

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
-- MySQL Proxy script for development/debugging purposes
2+
--
3+
-- Written by Patrick Allaert <[email protected]>
4+
-- Copyright © 2009-2011 Libereco Technologies
5+
--
6+
-- This program is free software: you can redistribute it and/or modify
7+
-- it under the terms of the GNU General Public License as published by
8+
-- the Free Software Foundation, either version 3 of the License, or
9+
-- (at your option) any later version.
10+
--
11+
-- This program is distributed in the hope that it will be useful,
12+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
-- GNU General Public License for more details.
15+
--
16+
-- You should have received a copy of the GNU General Public License
17+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
transaction_counter = 0
20+
21+
function read_query( packet )
22+
if packet:byte() ~= proxy.COM_QUERY then
23+
return
24+
end
25+
proxy.queries:append(1, string.char(proxy.COM_QUERY) .. packet:sub(2), {resultset_is_needed = true})
26+
27+
return proxy.PROXY_SEND_QUERY
28+
end
29+
30+
function read_query_result (inj)
31+
local res = assert(inj.resultset)
32+
local error_status = ""
33+
if res.flags.no_good_index_used then
34+
error_status = error_status .. "No good index used!"
35+
end
36+
if res.flags.no_index_used then
37+
error_status = error_status .. "No index used!"
38+
end
39+
local row_count = 0
40+
if res.affected_rows then
41+
row_count = res.affected_rows
42+
else
43+
local num_cols = string.byte(res.raw, 1)
44+
if num_cols > 0 and num_cols < 255 then
45+
for row in inj.resultset.rows do
46+
row_count = row_count + 1
47+
end
48+
end
49+
end
50+
if res.query_status == proxy.MYSQLD_PACKET_ERR then
51+
error_status = string.format("%q", res.raw:sub(10))
52+
end
53+
local query = string.gsub(string.sub(inj.query, 2), "%s+", " ")
54+
local word = string.upper(string.sub(query,1,6))
55+
if word == "COMMIT" then
56+
transaction_counter = transaction_counter - 1
57+
end
58+
59+
local i = 0
60+
while i < transaction_counter do
61+
io.write(" ")
62+
i = i +1
63+
end
64+
65+
if string.upper(string.sub(query,1,5)) == "BEGIN" then
66+
transaction_counter = transaction_counter + 1
67+
end
68+
69+
print(
70+
string.format(
71+
"%s\t%s\t%s\t%fms",
72+
query,
73+
error_status,
74+
row_count == 0 and "<NONE>" or row_count,
75+
inj.response_time / 1e3
76+
)
77+
)
78+
end

0 commit comments

Comments
 (0)