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

« back to all changes in this revision

Viewing changes to trunk/lib/proxy/commands.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%$ --]]
 
1
--[[
 
2
 
 
3
   Copyright (C) 2007 MySQL AB
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; version 2 of the 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
--]]
20
19
 
21
20
module("proxy.commands", package.seeall)
22
21
 
75
74
                -- nothing to decode
76
75
        elseif cmd.type == proxy.COM_STMT_PREPARE then
77
76
                cmd.query = packet:sub(2)
78
 
        -- the stmt_handler_id is at the same position for both STMT_EXECUTE and STMT_CLOSE
79
 
        elseif cmd.type == proxy.COM_STMT_EXECUTE or cmd.type == proxy.COM_STMT_CLOSE then
80
 
                cmd.stmt_handler_id = string.byte(packet, 2) + (string.byte(packet, 3) * 256) + (string.byte(packet, 4) * 256 * 256) + (string.byte(packet, 5) * 256 * 256 * 256)
81
77
        elseif cmd.type == proxy.COM_FIELD_LIST then
82
78
                cmd.table = packet:sub(2)
83
79
        elseif cmd.type == proxy.COM_INIT_DB or
84
80
               cmd.type == proxy.COM_CREATE_DB or
85
81
               cmd.type == proxy.COM_DROP_DB then
86
82
                cmd.schema = packet:sub(2)
87
 
        elseif cmd.type == proxy.COM_SET_OPTION then
88
 
                cmd.option = packet:sub(2)
89
83
        else
90
 
                print("[debug] (command) unhandled type name:" .. tostring(cmd.type_name) .. " byte:" .. tostring(cmd.type))
 
84
                print("[debug] (command) unhandled type " .. cmd.type_name)
91
85
        end
92
86
 
93
87
        return cmd
106
100
        elseif cmd.type == proxy.COM_FIELD_LIST then
107
101
                -- should have a table-name
108
102
                return ("[%s]"):format(cmd.type_name)
109
 
        elseif cmd.type == proxy.COM_STMT_EXECUTE then
110
 
        return ("[%s] %s"):format(cmd.type_name, cmd.stmt_handler_id)
111
 
        elseif cmd.type == proxy.COM_STMT_EXECUTE then
112
 
                return ("[%s] %s"):format(cmd.type_name, cmd.stmt_handler_id)
113
103
        end
114
104
 
115
105
        return ("[%s] ... no idea"):format(cmd.type_name)