Fixed a term encoding problem
See http://www.erlang.org/doc/man/ei.html#ei_decode_string
This commit is contained in:
@@ -403,11 +403,24 @@ static int bind_parameters(
|
||||
int i, cur_list_size = -1, param_index = 1, param_indices_are_explicit = 0, result = 0;
|
||||
long param_index_long;
|
||||
char param_name[MAXATOMLEN + 1]; // parameter names shouldn't be longer than 256!
|
||||
char *acc_string;
|
||||
result = ei_decode_list_header(buffer, p_index, &cur_list_size);
|
||||
if (result) {
|
||||
// probably all parameters are integers between 0 and 255
|
||||
// and the list was encoded as string (see ei documentation)
|
||||
ei_get_type(buffer, p_index, p_type, p_size);
|
||||
if (*p_type != ERL_STRING_EXT) {
|
||||
return output_error(drv, SQLITE_ERROR,
|
||||
"error while binding parameters");
|
||||
}
|
||||
acc_string = driver_alloc(sizeof(char*) * (*p_size + 1));
|
||||
ei_decode_string(buffer, p_index, acc_string);
|
||||
for (param_index = 1; param_index <= *p_size; param_index++) {
|
||||
sqlite3_bind_int(statement, param_index, (int) acc_string[param_index - 1]);
|
||||
}
|
||||
driver_free(acc_string);
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < cur_list_size; i++) {
|
||||
if (*p_index >= buffer_size) {
|
||||
return output_error(drv, SQLITE_ERROR,
|
||||
|
||||
@@ -47,7 +47,8 @@ all_test_() ->
|
||||
?FuncTest(select_many_records),
|
||||
?FuncTest(nonexistent_table_info),
|
||||
?FuncTest(large_number),
|
||||
?FuncTest(unicode)]}.
|
||||
?FuncTest(unicode),
|
||||
?FuncTest(acc_string_encoding)]}.
|
||||
|
||||
open_db() ->
|
||||
sqlite3:open(ct, [in_memory]).
|
||||
@@ -216,6 +217,9 @@ unicode() ->
|
||||
sqlite3:write(ct, unicode, [{str, UnicodeString}]),
|
||||
?assertEqual([{unicode:characters_to_binary(UnicodeString)}], rows(sqlite3:read_all(ct, unicode))).
|
||||
|
||||
acc_string_encoding() ->
|
||||
?assertEqual([{62}], rows(sqlite3:sql_exec(ct, "SELECT ? + ?", [30,32]))).
|
||||
|
||||
prepared_test() ->
|
||||
Columns = ["id", "name", "age", "wage"],
|
||||
Abby = {1, <<"abby">>, 20, 2000},
|
||||
|
||||
Reference in New Issue
Block a user