From 5030f355580ab2686b1df944ea8ab61f5a7ba93f Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Wed, 14 Jul 2010 21:23:21 +1000 Subject: [PATCH] correct handling of SQL boolean types (EJAB-1275) --- src/mod_privacy_odbc.erl | 10 +++++----- src/odbc/ejabberd_odbc.erl | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/mod_privacy_odbc.erl b/src/mod_privacy_odbc.erl index ae572ae64..5ad2fb958 100644 --- a/src/mod_privacy_odbc.erl +++ b/src/mod_privacy_odbc.erl @@ -726,11 +726,11 @@ raw_to_item({SType, SValue, SAction, SOrder, SMatchAll, SMatchIQ, "d" -> deny end, Order = list_to_integer(SOrder), - MatchAll = SMatchAll == "1" orelse SMatchAll == "t", - MatchIQ = SMatchIQ == "1" orelse SMatchIQ == "t" , - MatchMessage = SMatchMessage == "1" orelse SMatchMessage == "t", - MatchPresenceIn = SMatchPresenceIn == "1" orelse SMatchPresenceIn == "t", - MatchPresenceOut = SMatchPresenceOut == "1" orelse SMatchPresenceOut == "t", + MatchAll = ejabberd_odbc:to_bool(SMatchAll), + MatchIQ = ejabberd_odbc:to_bool(SMatchIQ), + MatchMessage = ejabberd_odbc:to_bool(SMatchMessage), + MatchPresenceIn = ejabberd_odbc:to_bool(SMatchPresenceIn), + MatchPresenceOut = ejabberd_odbc:to_bool(SMatchPresenceOut), #listitem{type = Type, value = Value, action = Action, diff --git a/src/odbc/ejabberd_odbc.erl b/src/odbc/ejabberd_odbc.erl index 1b07fd6d9..4a6481525 100644 --- a/src/odbc/ejabberd_odbc.erl +++ b/src/odbc/ejabberd_odbc.erl @@ -39,6 +39,7 @@ sql_bloc/2, escape/1, escape_like/1, + to_bool/1, keep_alive/1]). %% gen_fsm callbacks @@ -161,6 +162,12 @@ escape_like($%) -> "\\%"; escape_like($_) -> "\\_"; escape_like(C) -> odbc_queries:escape(C). +to_bool("t") -> true; +to_bool("true") -> true; +to_bool("1") -> true; +to_bool(true) -> true; +to_bool(1) -> true; +to_bool(_) -> false. %%%---------------------------------------------------------------------- %%% Callback functions from gen_fsm