next up previous
Next: Reading records Up: Module irpr_kappa(irpr_kappa.kl1) Previous: Execution of messages

Searching for records

The searching procedure for records is as follows.

The first argument "SearchType" of search_data/6 shown below is one of these atoms, i.e. current, history and all which specifies the table(s) to search.

search_data(SearchType, Search_cond, ComStatus, Status)-IFP :-
    get_table_list(read, Tables),
    IFP <= begin_transaction(Tables,[],Status1),
    search_data1(SearchType,Status1,Search_cond,VLS,ComStatus0)-IFP,
    IFP <= close(Status),
    ComStatus0 = normal,
    ComStatus = normal(VLS).

Here, pay attention to the fact that VLS(ValueListStream) is returned as an argument of the command status "ComStatus". This "VLS" is related to the control of reading records mentioned in the next section.

The next program is where a search condition allowed in irpr is transformed into Kappa formula and searching is done by irpr_select:select/6.

search1(TableName,Search_cond,Set,Status)-IFP :-
    irpr_select:select(TableName,Search_cond,Set1,Status1)-IFP,
    search2(Status1,TableName,{Set1,_Set1},Set,Status)-IFP.

% The following is extracted from module irpr_select(irpr_select.kl1).
select(TableName,Cond,Set,Status)-IFP :-
    conv_cond(Cond,normal,R,TableName,Status1)-IFP,  % converts the condition
    exec_select(R,Status1,TableName,Set,Status)-IFP. % selects records

exec_select(index(Cond),normal,TableName,Set,Status)-IFP :-
    IFP <= search_index(TableName,Cond,Set,Status).
exec_select(data(Cond),normal,TableName,Set,Status)-IFP :-
    IFP <= search_data(TableName,Cond,Set,Status).
exec_select(data_set(Set1,Cond),normal,TableName,Set,Status)-IFP :-
    IFP <= search_data(TableName,{Set1,_},Cond,Set,Status).
exec_select(mix(ICond,DCond),normal,TableName,Set,Status)-IFP :-
    IFP <= search_index(TableName,ICond,Set1,Status1),
    exec_select(data_set(Set1,DCond),Status1,TableName,Set,Status)-IFP.
otherwise.
exec_select(_R,PStatus,_TableName,Set,Status)-IFP :-
    Set = {},
    Status = PStatus.