improved does_match by Brieuc

This commit is contained in:
duboissim 2024-03-14 18:40:16 +01:00
parent d40cbb70df
commit b6df1b1ade
1 changed files with 22 additions and 14 deletions

View File

@ -159,19 +159,28 @@ delete(Table, Conds) :-
). ).
does_match([], _, Row) :- !. does_match([], _, _) :- !.
does_match([Cond|Rest], Table, Row) :- does_match([Cond|Rest], Table, Row) :-
% Extract the operator, field and value from the condition % Extract the operator, field and value from the condition
Cond =.. [Operator | T], Cond =.. [Operator | T],
[+F, S] = T, [+F, S] = T,
tabl(Table, Cols), % Get the columns of the table
member(F, Cols), tabl(Table, Cols),
nth0(Index, Cols, F),
nth0(Index, Row, Value), % Get the index of the field in the columns
apply(Operator, [Value, S]), member(F, Cols),
does_match(Rest, Table, Row). nth0(Index, Cols, F),
% Get the value of the field in the row
nth0(Index, Row, Value),
% Apply the operator to the value and the selector
apply(Operator, [Value, S]),
% Check the next condition
does_match(Rest, Table, Row).
:- dynamic selec/4. :- dynamic selec/4.
/* /*
@ -229,8 +238,7 @@ selector(Row, Cols, [+Selector|Selectors], AccCols, AccVals, ColumnNames, Column
%go to next column tho evaluate %go to next column tho evaluate
selector(Row, Cols, Selectors, [Selector|AccCols], [Value|AccVals], ColumnNames, ColumnValue) selector(Row, Cols, Selectors, [Selector|AccCols], [Value|AccVals], ColumnNames, ColumnValue)
; ;
string_concat(Selector, " isn't a column of table ", X), string_concat(Selector, " isn't a column of table ", Error),
string_concat(X, Table, Error),
throw(Error) throw(Error)
). ).