Merge lp:~ben-kersten/mysql-proxy/packet-empty-set into lp:mysql-proxy/0.8

Proposed by bkersten
Status: Needs review
Proposed branch: lp:~ben-kersten/mysql-proxy/packet-empty-set
Merge into: lp:mysql-proxy/0.8
Diff against target: 11 lines (+1/-0)
1 file modified
src/network-mysqld-packet.c (+1/-0)
To merge this branch: bzr merge lp:~ben-kersten/mysql-proxy/packet-empty-set
Reviewer Review Type Date Requested Status
Registry Administrators Pending
Review via email: mp+37427@code.launchpad.net

Description of the change

When a query goes through the lua layer and mysqld returns an error it is possible for the query status to be set to OK if the error packet is preceded by field header packets.

=========================

-- test script for a failing query that gets error packet after field packets

function read_query(packet)

  if string.byte(packet) ~= proxy.COM_QUERY then
    return
  end

  local query = string.sub(packet, 2)
  if string.match(string.upper(query), "TEST") then
    print("testing the bug")
    proxy.queries:append(1, string.char(proxy.COM_QUERY) .. "EXPLAIN SELECT * FROM dual", {resultset_is_needed = true})
    return proxy.PROXY_SEND_QUERY
  end
end

function read_query_result (inj)
  if inj.id == 1 then
    local status = inj.resultset.query_status

    if not status or status == proxy.MYSQLD_PACKET_ERR then
      print("An error occurred in query: " .. inj.query:sub(2))
      return -- original results
    end

    -- resultset rewrite
    local response = {
      ['type'] = proxy.MYSQLD_PACKET_OK,
      ['resultset'] = {
        ['fields'] = {
          {
            type = proxy.MYSQL_TYPE_STRING,
            name = "fake_field",
          }
        },
        ['rows'] = {}
      }
    }

    -- copy the hopefully empty resultset
    local rows = response.resultset.rows
    for row in inj.resultset.rows do
      rows[#rows+1] = row
    end

    print("row count: " .. #rows)

    proxy.response = response
    return proxy.PROXY_SEND_RESULT
  end
end

To post a comment you must log in.

Unmerged revisions

1133. By Ben Kersten <bkersten@mel601855>

Fixed bug where query status is not set to error when error packet is preceded by field header packets.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/network-mysqld-packet.c'
2--- src/network-mysqld-packet.c 2010-09-22 15:10:11 +0000
3+++ src/network-mysqld-packet.c 2010-10-04 00:12:44 +0000
4@@ -210,6 +210,7 @@
5 *
6 * EXPLAIN SELECT 1 FROM dual; returns a result-set
7 * */
8+ query->query_status = MYSQLD_PACKET_ERR;
9 is_finished = 1;
10 break;
11 case MYSQLD_PACKET_OK:

Subscribers

People subscribed via source and target branches