Hi list,

I received this patch (and another one that I'll send to you shortly)
to fix a bug in the MySQL driver described below. I tried testing it
but after I applied this patch I couldn't get the MySQL dispatcher to
start anymore. I'd appreciate it if somebody else could try it
(together with the next patch I'll email you) and verify that it
does/doesn't work before we check it in.

Thanks,
Yariv




Summary:
  - It was always assuming affected_rows < 253 and not
    actually decoding the mysql length-coded binary correctly

Test Plan:
  - Made a table with 258 rows, ran an UPDATE that changed them
    all, and verified the old version was broken. Fixed it and
    verified that it's now fixed
---
 erlang/mysql/src/mysql_conn.erl |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/erlang/mysql/src/mysql_conn.erl b/erlang/mysql/src/mysql_conn.erl
index 15ee23a..779fd8f 100644
--- a/erlang/mysql/src/mysql_conn.erl
+++ b/erlang/mysql/src/mysql_conn.erl
@@ -652,7 +652,7 @@ get_query_response(LogFun, RecvPid, Version) ->
            case Fieldcount of
                0 ->
                    %% No Tabular data
-                   <<AffectedRows:8, _Rest2/binary>> = Rest,
+                    {AffectedRows, _Rest2} = decode_length(Rest),
                    {updated, #mysql_result{affectedrows=AffectedRows}};
                255 ->
                    <<_Code:16/little, Message/binary>>  = Rest,
@@ -787,16 +787,24 @@ get_row([Field | OtherFields], Data, Res) ->
           end,
     get_row(OtherFields, Rest, [This | Res]).

-get_with_length(<<251:8, Rest/binary>>) ->
+
+get_with_length(Binary) ->
+    {Length, Rest} = decode_length(Binary),
+    case Length of
+        null -> {null, Rest};
+        _Else -> split_binary(Rest, Length)
+    end.
+
+decode_length(<<251:8, Rest/binary>>) ->
     {null, Rest};
-get_with_length(<<252:8, Length:16/little, Rest/binary>>) ->
-    split_binary(Rest, Length);
-get_with_length(<<253:8, Length:24/little, Rest/binary>>) ->
-    split_binary(Rest, Length);
-get_with_length(<<254:8, Length:64/little, Rest/binary>>) ->
-    split_binary(Rest, Length);
-get_with_length(<<Length:8, Rest/binary>>) when Length < 251 ->
-    split_binary(Rest, Length).
+decode_length(<<252:8, Length:16/little, Rest/binary>>) ->
+    {Length, Rest};
+decode_length(<<253:8, Length:24/little, Rest/binary>>) ->
+    {Length, Rest};
+decode_length(<<254:8, Length:64/little, Rest/binary>>) ->
+    {Length, Rest};
+decode_length(<<Length:8, Rest/binary>>) when Length < 251 ->
+    {Length, Rest}.


 %%--------------------------------------------------------------------
--
1.5.3.2

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to