~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to tests/suite/base/t/tokens-normalize.lua

  • Committer: Kay Roepke
  • Author(s): Jan Kneschke
  • Date: 2008-01-23 22:00:28 UTC
  • Revision ID: kay@mysql.com-20080123220028-hq2xqb69apa75fnx
first round on mysql-shell based on the proxy code

this is mostly a verification if the proxy-code is flexible enough to handle 
all three scenarios of: client, server and forwarding (proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--[[ $%BEGINLICENSE%$
2
 
 Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3
 
 
4
 
 This program is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU General Public License as
6
 
 published by the Free Software Foundation; version 2 of the
7
 
 License.
8
 
 
9
 
 This program is distributed in the hope that it will be useful,
10
 
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
 GNU General Public License for more details.
13
 
 
14
 
 You should have received a copy of the GNU General Public License
15
 
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ --]]
20
 
local tokenizer = require("proxy.tokenizer")
21
 
local proto = require("mysql.proto")
22
 
 
23
 
function connect_server()
24
 
        -- emulate a server
25
 
        proxy.response = {
26
 
                type = proxy.MYSQLD_PACKET_RAW,
27
 
                packets = {
28
 
                        proto.to_challenge_packet({})
29
 
                }
30
 
        }
31
 
        return proxy.PROXY_SEND_RESULT
32
 
end
33
 
 
34
 
--
35
 
--
36
 
 
37
 
 
38
 
function read_query( packet )
39
 
    if packet:byte() ~= proxy.COM_QUERY then
40
 
        proxy.response = { type = proxy.MYSQLD_PACKET_OK } 
41
 
        return proxy.PROXY_SEND_RESULT
42
 
    end
43
 
    local query = packet:sub(2)
44
 
    --
45
 
    -- Uncomment the following two lines if using with MySQL command line.
46
 
    -- Keep them commented if using inside the test suite
47
 
    -- counter = counter + 1
48
 
    -- if counter < 3 then return end
49
 
    local tokens = tokenizer.tokenize(query)
50
 
    proxy.response.type = proxy.MYSQLD_PACKET_OK
51
 
    proxy.response.resultset = {
52
 
        fields = {
53
 
            { type = proxy.MYSQL_TYPE_STRING, name = "text", },
54
 
        },
55
 
        rows = { { '<'..tokenizer.normalize(tokens)..'>' } }
56
 
    }
57
 
    return proxy.PROXY_SEND_RESULT
58
 
end