Fixed issue #13 (binding ints from 128 to 255 incorrectly)
This commit is contained in:
@@ -357,7 +357,7 @@ static inline int decode_and_bind_param(
|
|||||||
// include space for null separator
|
// include space for null separator
|
||||||
char_buf_val = driver_alloc((*p_size + 1) * sizeof(char));
|
char_buf_val = driver_alloc((*p_size + 1) * sizeof(char));
|
||||||
ei_decode_string(buffer, p_index, char_buf_val);
|
ei_decode_string(buffer, p_index, char_buf_val);
|
||||||
result = sqlite3_bind_text(statement, param_index, char_buf_val, *p_size, &driver_free_fun);
|
result = sqlite3_bind_text(statement, param_index, char_buf_val, *p_size, &driver_free_fun);
|
||||||
break;
|
break;
|
||||||
case ERL_BINARY_EXT:
|
case ERL_BINARY_EXT:
|
||||||
char_buf_val = driver_alloc(*p_size * sizeof(char));
|
char_buf_val = driver_alloc(*p_size * sizeof(char));
|
||||||
@@ -413,7 +413,7 @@ static int bind_parameters(
|
|||||||
acc_string = driver_alloc(sizeof(char*) * (*p_size + 1));
|
acc_string = driver_alloc(sizeof(char*) * (*p_size + 1));
|
||||||
ei_decode_string(buffer, p_index, acc_string);
|
ei_decode_string(buffer, p_index, acc_string);
|
||||||
for (param_index = 1; param_index <= *p_size; param_index++) {
|
for (param_index = 1; param_index <= *p_size; param_index++) {
|
||||||
sqlite3_bind_int(statement, param_index, (int) acc_string[param_index - 1]);
|
sqlite3_bind_int(statement, param_index, (int) (unsigned char) acc_string[param_index - 1]);
|
||||||
}
|
}
|
||||||
driver_free(acc_string);
|
driver_free(acc_string);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ all_test_() ->
|
|||||||
?FuncTest(large_number),
|
?FuncTest(large_number),
|
||||||
?FuncTest(unicode),
|
?FuncTest(unicode),
|
||||||
?FuncTest(acc_string_encoding),
|
?FuncTest(acc_string_encoding),
|
||||||
?FuncTest(large_offset)]}.
|
?FuncTest(large_offset),
|
||||||
|
?FuncTest(issue13)]}.
|
||||||
|
|
||||||
open_db() ->
|
open_db() ->
|
||||||
sqlite3:open(ct, [in_memory]).
|
sqlite3:open(ct, [in_memory]).
|
||||||
@@ -310,6 +311,21 @@ large_offset() ->
|
|||||||
[{columns, ["id"]}, {rows, []}, {error, 20, _}],
|
[{columns, ["id"]}, {rows, []}, {error, 20, _}],
|
||||||
sqlite3:sql_exec(ct, "select * from large_offset limit 1 offset 9223372036854775808")).
|
sqlite3:sql_exec(ct, "select * from large_offset limit 1 offset 9223372036854775808")).
|
||||||
|
|
||||||
|
issue13() ->
|
||||||
|
drop_table_if_exists(ct, issue13),
|
||||||
|
ok = sqlite3:create_table(ct, issue13, [{foo, integer}]),
|
||||||
|
sqlite3:write_many(ct, issue13,
|
||||||
|
[[{foo, X}] || X <- [-1, 0, 127, 128, 255, 256]]),
|
||||||
|
?assertEqual(
|
||||||
|
[{columns, ["foo"]}, {rows, [{255}, {256}]}],
|
||||||
|
sqlite3:sql_exec(ct, "select foo from issue13 where foo > 128;")),
|
||||||
|
?assertEqual(
|
||||||
|
[{columns, ["foo"]}, {rows, [{255}, {256}]}],
|
||||||
|
sqlite3:sql_exec(ct, "select foo from issue13 where foo > ?;", [128.0])),
|
||||||
|
?assertEqual(
|
||||||
|
[{columns, ["foo"]}, {rows, [{255}, {256}]}],
|
||||||
|
sqlite3:sql_exec(ct, "select foo from issue13 where foo > ?;", [128])).
|
||||||
|
|
||||||
% create, read, update, delete
|
% create, read, update, delete
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|||||||
Reference in New Issue
Block a user