Skip to content

Commit 4f97928

Browse files
committed
fix for doris
1 parent 6b90f71 commit 4f97928

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/myxql/protocol.ex

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,38 @@ defmodule MyXQL.Protocol do
339339
decode_resultset(payload, next_data, state, &Values.decode_text_row/2)
340340
end
341341

342+
# Handle 10-byte packet (DorisDB/Apache Doris - without num_warnings field)
343+
# DorisDB sends: [0x00 status (1 byte) | statement_id (4 bytes) | num_columns (2 bytes) | num_params (2 bytes) | 0x00 reserved (1 byte)]
344+
# Total: 10 bytes (missing the 2-byte num_warnings field that MySQL includes after the reserved byte)
345+
def decode_com_stmt_prepare_response(
346+
<<0x00, statement_id::uint4(), num_columns::uint2(), num_params::uint2(), 0x00>>,
347+
next_data,
348+
:initial
349+
) do
350+
# DorisDB sends 10-byte packets without num_warnings field
351+
# Default num_warnings to 0 for compatibility
352+
result =
353+
com_stmt_prepare_ok(
354+
statement_id: statement_id,
355+
num_columns: num_columns,
356+
num_params: num_params,
357+
num_warnings: 0
358+
)
359+
360+
cond do
361+
num_params > 0 ->
362+
{:cont, {result, :params, num_params, num_columns}}
363+
364+
num_columns > 0 ->
365+
{:cont, {result, :columns, num_columns}}
366+
367+
true ->
368+
"" = next_data
369+
{:halt, result}
370+
end
371+
end
372+
373+
# Handle 12-byte packet (Standard MySQL - with num_warnings field)
342374
def decode_com_stmt_prepare_response(
343375
<<0x00, statement_id::uint4(), num_columns::uint2(), num_params::uint2(), 0,
344376
num_warnings::uint2()>>,

0 commit comments

Comments
 (0)