diff --git a/src/emysql_conn.erl b/src/emysql_conn.erl index 727dc561..ad125dec 100644 --- a/src/emysql_conn.erl +++ b/src/emysql_conn.erl @@ -386,10 +386,18 @@ encode(null, list) -> "null"; encode(undefined, list) -> "null"; +encode(false, list) -> + "false"; +encode(true, list) -> + "true"; encode(null, binary) -> <<"null">>; encode(undefined, binary) -> <<"null">>; +encode(false, binary) -> + <<"false">>; +encode(true, binary) -> + <<"true">>; encode(Val, list) when is_binary(Val) -> quote(binary_to_list(Val)); encode(Val, binary) when is_atom(Val) -> diff --git a/test/basics_SUITE.erl b/test/basics_SUITE.erl index 97fc363a..703798bc 100644 --- a/test/basics_SUITE.erl +++ b/test/basics_SUITE.erl @@ -68,7 +68,8 @@ groups() -> json_empty_test, json_single_test, json_multi_test, - record_test]} + record_test, + boolean_test]} ]. %% Optional suite pre test initialization @@ -468,6 +469,19 @@ record_test(_Config) -> Expected = emysql:as_record(Result, person, record_info(fields, person)), ok. +boolean_test(_Config) -> + emysql:execute(test_pool, <<"DROP TABLE IF EXISTS boolean_test">>), + emysql:execute(test_pool, <<"CREATE TABLE boolean_test (bool BOOLEAN)">>), + emysql:prepare(b_insert, <<"INSERT INTO boolean_test VALUES (?), (?)">>), + emysql:prepare(b_select, <<"SELECT * FROM boolean_test WHERE bool = ?">>), + emysql:execute(test_pool, b_insert, [true, false]), + RTrue = emysql:execute(test_pool, b_select, [true]), + RFalse = emysql:execute(test_pool, b_select, [false]), + ETrue = [{<<"bool">>, 1}], + EFalse = [{<<"bool">>, 0}], + [ETrue] = emysql:as_proplist(RTrue), + [EFalse] = emysql:as_proplist(RFalse), + ok. %%% Data generation %% --------------------------------------------------------------------------------------------