Separate debugging macros from testing
This commit is contained in:
@@ -1,14 +1,22 @@
|
|||||||
-ifdef(DEBUG).
|
-ifdef(DEBUG).
|
||||||
-include_lib("eunit/include/eunit.hrl"). %% for debugging macros
|
-include_lib("eunit/include/eunit.hrl"). %% for debugging macros
|
||||||
|
-define(dbg(Message), ?debugMsg(Message)).
|
||||||
|
-define(dbg(Format, Data), ?debugFmt(Format, Data)).
|
||||||
|
-define(dbgVal(Expr), ?debugVal(Expr)).
|
||||||
|
-define(dbgTime(Text, Expr), ?debugTime(Text, Expr)).
|
||||||
-else.
|
-else.
|
||||||
-ifdef(TEST).
|
-define(dbg(_Message), ok).
|
||||||
-include_lib("eunit/include/eunit.hrl"). %% for debugging macros
|
-define(dbg(_Format, _Data), ok).
|
||||||
-else.
|
-define(dbgVal(Expr), Expr).
|
||||||
-define(debugMsg(_Message), ok).
|
-define(dbgTime(_Text, Expr), Expr).
|
||||||
-define(debugFmt(_Format, _Data), ok).
|
%% -ifdef(TEST).
|
||||||
-define(debugVal(Expr), Expr).
|
%% -include_lib("eunit/include/eunit.hrl"). %% for debugging macros
|
||||||
-define(debugTime(_Text, Expr), Expr).
|
%% -else.
|
||||||
-endif.
|
%% -define(debugMsg(_Message), ok).
|
||||||
|
%% -define(debugFmt(_Format, _Data), ok).
|
||||||
|
%% -define(debugVal(Expr), Expr).
|
||||||
|
%% -define(debugTime(_Text, Expr), Expr).
|
||||||
|
%% -endif.
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
-define(NULL_ATOM, null).
|
-define(NULL_ATOM, null).
|
||||||
|
|||||||
@@ -494,7 +494,8 @@ handle_call(close, _From, State) ->
|
|||||||
Reply = ok,
|
Reply = ok,
|
||||||
{stop, normal, Reply, State};
|
{stop, normal, Reply, State};
|
||||||
handle_call(list_tables, _From, #state{port = Port} = State) ->
|
handle_call(list_tables, _From, #state{port = Port} = State) ->
|
||||||
Reply = exec(Port, {sql_exec, "select name from sqlite_master where type='table';"}),
|
SQL = "select name from sqlite_master where type='table';",
|
||||||
|
Reply = exec(Port, {sql_exec, SQL}),
|
||||||
TableList = proplists:get_value(rows, Reply),
|
TableList = proplists:get_value(rows, Reply),
|
||||||
TableNames = [erlang:list_to_atom(erlang:binary_to_list(Name)) || {Name} <- TableList],
|
TableNames = [erlang:list_to_atom(erlang:binary_to_list(Name)) || {Name} <- TableList],
|
||||||
{reply, TableNames, State};
|
{reply, TableNames, State};
|
||||||
@@ -621,7 +622,7 @@ create_port_cmd(Dbase) ->
|
|||||||
atom_to_list(?DRIVER_NAME) ++ " " ++ Dbase.
|
atom_to_list(?DRIVER_NAME) ++ " " ++ Dbase.
|
||||||
|
|
||||||
do_handle_sql_exec(SQL, #state{port = Port} = State) ->
|
do_handle_sql_exec(SQL, #state{port = Port} = State) ->
|
||||||
% ?debugFmt("~s~n", [SQL]),
|
?dbg("SQL: ~s~n", [SQL]),
|
||||||
Reply = exec(Port, {sql_exec, SQL}),
|
Reply = exec(Port, {sql_exec, SQL}),
|
||||||
{reply, Reply, State}.
|
{reply, Reply, State}.
|
||||||
|
|
||||||
@@ -637,20 +638,16 @@ wait_result(Port) ->
|
|||||||
receive
|
receive
|
||||||
%% Messages given at http://www.erlang.org/doc/reference_manual/ports.html
|
%% Messages given at http://www.erlang.org/doc/reference_manual/ports.html
|
||||||
{Port, Reply} ->
|
{Port, Reply} ->
|
||||||
% ?debugFmt("Reply: ~p~n", [Reply]),
|
% ?dbg("Reply: ~p~n", [Reply]),
|
||||||
Reply;
|
Reply;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
error_logger:error_msg("sqlite3 driver port closed with reason~p~n", [Reason]),
|
error_logger:error_msg("sqlite3 driver error: ~s~n", [Reason]),
|
||||||
% ?debugFmt("Error: ~p~n", [Reason]),
|
% ?dbg("Error: ~p~n", [Reason]),
|
||||||
{error, Reason};
|
{error, Reason};
|
||||||
{'EXIT', Port, Reason} ->
|
{'EXIT', Port, Reason} ->
|
||||||
error_logger:error_msg("sqlite3 driver port closed with reason ~p~n", [Reason]),
|
error_logger:error_msg("sqlite3 driver port closed with reason ~p~n", [Reason]),
|
||||||
% ?debugFmt("Error: ~p~n", [Reason]),
|
% ?dbg("Error: ~p~n", [Reason]),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
%% ;
|
|
||||||
%% _Else ->
|
|
||||||
%% io:format("Else: ~p~n", [_Else]),
|
|
||||||
%% _Else
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
parse_table_info(Info) ->
|
parse_table_info(Info) ->
|
||||||
@@ -691,7 +688,6 @@ build_primary_key_constraint(Tail, []) ->
|
|||||||
build_primary_key_constraint(Tail, Acc) ->
|
build_primary_key_constraint(Tail, Acc) ->
|
||||||
{{primary_key, lists:reverse(Acc)}, Tail}.
|
{{primary_key, lists:reverse(Acc)}, Tail}.
|
||||||
|
|
||||||
|
|
||||||
%% conflict_clause(["ON", "CONFLICT", ResolutionString | Tail]) ->
|
%% conflict_clause(["ON", "CONFLICT", ResolutionString | Tail]) ->
|
||||||
%% Resolution = case ResolutionString of
|
%% Resolution = case ResolutionString of
|
||||||
%% "ROLLBACK" -> rollback;
|
%% "ROLLBACK" -> rollback;
|
||||||
|
|||||||
Reference in New Issue
Block a user