From ef3346e8977a8f726ff8877d8bcbda953ea23796 Mon Sep 17 00:00:00 2001 From: Hajime Nakagami Date: Wed, 8 May 2024 20:32:34 +0900 Subject: [PATCH 1/3] add test bigint parameter --- test/efirebirdsql_tests.erl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/efirebirdsql_tests.erl b/test/efirebirdsql_tests.erl index 83150b8..bcc7175 100644 --- a/test/efirebirdsql_tests.erl +++ b/test/efirebirdsql_tests.erl @@ -36,12 +36,13 @@ create_test_tables(C) -> h1 BLOB SUB_TYPE 1, i DOUBLE PRECISION DEFAULT 1.0, j FLOAT DEFAULT 2.0, + k BIGINT DEFAULT 123456789999999999, PRIMARY KEY (a), CONSTRAINT CHECK_A CHECK (a <> 0) ) ">>), ok = efirebirdsql:execute(C, <<"insert into foo(a, b, c, h0, h1) values (?,?,?,?,?)">>, [1, <<"b">>, <<"c">>, nil, <<"blob">>]), - ok = efirebirdsql:execute(C, <<"insert into foo(a, b, c, h1) values (?,?,?,?)">>, [2, <<"B">>, <<"C">>, <<"BLOB">>]), + ok = efirebirdsql:execute(C, <<"insert into foo(a, b, c, h1, k) values (?,?,?,?)">>, [2, <<"B">>, <<"C">>, <<"BLOB">>, 123456780000000000]), ok = efirebirdsql:execute(C, <<" CREATE PROCEDURE foo_proc @@ -70,7 +71,8 @@ description() -> {<<"H0">>,blob,0,8,true}, {<<"H1">>,blob,4,8,true}, {<<"I">>,double,0,8,true}, - {<<"J">>,float,0,4,true}]. + {<<"J">>,float,0,4,true}, + {<<"K">>,int64,0,8,true}]. alias_description() -> [{<<"ALIAS_NAME">>,long,0,4,false}]. @@ -86,7 +88,8 @@ result1() -> {<<"H0">>,nil}, {<<"H1">>,<<"blob">>}, {<<"I">>,1.0}, - {<<"J">>,2.0}]. + {<<"J">>,2.0}, + {<<"K">>,123456789999999999}]. result2() -> [{<<"A">>,2}, @@ -99,7 +102,8 @@ result2() -> {<<"H0">>,nil}, {<<"H1">>,<<"BLOB">>}, {<<"I">>,1.0}, - {<<"J">>,2.0}]. + {<<"J">>,2.0}, + {<<"K">>,123456780000000000}]. basic_test() -> %% connect to bad database From b9b3b5095aa0f0fbe7181e4afaee0a24b7f20b3a Mon Sep 17 00:00:00 2001 From: Hajime Nakagami Date: Wed, 8 May 2024 20:35:10 +0900 Subject: [PATCH 2/3] fix test --- test/efirebirdsql_tests.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/efirebirdsql_tests.erl b/test/efirebirdsql_tests.erl index bcc7175..8b74ead 100644 --- a/test/efirebirdsql_tests.erl +++ b/test/efirebirdsql_tests.erl @@ -42,7 +42,7 @@ create_test_tables(C) -> ) ">>), ok = efirebirdsql:execute(C, <<"insert into foo(a, b, c, h0, h1) values (?,?,?,?,?)">>, [1, <<"b">>, <<"c">>, nil, <<"blob">>]), - ok = efirebirdsql:execute(C, <<"insert into foo(a, b, c, h1, k) values (?,?,?,?)">>, [2, <<"B">>, <<"C">>, <<"BLOB">>, 123456780000000000]), + ok = efirebirdsql:execute(C, <<"insert into foo(a, b, c, h1, k) values (?,?,?,?,?)">>, [2, <<"B">>, <<"C">>, <<"BLOB">>, 123456780000000000]), ok = efirebirdsql:execute(C, <<" CREATE PROCEDURE foo_proc From 8038359bd3117a279867de99926a08d3055a679d Mon Sep 17 00:00:00 2001 From: Hajime Nakagami Date: Wed, 8 May 2024 21:09:38 +0900 Subject: [PATCH 3/3] fix over 4 bytes int parameter #17 --- src/efirebirdsql_conv.erl | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/efirebirdsql_conv.erl b/src/efirebirdsql_conv.erl index 1496cae..05e1a2b 100644 --- a/src/efirebirdsql_conv.erl +++ b/src/efirebirdsql_conv.erl @@ -42,6 +42,25 @@ byte4(N, little) -> byte4(N) -> byte4(N, big). +%%% big endian number list fill 8 byte alignment +-spec byte8(integer(), atom()) -> list(). +byte8(N, big) -> + LB = binary:encode_unsigned(N, big), + LB8 = case size(LB) of + 1 -> << <<0,0,0,0,0,0,0>>/binary, LB/binary >>; + 2 -> << <<0,0,0,0,0,0>>/binary, LB/binary >>; + 3 -> << <<0,0,0,0,0>>/binary, LB/binary >>; + 4 -> << <<0,0,0,0>>/binary, LB/binary >>; + 5 -> << <<0,0,0>>/binary, LB/binary >>; + 6 -> << <<0,0>>/binary, LB/binary >>; + 7 -> << <<0>>/binary, LB/binary >>; + 8 -> LB + end, + binary_to_list(LB8). + +byte8(N) -> + byte8(N, big). + %%% 4 byte padding -spec pad4(list()) -> list(). pad4(L) -> @@ -155,8 +174,10 @@ param_to_date(Year, Month, Day) -> param_to_time(Hour, Minute, Second, Microsecond) -> byte4((Hour*3600 + Minute*60 + Second) * 10000 + Microsecond div 100). -param_to_blr(V, _) when is_integer(V) -> +param_to_blr(V, _) when is_integer(V) and (V =< 16#7FFFFFFF) and (V >= -16#80000000) -> {[8, 0, 7, 0], byte4(V)}; +param_to_blr(V, _) when is_integer(V) -> + {[16, 0, 7, 0], byte8(V)}; param_to_blr(V, _) when is_binary(V) -> B = binary_to_list(V), {lists:flatten([14, byte2(length(B)), 7, 0]),