Pass back errors in fetch steps to the caller

Constraint errors (e.g. foreign keys) can fail in the fetch phase of a
query. The library did not support error handling in the fetch phase yet.
This commit is contained in:
Arjan Scherpenisse
2014-06-15 09:18:07 +02:00
parent d860e0182c
commit c7c9421429

View File

@@ -123,6 +123,7 @@ foreach(F, Sql, Connection) ->
foreach_s(F, Statement) when is_function(F, 1) -> foreach_s(F, Statement) when is_function(F, 1) ->
case try_step(Statement, 0) of case try_step(Statement, 0) of
'$done' -> ok; '$done' -> ok;
{error, _} = E -> F(E);
{row, Row} -> {row, Row} ->
F(Row), F(Row),
foreach_s(F, Statement) foreach_s(F, Statement)
@@ -131,6 +132,7 @@ foreach_s(F, Statement) when is_function(F, 2) ->
ColumnNames = column_names(Statement), ColumnNames = column_names(Statement),
case try_step(Statement, 0) of case try_step(Statement, 0) of
'$done' -> ok; '$done' -> ok;
{error, _} = E -> F([], E);
{row, Row} -> {row, Row} ->
F(ColumnNames, Row), F(ColumnNames, Row),
foreach_s(F, Statement) foreach_s(F, Statement)
@@ -145,6 +147,7 @@ foreach_s(F, Statement) when is_function(F, 2) ->
map_s(F, Statement) when is_function(F, 1) -> map_s(F, Statement) when is_function(F, 1) ->
case try_step(Statement, 0) of case try_step(Statement, 0) of
'$done' -> []; '$done' -> [];
{error, _} = E -> F(E);
{row, Row} -> {row, Row} ->
[F(Row) | map_s(F, Statement)] [F(Row) | map_s(F, Statement)]
end; end;
@@ -152,6 +155,7 @@ map_s(F, Statement) when is_function(F, 2) ->
ColumnNames = column_names(Statement), ColumnNames = column_names(Statement),
case try_step(Statement, 0) of case try_step(Statement, 0) of
'$done' -> []; '$done' -> [];
{error, _} = E -> F([], E);
{row, Row} -> {row, Row} ->
[F(ColumnNames, Row) | map_s(F, Statement)] [F(ColumnNames, Row) | map_s(F, Statement)]
end. end.
@@ -161,6 +165,7 @@ map_s(F, Statement) when is_function(F, 2) ->
fetchone(Statement) -> fetchone(Statement) ->
case try_step(Statement, 0) of case try_step(Statement, 0) of
'$done' -> ok; '$done' -> ok;
{error, _} = E -> E;
{row, Row} -> Row {row, Row} -> Row
end. end.
@@ -170,6 +175,7 @@ fetchall(Statement) ->
case try_step(Statement, 0) of case try_step(Statement, 0) of
'$done' -> '$done' ->
[]; [];
{error, _} = E -> E;
{row, Row} -> {row, Row} ->
[Row | fetchall(Statement)] [Row | fetchall(Statement)]
end. end.