Cleaner error handling
This commit is contained in:
@@ -115,15 +115,17 @@ static int control(ErlDrvData drv_data, unsigned int command, char *buf,
|
||||
|
||||
static inline int return_error(sqlite3_drv_t *drv, const char *error,
|
||||
ErlDrvTermData **spec, int *term_count) {
|
||||
*spec = (ErlDrvTermData *) calloc(7, sizeof(ErlDrvTermData));
|
||||
(*spec)[0] = ERL_DRV_ATOM;
|
||||
(*spec)[1] = drv->atom_error;
|
||||
(*spec)[2] = ERL_DRV_STRING;
|
||||
(*spec)[3] = (ErlDrvTermData) error;
|
||||
(*spec)[4] = strlen(error);
|
||||
(*spec)[5] = ERL_DRV_TUPLE;
|
||||
(*spec)[6] = 2;
|
||||
*term_count = 7;
|
||||
*spec = (ErlDrvTermData *) malloc(9 * sizeof(ErlDrvTermData));
|
||||
(*spec)[0] = ERL_DRV_PORT;
|
||||
(*spec)[1] = driver_mk_port(drv->port);
|
||||
(*spec)[2] = ERL_DRV_ATOM;
|
||||
(*spec)[3] = drv->atom_error;
|
||||
(*spec)[4] = ERL_DRV_STRING;
|
||||
(*spec)[5] = (ErlDrvTermData) error;
|
||||
(*spec)[6] = strlen(error);
|
||||
(*spec)[7] = ERL_DRV_TUPLE;
|
||||
(*spec)[8] = 3;
|
||||
*term_count = 9;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -716,13 +716,13 @@ exec(Port, {sql_exec, Cmd}) ->
|
||||
wait_result(Port) ->
|
||||
receive
|
||||
%% Messages given at http://www.erlang.org/doc/reference_manual/ports.html
|
||||
{Port, Reply} ->
|
||||
% ?dbg("Reply: ~p~n", [Reply]),
|
||||
Reply;
|
||||
{error, Reason} ->
|
||||
{Port, error, Reason} ->
|
||||
error_logger:error_msg("sqlite3 driver error: ~s~n", [Reason]),
|
||||
% ?dbg("Error: ~p~n", [Reason]),
|
||||
{error, Reason};
|
||||
{Port, Reply} ->
|
||||
% ?dbg("Reply: ~p~n", [Reply]),
|
||||
Reply;
|
||||
{'EXIT', Port, Reason} ->
|
||||
error_logger:error_msg("sqlite3 driver port closed with reason ~p~n", [Reason]),
|
||||
% ?dbg("Error: ~p~n", [Reason]),
|
||||
|
||||
@@ -56,16 +56,17 @@ basic_functionality() ->
|
||||
Columns = ["id", "name", "age", "wage"],
|
||||
AllRows = [{1, <<"abby">>, 20, 2000}, {2, <<"marge">>, 30, 2000}],
|
||||
AbbyOnly = [{1, <<"abby">>, 20, 2000}],
|
||||
TableInfo = [{id, integer, [primary_key]}, {name, text}, {age, integer}, {wage, integer}],
|
||||
drop_all_tables(ct),
|
||||
?assertEqual(
|
||||
[],
|
||||
sqlite3:list_tables(ct)),
|
||||
{ok, TableId} = sqlite3:create_table(ct, user, [{id, integer, [primary_key]}, {name, text}, {age, integer}, {wage, integer}]),
|
||||
{ok, TableId} = sqlite3:create_table(ct, user, TableInfo),
|
||||
?assertEqual(
|
||||
[user],
|
||||
sqlite3:list_tables(ct)),
|
||||
?assertEqual(
|
||||
[{id, integer, [primary_key]}, {name, text}, {age, integer}, {wage, integer}],
|
||||
TableInfo,
|
||||
sqlite3:table_info(ct, user)),
|
||||
?assertEqual(
|
||||
{id, 1},
|
||||
|
||||
Reference in New Issue
Block a user