Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add boolean (true/false atoms) #130

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/emysql_conn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
16 changes: 15 additions & 1 deletion test/basics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
%% --------------------------------------------------------------------------------------------
Expand Down