Fix select for non existing or empty tables
This commit is contained in:
parent
1e89e0f6b7
commit
cacda5594a
16
solution.pl
16
solution.pl
|
@ -233,6 +233,17 @@ For example:
|
|||
findall(Values, selec(persons,[+id,+first],[],Values), Projections)
|
||||
returns: Projections = [[0, "Jeffrey"], [1, "Lorena"], [2, "Joseph"], ...
|
||||
*/
|
||||
selec(Table, _, _, _) :-
|
||||
\+ tabl(Table, _),
|
||||
throw("Table doesn't exist"),
|
||||
!.
|
||||
|
||||
selec(Table, _, _, _) :-
|
||||
tabl(Table, Cols),
|
||||
length(Cols, L),
|
||||
\+ current_predicate(Table/L),
|
||||
!.
|
||||
|
||||
selec(Table, Selector, Cond, Projection) :-
|
||||
tabl(Table, Cols),
|
||||
row(Table, R),
|
||||
|
@ -246,8 +257,6 @@ selec(Table, *, Cond, Projection) :-
|
|||
does_match(Cond, Table, R),
|
||||
Projection = Cols/R.
|
||||
|
||||
%base case
|
||||
selector(_,_,[],ColumnNames, ColumnValue, ColumnNames, ColumnValue):-!.
|
||||
/**
|
||||
* Row: A row from the table
|
||||
* Cols: name of the column of the table
|
||||
|
@ -257,6 +266,9 @@ selector(_,_,[],ColumnNames, ColumnValue, ColumnNames, ColumnValue):-!.
|
|||
* ColumnNames: List returning the column(s) name(s)
|
||||
* ColumnValue: List returning the row values for each column
|
||||
*/
|
||||
|
||||
selector(_,_,[],ColumnNames, ColumnValue, ColumnNames, ColumnValue):-!.
|
||||
|
||||
selector(Row, Cols, [+Selector|Selectors], AccCols, AccVals, ColumnNames, ColumnValue):-
|
||||
(member(Selector, Cols) ->
|
||||
%find the value corresponding to the column in the row
|
||||
|
|
Loading…
Reference in New Issue