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

« back to all changes in this revision

Viewing changes to trunk/tests/suite/base/t/tokens2.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) 2007, 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
 
 
21
 
local proto = assert(require("mysql.proto"))
22
 
local tokenizer = assert(require("mysql.tokenizer"))
23
 
 
24
 
function connect_server()
25
 
        -- emulate a server
26
 
        proxy.response = {
27
 
                type = proxy.MYSQLD_PACKET_RAW,
28
 
                packets = {
29
 
                        proto.to_challenge_packet({})
30
 
                }
31
 
        }
32
 
        return proxy.PROXY_SEND_RESULT
33
 
end
34
 
 
35
1
--
36
2
-- returns the tokens of every query
37
3
--
42
8
 
43
9
function read_query( packet )
44
10
    if packet:byte() ~= proxy.COM_QUERY then
45
 
        proxy.response = { type = proxy.MYSQLD_PACKET_OK } 
46
 
        return proxy.PROXY_SEND_RESULT
 
11
        return
47
12
    end
48
13
    local query = packet:sub(2)
49
14
    --
51
16
    -- Keep them commented if using inside the test suite
52
17
    -- counter = counter + 1
53
18
    -- if counter < 3 then return end
54
 
    local tokens = tokenizer.tokenize(query)
 
19
    local tokens = proxy.tokenize(query)
55
20
    proxy.response.type = proxy.MYSQLD_PACKET_OK
56
21
    proxy.response.resultset = {
57
22
        fields = {
61
26
        },
62
27
        rows = {  }
63
28
    }
64
 
    for i = 1, #tokens do
65
 
            local token = tokens[i]
 
29
    for i,token in pairs(tokens) do
66
30
        table.insert(proxy.response.resultset.rows,
67
31
            {
68
32
               token['token_id'],