% vb : foreig_key_ema.txt
% clauses
% forey_key_ema("rene@hsw.nl","0010000","4961091119").
% vb : foreig_key_map.txt
% forey_key(20191109184320,"0010000","4961091119").
% MOETEN DUS WEL per Db assertene ivm multi thread !!??
% dus dit, :- thread_local forey_keyi_ema/5.
% dus dit nog voeg in de windows versie, pos for key found stond fout op 3
% deze 2 evt nog via db en dynamic
% digi_to_zkey( Dig, Leng, Key )
% :- thread_local forey_keyi_ema/5.
:- thread_local forey_keyi_ema/3.
% :- thread_local forey_keyi/5.
:- thread_local forey_keyi/3.
% :- thread_local match_line/1.
:- dynamic match_line/4.
:- dynamic start_posit_kpos/4.
:- dynamic startp_ag_roos/3.
% deze ook nog per db en dynamic
:- thread_local match_id_line/2.
:- thread_local pos_for_key_found/2.
:- thread_local last_pos_key/2.
:- thread_local app_id_data/3.
:- thread_local key_for_pos_found/1.
:- dynamic mem_modif_agd/5.
:- dynamic ag_m_rec/4.
:- dynamic mmdf_ag_del/3.
:- dynamic can_remove/2.
:- thread_local ag_id_data/2.
% deze dus dynamic moet ook , per dbnummer
is_windos('c:', "c:"):- current_prolog_flag(home, Pa), sub_atom(Pa, 0, _, _, 'c:'),!.
is_windos('d:', "d:"):- current_prolog_flag(home, Pa), sub_atom(Pa, 0, _, _, 'd:'),!.
is_windos('e:', "e:"):- current_prolog_flag(home, Pa), sub_atom(Pa, 0, _, _, 'e:'),!.
osdir_a(D, D2):- is_windos(At, _), atom_concat(At, D, D2),!.
osdir_a(D, D2):- sub_atom(D, Sta, Le, Aft, '/xampp/htdocs/'), Y is Sta + Le,
sub_atom(D, Y, Aft, _, Rs), atom_concat('/var/www/html/', Rs, D2),!.
osdir_a(D, D):- !.
% osdir_a(D, D2):- sub_atom(D, Sta, Le, Aft, '/xampp/htdocs/'), Y is Sta + Le, sub_atom(D, Y, Aft, _, Rs),
% atom_concat('/var/www/html/', Rs, D2),!.
osdir_s(D, D2):- is_windos(_, S), string_concat(S, D, D2),!.
osdir_s(D, D2):- sub_string(D, Sta, Le, Aft, "/xampp/htdocs/"), Y is Sta + Le,
sub_string(D, Y, Aft, _, Rs), atom_concat("/var/www/html/", Rs, D2),!.
osdir_s(D, D):- !.
ossla('\\'):- is_windos(_, _) , !.
ossla('/'):-!.
js_file_cfgrec_at(Fnabs):- !, osdir_a('/xampp/htdocs/gymapp/', Osd), atom_concat(Osd, 'app2cfg_rec.js', Fnabs),!.
js_file_dclog_at(Fnabs):- !, osdir_a('/xampp/htdocs/', Osd), atom_concat(Osd, 'dclog.js', Fnabs),!.
% i,i,o
db_file_abs_at(Dbnat, Filen_at, Fnabs_at ):- osdir_a('/rdb_tempv6/dbd/', Osd),
atomic_list_concat([Osd, Dbnat, '/', Filen_at, '.txt' ], Fnabs_at ), !.
db_key_file_abs_at(Dbnat, Tbn, Fn, Fnabs_at ):- osdir_a('/rdb_tempv6/dbd/', Osd),
atomic_list_concat([Osd, Dbnat, '/',Tbn, '_',Fn, '.txt' ], Fnabs_at ),!.
docvals_file( Db, 'trai', Fnabs ):- !, db_file_abs_at(Db, 'docvals', Fnabs ).
docvals_file( Db, Tag, Fnabs ):- atom_length(Tag, Tle), Tle > 0, !, atomic_list_concat(['docvals_', Tag], Fitag), db_file_abs_at(Db, Fitag, Fnabs ).
docvals_file( _, _, 'cantmakefilename' ):- !.
% i,i,i,o
docvals_key_file( Db, trai, Fnabs ):- !, db_file_abs_at(Db, 'docvals_key', Fnabs ).
docvals_key_file( Db, Tag, Fnabs ):- atom_length(Tag, Tle), Tle > 0, !, atomic_list_concat(['docvals_key_', Tag], Fitag), db_file_abs_at(Db, Fitag, Fnabs ).
docvals_key_file( _, _, 'cantmakefilename' ):- !.
% seek position
% stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, ChaCount),
% record_file_last_matchwc_record(
asser_match_line(Dbi, Ftp, Sx, EmxStr, Chacou):- sub_string(Sx, _,_,_, EmxStr),!, retractall(match_line(Dbi, Ftp, _,_)), assert(match_line(Dbi, Ftp, Sx, Chacou)).
asser_match_line(_, _, _, _, _):- !.
%--
% deze is allemaal unico le , dwz moet zijn
% HIER NOG check dat het geen float is ( kan niet alles alles bormaal verloppt )
% write("bb1-"), write(Pos2),
% record_file_last_matchwc_record(Sea, "get_path_db("),
% close(Sea),
% start_posit_kpos
set_msucce_pos(Dbi, Kif, _Lpos):- startp_ag_roos(Dbi, Kif, _),!.
set_msucce_pos(Dbi, Kif, Lpos):- assert( startp_ag_roos(Dbi, Kif, Lpos) ),!.
% mark_seek
% hier klopt dus niet , je moet allemaal opvragen en dan de hoogste nemen
% nu dus gemaakt
% je kan bij voegen
% mark_seek
% dit was de laatste , nu met beter
%set_start_pos_roosdata(Dbi, Sea, Kif):- startp_ag_roos(Dbi, Kiv, Pox), Kif >= Kiv,
% Pox > 0, Px2 is Pox / 2, seek(Sea, Px2, bof, _), !.
%set_start_pos_roosdata(_, _, _):- !.
startp_ag_smallt(Dbi, Kif, Kis ):- startp_ag_roos(Dbi, Kis, _), Kif >= Kis.
set_start_pos_roosdata(Dbi, Sea, Kif):-
% write("-aa-"), nl,
findall(Kis, startp_ag_smallt(Dbi, Kif, Kis ), Kil),
length(Kil, Lx), Lx > 0, sort(0, @>, Kil, Kil2), nth0(0, Kil2, Fel,_),
startp_ag_roos(Dbi, Fel, Pox),
Pox > 0, Px2 is Pox / 2, seek(Sea, Px2, bof, _),
write("snel start pos "),
% write_term(Kil2, []),
write(Px2), nl, !.
set_start_pos_roosdata(_, _, _):- !.
% mark_seek
fset_start_position(Dbi, is_unico, Ftp, Sea, Zktag_s):- Dbi > 0, Ftp < 21, match_line(Dbi, Ftp, Zktag_s, Pox),
Pox > 0, Px2 is Pox / 2, seek(Sea, Px2, bof, _), !.
fset_start_position(Dbi, is_ut8, Ftp, Sea, Zktag_s):- Dbi > 0, Ftp < 21, match_line(Dbi, Ftp, Zktag_s, Pox),
Pox > 0, seek(Sea, Pox, bof, _), !.
fset_start_position(_, _, _, _, _):- !.
% deze is alt unico_le dacht ik
get_nth_or_last(Num, Posils, Elx):- length(Posils, Le), Le > Num, nth1(Num, Posils, Elx),!.
get_nth_or_last(_, Posils, Elx):- length(Posils, Le), nth1(Le, Posils, Elx),!.
% HIJ moet meteen per DB, thread_local werkt niet meteen snel en goed
% start_posit_kpos en match_line moet dynamci worden
% mark_seek
fset_start_posit_kposis(Dbi, Ftp, Sea, Zktag_s):- Dbi > 0, Ftp < 21, start_posit_kpos(Dbi, Ftp, Zktag_s, Pox),
Pox > 0, Px2 is Pox / 2, seek(Sea, Px2, bof, _), !.
fset_start_posit_kposis(_, _, _, _):- !.
% deze 2 horen bij elkaar
to_mem_search_start_pos_keyf(Fnabs_key_at, KeyStr, Keyspl1, Keyspl2):-
path_read_dbi( Fnabs_key_at, Dbi),
fsearch_type(Fnabs_key_at, Ftype),
append(Keyspl1, Keyspl2, Posis), length(Posis, Ple), Ple > 1,
sort(0, @>, Posis, Posi2),
get_nth_or_last(40, Posi2, Pox),!, retractall( start_posit_kpos(Dbi, Ftype, KeyStr, _)),
assert( start_posit_kpos(Dbi, Ftype, KeyStr, Pox)).
to_mem_search_start_pos_keyf(_, _, _, _):- !.
% fset_start_posit_kposis(Ftype, Sea, KeyStr),
% die 2 zijn bij elkaar dus alle gevonden key posities
% dan eigenlijk union laten maken van die 2
% sorteer die van hoog naar laag, neem de voorste 20 of 40 , dan neem je het 40 ste element of de laatste als het er geen 40 zijn
% die positie wordt de start_positie in de file voor die zoekstring
% later nog per db en dan dynamisch ivm local thread
% to_mem_search_start_pos_keyf(Fnabs_key_at, KeyStr, Keyspl1, Keyspl2).
% fsearch_type(Fnabs_key_at, Ftype),
% deze willen we ook doen in strght_profi utf8
% daar staat hij als rvvessum@gmail.com;0300033 dus gebruik puntkomma
% en dan het front stuk als email string geef
%
% asser_match_id(Id, Emads):- match_id_line(Id, Emads),!.
% asser_match_id(Id, Emads):- assert(match_id_line(Id, Emads)).
asser_match_id(Id, Emads):- % match_id_line(Id, Emads),!.
retractall(match_id_line(Id, _)),
assert(match_id_line(Id, Emads)).
%--- deze toegevoe lees em data uit strght
asser_match_strght_li(Sx, Idlis):-
member(Id, Idlis),
digi_to_zkey(Id, 7, Keys),
string_concat(";", Keys, C1), sub_string(Sx, Start, _Leng, _, C1),
sub_string(Sx, 0, Start, _, Emads), !,
asser_match_id(Id, Emads).
% retractall(match_id_line(Id, _)),
% assert(match_id_line(Id, Emads)).
asser_match_strght_li(_, _):- !.
find_strght_acc_all_esea(Sea, Idlis):- not( at_end_of_stream(Sea) ), read_line_to_string(Sea, Sx),!,
asser_match_strght_li(Sx, Idlis), find_strght_acc_all_esea(Sea, Idlis).
find_strght_acc_all_esea(_, _):- !.
find_strght_acc_all_em(Fnabs, Idlis, Slilis, Idsuclis):-
exists_file(Fnabs), !,
retractall(match_id_line(_,_)),
open(Fnabs, read, Sea, [encoding(utf8)]),
find_strght_acc_all_esea(Sea, Idlis),
close(Sea),
findall( Idsuc, match_id_line(Idsuc, _), Idsuclis),
findall( Sline, match_id_line(_, Sline), Slilis),!.
find_strght_acc_all_em( _, _, [], []):- !.
%--- tot hier toegevoe lees em data uit strght
str_remove_last_spa(Em, Es ):- string_length( Em, Le), Y is Le - 1,
string_code(Le, Em, Co), Co = 32, sub_string(Em, 0, Y, _, Es), !.
str_remove_last_spa(Em, Em ):-!.
asser_match_allid_line(Sx, Idlis):- member(Id, Idlis), digi_to_zkey(Id, 7, Keys), string_concat("webnumber=", Keys, C1),
sub_string(Sx, _,_,_, C1), param_val(Sx, "emailad", Ema0), !,
str_remove_last_spa(Ema0, Emads ),
asser_match_id(Id, Emads).
% retractall(match_id_line(Id, _)),
% assert(match_id_line(Id, Emads)).
asser_match_allid_line(_, _):- !.
str_to_number_def(Wcs, Wcn):- number_string(Wcn, Wcs),!.
str_to_number_def(_, 0):- !.
%20200430143011;webcode=4143160320&webnumber=0010000&emailad=kareltje66@hsw.nl
%20200430143011;webcode=4143160320&webnumber=0010000&emailad=kareltje66@hsw.nl
asser_app_line(Wn, Wc, _):- retract( app_id_data(Wn, Wc, _) ), fail, !.
asser_app_line(Wn, Wc, Ema):- !, assert( app_id_data(Wn, Wc, Ema) ).
give_app_line_mems():- app_id_data(Wn, Wc, Ema), write(Wn), write(";"), write(Wc), write(";"), write(Ema), nl, fail,!.
give_app_line_mems():- !.
app_line_to_mem(Sx):- string_length(Sx, Le), Y is Le - 60,
sub_string(Sx, 23, 10, _, Webcos), number_string(Wc, Webcos),
sub_string(Sx, 44, 7, _, Webnus), number_string(Wn, Webnus),
sub_string(Sx, 60, Y, _, Ema),!,
asser_app_line(Wn, Wc, Ema).
app_line_to_mem(_):- !.
match_allids(_, Zks):- string_length(Zks, Le), Le = 0,!.
match_allids(Sx, Zks):- sub_string(Sx, _,_,_, Zks),!.
asser_match_allid_app(Sx, Zks):- match_allids(Sx, Zks),
split_string(Sx, ";", "", Li), nth0(1, Li, RecStr ),
param_val(RecStr, "emailad", Emx),
param_val(RecStr, "webcode", Wc), str_to_number_def(Wc, Wcn),
param_val(RecStr, "webnumber", Wn), str_to_number_def(Wn, Wnn),
asser_app_line(Wnn, Wcn, Emx),
!.
% split_string
asser_match_allid_app(_, _):-!.
% match
record_file_allid_app_ema(Sea, Zk):- not( at_end_of_stream(Sea) ), read_line_to_string(Sea, Sx),!,
asser_match_allid_app(Sx, Zk), record_file_allid_app_ema(Sea, Zk).
record_file_allid_app_ema( _ , _):- !.
% webnumber=0010000
% position
% stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, ChaCount),
% read_line_str(Sea, Sx, ChaCount)
record_file_last_matchwc_record(Dbi, Sea, EmxStr, Ftp):- not( at_end_of_stream(Sea) ),
% read_line_to_string(Sea, Sx),!,
read_line_str(Sea, Sx, ChaCount),!,
asser_match_line(Dbi, Ftp, Sx, EmxStr, ChaCount), record_file_last_matchwc_record(Dbi, Sea, EmxStr, Ftp).
record_file_last_matchwc_record(_, _, _, _):- !.
%----
record_file_allid_matchwc_record(Sea, Idlis):- not( at_end_of_stream(Sea) ), read_line_to_string(Sea, Sx),!,
asser_match_allid_line(Sx, Idlis), record_file_allid_matchwc_record(Sea, Idlis).
record_file_allid_matchwc_record(_, _):- !.
% deze waarsch ook niet gebruikt
record_file_allapp_key_data_mem(Sea):- not( at_end_of_stream(Sea) ), read_line_to_string(Sea, Sx),!,
app_line_to_mem(Sx),
record_file_allapp_key_data_mem(Sea).
record_file_allapp_key_data_mem(_):- !.
% emailad
% hier moet dus lock( read ) , bij dat zorgt dat anderen alleen niet kunnen schrijven, wel lezen , zonder lockt hij niks
% hier nog close on abort bij
% match_id_line
fsearch_type(Fna, 1):- sub_atom(Fna, _,_,_, '.js'),!.
fsearch_type(Fna, 2):- sub_atom(Fna, _,_,_, 'docvals_app'),!.
fsearch_type(Fna, 3):- sub_atom(Fna, _,_,_, 'docvals_fit'),!.
fsearch_type(Fna, 4):- sub_atom(Fna, _,_,_, 'docvals_voe'),!.
fsearch_type(Fna, 5):- sub_atom(Fna, _,_,_, 'docvals.txt'),!.
fsearch_type(Fna, 6):- sub_atom(Fna, _,_,_, 'docvals_key.txt'),!.
fsearch_type(Fna, 7):- sub_atom(Fna, _,_,_, 'docvals_key_app'),!.
fsearch_type(Fna, 8):- sub_atom(Fna, _,_,_, 'docvals_key_fit'),!.
fsearch_type(Fna, 9):- sub_atom(Fna, _,_,_, 'docvals_key_voe'),!.
fsearch_type(_Fna, 21):- !.
% fset_start_position
% deze nog apart maak zonder gedeeeld door 2 bij unicode length en dus ook test
check_exist_acc_in_js_line(Fnapp2cfg, Accstr, "success", Cx ):- exists_file(Fnapp2cfg),!,
path_read_dbi(Fnapp2cfg, Dbi),
fsearch_type(Fnapp2cfg, Ftype),
open(Fnapp2cfg, read, Sea, [encoding(utf8) ]),
% je kan hier de dbi uit pad lezen van Fnabs
% fset_start_position(Dbi, is_ut8, Ftype, Sea, "get_path_db("),
retractall(match_line(Dbi, Ftype, _,_)), assert(match_line(Dbi, Ftype, "", 0)),
% je kan hier de dbi uit pad lezen van Fnabs
record_file_last_matchwc_record(Dbi, Sea, "get_path_db(", Ftype),
close(Sea), match_line(Dbi, Ftype, ReclineStr, _),
sub_string(ReclineStr,_,_,_, Accstr),
string_concat(Fnapp2cfg, Accstr, Cx ),
!.
check_exist_acc_in_js_line(Fnstr, Accs, "is faal", Cx ):- string_concat(Fnstr, Accs, Cx ), !.
%---
find_record_file_last_matchwc_record(Fnabs, EmxStr, ReclineStr):- exists_file(Fnabs),!,
% write(" exist file "), write(Fnabs),
path_read_dbi(Fnabs, Dbi),
fsearch_type(Fnabs, Ftype),
open(Fnabs, read, Sea, [encoding(unicode_le)]),
% je kan hier de dbi uit pad lezen van Fnabs
fset_start_position(Dbi, is_unico, Ftype, Sea, EmxStr),
retractall(match_line(Dbi, Ftype, _,_)), assert(match_line(Dbi, Ftype, "", 0)),
% je kan hier de dbi uit pad lezen van Fnabs , moet meegeef in record_file_last_matchwc_record
record_file_last_matchwc_record(Dbi, Sea, EmxStr, Ftype),
close(Sea), match_line(Dbi, Ftype, ReclineStr, _),!.
%--
% 20200914200511;webcode=4272719002&webnumber=0010378&emailad=merlincoenraad@gmail.com
%
% 20200914200511;webcode=4272719002&webnumber=0010378&emailad=merlincoenraad@gmail.com
%
% 20200819102005;webcode=9371508002&webnumber=0010299&emailad=anjaenjo32@gmail.com
%
% 20200710135840;webcode=2602528002&webnumber=0010328&emailad=peetvande@gmail.com
%
% 20200710135840;webcode=2602528002&webnumber=0010328&emailad=peetvande@gmail.com
%
%20200918080508;webcode=&webnumber=&emailad=marij.van.erp@upcmail.nl
% 20200918080508;webcode=6342925002&webnumber=0010081&emailad=marij.van.erp@upcmail.nl
%
% app_id_data(Wn, Wc, Ema)
% find_record_file_all_app_ema(Fnabs, Emalis, Idsuclis):
% dit hele stuk is funct voor zoek in ag data
asser_ag_line( Ema):- ag_id_data(Ema, _) , !.
asser_ag_line( Ema):- !, assert( ag_id_data( Ema, 0) ).
asser_match_allid_ag(Sx, Zks):- split_string(Sx, ";", "", Li),
string_length(Zks, Le), nth0(12, Li, Rsvnaam ),
trim(Rsvnaam, S2), string_lower(S2, S3),
( Le = 0 ; sub_string(S3, _,_,_, Zks) ), asser_ag_line( S3), !.
asser_match_allid_ag(_Sx, _Zks):- !.
record_file_allid_ag_ema(Sea, Zk):- not( at_end_of_stream(Sea) ), read_line_to_string(Sea, Sx),!,
asser_match_allid_ag(Sx, Zk), record_file_allid_ag_ema(Sea, Zk).
record_file_allid_ag_ema( _ , _):- !.
find_record_file_all_ag_ema(Fnabs, Zks, Emalis, Idsuclis):- sub_atom(Fnabs, _,_,_, '00009'), exists_file(Fnabs),!,
retractall( ag_id_data(_, _) ), open(Fnabs, read, Sea, [encoding(unicode_le)]),
record_file_allid_ag_ema( Sea, Zks ), close(Sea),
findall( Idsuc, ag_id_data(_,Idsuc), Idsuclis),
findall( Emastr, ag_id_data(Emastr, _), Emalis0), msort(Emalis0, Emalis),!.
find_record_file_all_ag_ema(_, _, [],[]):- !.
% deze lijkt er op find_record_file_all_mem_record
% hier dus ook de extra voor bij maak voor de strgt
find_record_file_all_app_ema(Fnabs, Zks, Emalis, Idsuclis):- exists_file(Fnabs),!, retractall( app_id_data(_, _, _) ),
% write(" exist file "), write(Fnabs),
open(Fnabs, read, Sea, [encoding(unicode_le)]),
record_file_allid_app_ema( Sea, Zks ),
close(Sea),
findall( Idsuc, app_id_data(Idsuc, _, _), Idsuclis),
findall( Emastr, app_id_data(_, _, Emastr), Emalis),!.
% en we moetn dus ook nu laten zoeken in strght_profi ivm dat men zelf account daar aanmaakt
% deze dus voor alle nums terug zoek uit appkey file , kan id zelf nog bij output
% deze ook utf8 nodig voor op te zoek in strght_profi
find_record_file_all_matchwc_record(Fnabs, Idlis, Slilis, Idsuclis):- exists_file(Fnabs),!, retractall(match_id_line(_,_)),
% write(" exist file "), write(Fnabs),
open(Fnabs, read, Sea, [encoding(unicode_le)]),
record_file_allid_matchwc_record(Sea, Idlis),
close(Sea),
findall( Idsuc, match_id_line(Idsuc, _), Idsuclis),
findall( Sline, match_id_line(_, Sline), Slilis), !.
% deze toegeveo na strght
find_record_file_all_matchwc_record( _, _, [], []):- !.
% deze nu deze wordt waarsch niet gebruikt bij get_xall_app_data
find_record_file_all_mem_record(Fnabs ):- exists_file(Fnabs),!, retractall(app_id_data(_,_,_)),
% write(" exist file "), write(Fnabs),
open(Fnabs, read, Sea, [encoding(unicode_le) ]),
record_file_allapp_key_data_mem(Sea),
close(Sea), !.
% als het een email adres is dan zoek in
% foreig_key_ema
% forey_key_ema("kees@hsw.nl","0010003","3644101219").
% cons_foreig_key_ema(Dba) via time_file
% eerste twee is input i,i, rest output
find_app_email_key_or_foreikey(Dbn, Emx, Appkey, RecStr, Wn, Wc, ""):- find_app_email_key_or_foreikey_f(Dbn, Emx, Appkey, RecStr, Wn, Wc),!.
% stond fout omdat Appkey output is
find_app_email_key_or_foreikey(_, Emx, "", " ", "0", "0", Emx):- !.
%---
find_app_email_key_or_foreikey_f(Dbn, Emx, Appkey, RecStr, Wn, Wc):- find_app_email_key(Dbn, Emx, Appkey, RecStr, Wn, Wc),!.
find_app_email_key_or_foreikey_f(Dba, Emx, Wn, " ", Wn, Wc):- cons_foreig_key_ema(Dba),!,
forey_keyi_ema(Emx, Wni, Wci), digi_to_zkey( Wni, 7, Wn ), digi_to_zkey( Wci, 10, Wc ).
% load
% 20200730100209;webcode=2523126002&webnumber=0010001&emailad=rene@hsw.nl
% hier extra functie maak erbij om vi appkey ophaal de email
find_appkey_email(Dbn, Appkey, Emx, RecStr, Wn, Wc):- string_length(Appkey, Le), Le > 3, db_file_abs_at(Dbn, 'docvals_app', Fnabs ), exists_file(Fnabs),
find_record_file_last_matchwc_record(Fnabs, Appkey, ReclineStr),
split_string(ReclineStr, ";", "", Li), nth0(1, Li, RecStr ),
param_val(RecStr, "emailad", Emx),
param_val(RecStr, "webcode", Wc), param_val(RecStr, "webnumber", Wn), !.
find_appkey_email(_, _, "","","",""):-!.
find_app_email_key(Dbn, Emx, Appkey, RecStr, Wn, Wc):- db_file_abs_at(Dbn, 'docvals_app', Fnabs ),
find_record_file_last_matchwc_record(Fnabs, Emx, ReclineStr),
split_string(ReclineStr, ";", "", Li), nth0(0, Li, Appkey ), nth0(1, Li, RecStr ),
param_val(RecStr, "webcode", Wc), param_val(RecStr, "webnumber", Wn), !.
%---
read_line_str(Sea, Sx, ChaCount):- stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, ChaCount),
read_line_to_string(Sea, Sx), Sx \= end_of_file, !.
read_line_str(_, "", 0):- !.
% key_2lines_read(Sea, Lpos1, Keystr, Num, Lpos2, Keystr2, Num2 ):- !, read_line_str(Sea, Sx1, Lpos1), read_line_str(Sea, Sx2, Lpos2),
% key_line_parse(Sx1, Keystr, Num), key_line_parse(Sx2, Keystr2, Num2).
key_1lines_read(Sea, Lpos1, Keystr, Num ):- !, read_line_str(Sea, Sx1, Lpos1), key_line_parse(Sx1, Keystr, Num).
%---
% asser_non_zero_keyfou(_, _, 0):- !.
% asser_non_zero_keyfou(1, Lpo, Frcp):- !, assert( pos_for_key_found( Lpo, Frcp )).
% find_previous_for_first( Frcpos, LposPv, Frcpos):- last_pos_key(LposPv, Frcpos),!.
% find_previous_for_first( _, 0, 0):- !.
find_previous_for(1, Frcpos1 ):- last_pos_key(LposPv, Frcpos1),!, asserta(pos_for_key_found( LposPv, Frcpos1 )).
find_previous_for(_, _ ):-!.
match_key_line_poskey(Frecpos, Kfinds, 1):- number_string(Nux, Kfinds), Nux = Frecpos,!.
match_key_line_poskey(_, _, 0):-!.
match_key_line_key(Kstr, Kfinds, Kfle, 1):- string_length(Kstr, Le), Le = Kfle, Kstr = Kfinds,!.
% match_key_line_key(Sx, _, _, 1):- atom_string(A, Sx), A = '0010002',!.
match_key_line_key(_, _, _, 0):-!.
%--
update_poskey(1, Keystr):- !, assert( key_for_pos_found( Keystr ) ).
% update_poskey(0, Keystr):- !, assert( pos_for_key_found( Lpo, Frcpos ) ), !.
update_poskey(_, _):- !.
%---
% HIER OP asserta gezet !!
update_last_key(1, Lpos, Frcpos):- !, retractall(last_pos_key( _, _)), assert(last_pos_key(Lpos, Frcpos)), asserta( pos_for_key_found( Lpos, Frcpos ) ).
update_last_key(0, Lpo, Frcpos):- retract( last_pos_key(_, Frcpos)),!, asserta( pos_for_key_found( Lpo, Frcpos ) ), !.
% update_last_key(0, Lpo, Frcpos):- !, assert( pos_for_key_found( Lpo, Frcpos ) ), !.
update_last_key(_, _, _):- !.
% update_last_key(0, Lpo, Frcpos):- assert(last_pos_key(Lpo, Frcpos)), !.
find_key_file_poskeys2(Sea, Cou, KeyStrFi):- not( at_end_of_stream(Sea) ),!,
key_1lines_read(Sea, _Lpos1, Keystr, Frcpos1),
match_key_line_poskey(Frcpos1, KeyStrFi, Matchresu1), % Matchresu1 = 1,!,
update_poskey(Matchresu1, Keystr),
Cou2 is Cou + 1, find_key_file_poskeys2(Sea, Cou2, KeyStrFi).
find_key_file_poskeys2(_, _, _):- !.
% deze is die overal gebruikt wordt met docs voor id, wordt ook voor de app vals gebruikt
find_key_file_key_pos2(Sea, Cou, KeyStrFi, Keyle):- not( at_end_of_stream(Sea) ),!,
% key_2lines_read(Sea, Lpos1, Keystr, Frcpos1, Lpos2, Keystr2, Frcpos2),
key_1lines_read(Sea, Lpos1, Keystr, Frcpos1),
match_key_line_key(Keystr, KeyStrFi, Keyle, Matchresu1), % Matchresu1 = 1,!,
update_last_key(Matchresu1, Lpos1, Frcpos1),
Cou2 is Cou + 1, find_key_file_key_pos2(Sea, Cou2, KeyStrFi, Keyle).
%find_key_file_key_pos2(Sea, Cou, Keyat, Atle):- not( at_end_of_stream(Sea) ),!, Cou2 is Cou + 1, find_key_file_key_pos2(Sea, Cou2, Keyat, Atle).
find_key_file_key_pos2(_, _, _, _):- !.
% find_previous_for_first( Frcpos1, Lpo_prv, Frc_prvpos),
% find_previous_for(Matchresu1, Frcpos1 ),
% match_key_line_key(Keystr2, Keyat , Atle, Matchresu2),
% ( Matchresu1 = 1 ; Matchresu2 = 1 ), !,
% ( Matchresu1 = 1 ; Matchresu2 = 1 ), !,
% find_previous_for_first( Frcpos1, Lpo_prv, Frc_prvpos), update_last_key(Lpos2, Frcpos2),
% asser_non_zero_keyfou(Matchresu1, Lpo_prv, Frc_prvpos), asser_non_zero_keyfou(Matchresu2, Lpos1, Frcpos1), asser_non_zero_keyfou(1, Lpos2, Frcpos2),
% asser_non_zero_keyfou(Matchresu1, Lpos1, Frcpos1),
% asser_non_zero_keyfou(1, Lpos2, Frcpos2),
% OP ASSERTA gezet MOET eig efficienter dat hij max aantal in mem assert of
% dat hij begin vanaf bepaalde positie
find_dkey_file_dkey_pos2(Dbi, Sea, Cou, KiF, KiT):- not( at_end_of_stream(Sea) ),
read_line_str(Sea, Sx1, Lpos1), sub_string(Sx1, _, 14, _, Kein), number_string(Ki, Kein),
Ki >= KiF, Ki =< KiT, !, set_msucce_pos(Dbi, KiF, Lpos1), key_line_parse(Sx1, _, Num),
asserta( pos_for_key_found( Lpos1, Num ) ),
Cou2 is Cou + 1, find_dkey_file_dkey_pos2(Dbi, Sea, Cou2, KiF, KiT).
find_dkey_file_dkey_pos2(Dbi, Sea, Cou, KiF, KiT):- not( at_end_of_stream(Sea) ),!,
Cou2 is Cou + 1, find_dkey_file_dkey_pos2(Dbi, Sea, Cou2, KiF, KiT).
find_dkey_file_dkey_pos2(_, _, _, _,_):- !.
one_keys_list_for_posl([], []):-!.
one_keys_list_for_posl([Rc|RecposLis], [K1|Keyspl1] ):- retract(pos_for_key_found( K1, Rc)),!,
one_keys_list_for_posl(RecposLis, Keyspl1 ).
one_keys_list_for_posl([_|RecposLis], [0|Keyspl1] ):- !, one_keys_list_for_posl(RecposLis, Keyspl1 ).
two_keys_lists_for_posl([], [], [] ):-!.
two_keys_lists_for_posl([Rc|RecposLis], [K1|Keyspl1], [K2|Keyspl2] ):- retract(pos_for_key_found( K1, Rc)),!, ( retract(pos_for_key_found( K2, Rc)) ; K2 = 0 ),
two_keys_lists_for_posl(RecposLis, Keyspl1, Keyspl2 ).
two_keys_lists_for_posl([_|RecposLis], [0|Keyspl1], [0|Keyspl2] ):- !, two_keys_lists_for_posl(RecposLis, Keyspl1, Keyspl2 ).
list_front_aantal([], _Cou, _Max, [] , []):-!.
list_front_aantal([H|RecposLis0], Cou, Max, [H|RecposLis] , Old):- Cou < Max,!, Cou2 is Cou + 1,
list_front_aantal(RecposLis0, Cou2, Max, RecposLis , Old).
list_front_aantal([H|RecposLis0], Cou, Max, RecposLis , [H|Old]):- !, Cou2 is Cou + 1,
list_front_aantal(RecposLis0, Cou2, Max, RecposLis , Old).
find_key_file_poskeys(Fnabs_key_at, KeyStr, Keysxlis):-
retractall(key_for_pos_found( _)), exists_file(Fnabs_key_at),!,
open(Fnabs_key_at, read, Sea, [encoding(unicode_le) ]),
find_key_file_poskeys2(Sea, 0, KeyStr), close(Sea),
findall(Keysx, key_for_pos_found( Keysx), Keysxlis ).
find_key_file_poskeys(_, _, ["nonefound"]):- !.
% centraal
% in feite kun je hier in geheugen opslaan wat de gevonden zijn voor Keystr als Keystr dus naar getal kan , Je moet dan
% voor die Keystr getal ook resetten bij save
% als key lengte 14 is
% dus bij save_db_doc vals reset dan dat geheugen voor die key
% doe die Key per via threadlocal, nee mag ook via db permanent in mem voor alles
% straks nog rooser oplossing
% als je voor rooster data voor de NA datum vanaf bepaalde positie
% de eerste suscess hit hebt gehad, dan in het vervolg beginnen vanaf die positie
% http://localhost:1080/?rdb_wf_action=save_db_doc_vals_app&doc_id=20210605104410&ud=Train_supervisor&db=0000202&webcode=&webnumber=&emailad=rene@hsw.nl&email=rene@hsw.nl
% fsearch_type(Fnapp2cfg, Ftype),
% open(Fnapp2cfg, read, Sea, [encoding(utf8) ]),
% fset_start_position(Ftype, Sea, "get_path_db("),
% fset_start_posit_kposis(Ftype, Sea, KeyStr),
% die 2 zijn bij elkaar dus alle gevonden key posities
% dan eigenlijk union laten maken van die 2
% sorteer die van hoog naar laag, neem de voorste 20 of 40 , dan neem je het 40 ste element of de laatste als het er geen 40 zijn
% die positie wordt de start_positie in de file voor die zoekstring
% later nog per db en dan dynamisch ivm local thread
% to_mem_search_start_pos_keyf(Fnabs_key_at, KeyStr, Keyspl1, Keyspl2).
% fsearch_type(Fnabs_key_at, Ftype),
find_key_file_key_posis(Fnabs_key_at, KeyStr, RecposLis, Keyspl1, Keyspl2):- retractall(pos_for_key_found( _, _)), retractall(last_pos_key( _, _)), exists_file(Fnabs_key_at),!,
% write(" file is open "), nl,
path_read_dbi(Fnabs_key_at, Dbi),
string_length(KeyStr, Strle),
fsearch_type(Fnabs_key_at, Ftype),
open(Fnabs_key_at, read, Sea, [encoding(unicode_le) ]),
% seek
% je kan hier de Db lezen uit het pad van de file
fset_start_posit_kposis(Dbi, Ftype, Sea, KeyStr),
find_key_file_key_pos2(Sea, 0, KeyStr, Strle), close(Sea),
findall(Pos, pos_for_key_found( _, Pos), RecposLis0 ),
% findall(Lpo, pos_for_key_found(Lpo, _), Keyspl1 ) ,
% findall(Lpo, pos_for_key_found(Lpo, _), Keyspl2 ) .
% sort(RecposLis0, RecposLis),
% sort(0, @>, RecposLis0, RecposLis),
% hij gaat hier dus ervan uit dat het juist in geheugen staat kwa volgorde
% even uitschrijven
% HIJ Moet hier in de goeie volgorde staan als hij uit geheugen komt, van groot naar klein
%
% write_term(RecposLis0,[]), nl,
list_front_aantal(RecposLis0, 0, 40, RecposLisx ,_),
sort(0, @>, RecposLisx, RecposLis),
% die 2 zijn bij elkaar dus alle gevonden key posities
% dan eigenlijk union laten maken van die 2
% sorteer die van hoog naar laag, neem de voorste 20 of 40 , dan neem je het 40 ste element of de laatste als het er geen 40 zijn
% die positie wordt de start_positie in de file voor die zoekstring
% later nog per db en dan dynamisch ivm local thread
two_keys_lists_for_posl(RecposLis, Keyspl1, Keyspl2),
% je kan hier de Db lezen uit het pad
to_mem_search_start_pos_keyf(Fnabs_key_at, KeyStr, Keyspl1, Keyspl2).
find_key_file_key_posis(_, _, [0], [0],[0]):- !.
% kan hier du snog de sort bij , daarmee zou hij sneller worden ivm file access in volgorde
% nu met msort gemaakt
% hier dus new met one_keys_list_for_posl bij
% met begin pos kan sneller maken
find_dkey_file_dkey_posis(Fnabs_key_at, KeiF, KeiT, RecposLis, KeypL):- retractall(pos_for_key_found( _, _)), retractall(last_pos_key( _, _)), exists_file(Fnabs_key_at),!,
path_read_dbi(Fnabs_key_at, Dbi),
atom_number(KeiF, KiF ), atom_number(KeiT, KiT ),
open(Fnabs_key_at, read, Sea, [encoding(unicode_le) ]),
set_start_pos_roosdata(Dbi, Sea, KiF),
find_dkey_file_dkey_pos2(Dbi, Sea, 0, KiF, KiT), close(Sea),
findall(Pos, pos_for_key_found( _, Pos), RecposLis0 ),
msort(RecposLis0, RecposLis),
% findall(Pos, pos_for_key_found( _, Pos), RecposLis ),
% msort(RecposLis0, RecposLis),
one_keys_list_for_posl(RecposLis, KeypL).
% write_term(RecposLis, []), nl,
% findall(Keyp, pos_for_key_found( Keyp, _), KeypL ).
find_dkey_file_dkey_posis(_, _, [0], [0]):- !.
% list_front_aantal(RecposLis0, 0, 40, RecposLisx ,_),
% sort(0, @>, RecposLisx, RecposLis),
% two_keys_lists_for_posl(RecposLis, Keyspl1, Keyspl2).
% hier gaat dus fout als de positie foutief is
% write("aa1"), write(Po), write("-"), write(Kposi),
% seek()
% mark_seek
erase_tra_key_in_file2(Sea, P1n):- P1n > 0, Pos2 is P1n / 2,
% write("bb1-"), write(Pos2),
seek(Sea, Pos2, bof, _),
% write("bb2-"), write(Pos2),
!,
write(Sea, "---").
% bezig_debug
% write(Sea, "---z").
erase_tra_key_in_file2(_, _):- !.
erase_tra_key_in_file(Db, Taga, FkeyPos, "succeed") :- split_string(FkeyPos, "-", "", Li), nth0(0, Li, P1 ), nth0(1, Li, P2 ),
% write(" aa hier2 "),
atom_string(Dba, Db), number_string(P1n, P1), number_string(P2n, P2),!, docvals_key_file( Dba, Taga, Fnabs ),
% open(Fnabs, read, Sea, [encoding(unicode_le)]),
open(Fnabs, update, Sea,[ encoding(unicode_le), lock(write)]),
erase_tra_key_in_file2(Sea, P1n), erase_tra_key_in_file2(Sea, P2n), close(Sea).
erase_tra_key_in_file(_, _, _, "notdeleted") :- !.
% hier evt catch bij zetten
% Positie in de file moet dus gedeelt door 2 ivm Unicode little endian , Check dan dus wel dat het een deelbaar door 2 getal is!
% maar dat is dan altijd dus al zo, nog check of anders kan / moet
% mark_seek
get_fpos_rec2(Sea, PosI, Xkey, Rec2):- Pos2 is PosI / 2,
catch( seek(Sea, Pos2, bof, _), _, fail),
read_line_to_string(Sea, Recstr), split_string(Recstr, ";", "", Li), nth0(0, Li, Xkey ), nth0(1, Li, Rec2 ), !.
get_fpos_rec2(_, _,"", " no rec fou for position "):- !.
get_fposition_record(Fnabs_rec_at, PosI, Xkey, Recstr):- exists_file(Fnabs_rec_at),!,
open(Fnabs_rec_at, read, Sea, [encoding(unicode_le) ]),
get_fpos_rec2(Sea, PosI, Xkey, Recstr), close(Sea).
get_fposition_record(_, _, "", ""):- !.
%--
write_apoi_data_line([H]):- !, trim_string(H,H2), write(H2).
write_apoi_data_line([H|Li]):- !, trim_string(H,H2), write(H2), format(";"), write_apoi_data_line(Li).
%---
% pb_apointments[0] = [ref;apntmnt_for_bdr;entity_cde_nme;apnt_datum;apnt_subject_type;apnt_tekst;datum_created;is_afgehandeld_ja_nee;user_cde_nme;locatie;pso_str;apnt_e_datum];
lis_remove_f3(Li0, Li2 ):- append([_,_,_], Li2, Li0), !.
lis_remove_f3(Li0, Li0 ):- !.
% mark_seek
summarize_frecs2(_,_, [], []):-!.
summarize_frecs2(Sea, Cou, [P| RecposLis0], [_| KeypL]):- P2 is P / 2,
seek(Sea, P2, bof, _), read_line_to_string(Sea, Recstr), split_string(Recstr, ";", "", Li0),
lis_remove_f3(Li0, Li ),!,
% append([_,_,_], Li, Li0),!,
Cou2 is Cou +1,
format('pb_apointments['), format(Cou), format('] = ['), format(P), format(";"),
write_apoi_data_line( Li), format('];'), nl,
summarize_frecs2(Sea, Cou2, RecposLis0, KeypL).
summarize_frecs2(Sea, Cou, [_| RecposLis0], [_| KeypL]):- !, summarize_frecs2(Sea, Cou, RecposLis0, KeypL).
%----
% deze 4 moeten gemaakt worden
% deze nog maak !
% set_modif_agd_mem_dtday(_Dba, _Mdfstr):-!.
% set_modif_agd_mem_db(_Dba, _Keyva, _Keyta, _Mdfstr):- !.
% ALS Atom niet werkt dan moet we alles naar string zetten !
% mem_modif_agd(Dbnum, Dkeynum, Bgt_num, Endt_num, Mdfstr )
% bij deze moet je de eerste 8 chars nemen om daykey te maken
% de key is 14 in lengte latste 2 is dus seconds die meetsal ignoreert wordt
clean_mem_mdfbefo(Dba, Mdfstr):- number_string(Mdfnu, Mdfstr), atom_number(Dba, Dn),
retractall( can_remove(_,_) ), Etmaal_secs is 60 * 60 * 24, Mdf2 is Mdfnu - Etmaal_secs,
ag_m_rec(Dn, Po, Mdfr, _), Mdfr < Mdf2,
assert( can_remove(Dn, Po) ), fail,!.
clean_mem_mdfbefo(Dba, _Mdfstr):- atom_number(Dba, Dn),
retract( can_remove(Dn, Po) ), retract( ag_m_rec(Dn, Po, _, _) ), fail,!.
clean_mem_mdfbefo(_, _).
% deze dus voor de recnte records in geheugen te zetten
% modiefied moet binnen komen als integer
summariz_mem_afterd(Dba, Mdfstr):- clean_mem_mdfbefo(Dba, Mdfstr),
number_string(Mdfnu, Mdfstr), atom_number(Dba, Dn),
ag_m_rec(Dn, Po, Mdfr, Fvs), Mdfr > Mdfnu,
number_string(Po, Postr),
format('pb_apointments['), format('1'), format('] = ['), format(Postr), format(";"),
write_apoi_data_line( Fvs), format('];'), nl, fail,!.
summariz_mem_afterd(_, _).
% po is dus nummer
save_ag_mem_rec(Dbs, Po, Fvs):- Po > 0,
get_time( Sta), Y is round(Sta),
atom_number(Dbs, Dn),!,
retractall( ag_m_rec(Dn, Po, _, _)), assert( ag_m_rec(Dn, Po, Y, Fvs)).
save_ag_mem_rec(_, _, _):-!.
% i,i,o,o
adh_omz_ti(15, 2345, 0, 0 ):- !.
adh_omz_ti(Bg, End, Bg, End ):-!.
read_dayk_tibg_te(Dkeya, Bgta, Endta, Dn, Bgn, Endnu):-
atom_length(Dkeya, Dle), Dle > 7, sub_atom(Dkeya, 0, 8, _, Dk2),
atom_number(Dk2, Dn),
atom_length(Bgta, Ble), Ble = 4, atom_number(Bgta, Bgn0),
atom_length(Endta, Ele), Ele = 4, atom_number(Endta, Endnu0),
adh_omz_ti(Bgn0, Endnu0, Bgn, Endnu ),
!.
read_dayk_tibg_te(Dkeya, _, _, Dn, 0, 0):-
atom_length(Dkeya, Dle), Dle > 7, sub_atom(Dkeya, 0, 8, _, Dk2), atom_number(Dk2, Dn),!.
read_dayk_tibg_te(_Dkeya, _, _, 0, 0, 0):- !.
% ** dus dan zou het simpel zijn, check natuurlijk eerst alles valid en lengte
% if de keys zet in mem op nummers
% i, o, o
read_date_dn_tn(Dka, Dayn, Tn):- atom_length(Dka, Le), Le > 13,
sub_atom(Dka, 0, 8, _, Daya), atom_number(Daya, Dayn),
sub_atom(Dka, 8, 4, _, Tia), atom_number(Tia, Tn),!.
% read_dn_tnbe3(Dka, Bgta, Endta):- atom_length(Dka, Le), Le > 7,
% atom_length(Bgta, Le),
% hier dus tijdelijk nog latenb resetten, is indd in efficient
% je weet nog niet welk tijsegment de delete voor is was
% set_modif_agd_mem_dkey(_,_,_):- !.
% deze even gezet opvang
set_modif_agd_mem_dkey(Dba, Dkeya_bg, Dkeya_e):-
atom_length(Dba, Ale), Ale > 0, atom_number(Dba, Dbn),
read_date_dn_tn(Dkeya_bg, Daynbg, Tnbg), read_date_dn_tn(Dkeya_e, Dayne, Tne),
Dayne = Daynbg,!, get_time( Sta), number_string(Sta, Mdfstr),
retractall( mem_modif_agd(Dbn, Dayne, Tnbg, Tne, _ ) ),
assert( mem_modif_agd(Dbn, Dayne, Tnbg, Tne, Mdfstr ) ),
retractall( mem_modif_agd(Dbn, 0, 0, 0, _ ) ),
assert( mem_modif_agd(Dbn, 0, 0, 0, Mdfstr ) ), !.
set_modif_agd_mem_dkey(_Dba, _Dkeya_bg, _Dkeya_e):- !.
get_mem_modif_ag(Dbn, Dn, Bgn, Endnu, Mdfstr ):- mem_modif_agd(Dbn, Dn, Bgn, Endnu, Mdfstr ),!.
get_mem_modif_ag(Dbn, _, _, _, Mdfstr ):- mem_modif_agd(Dbn, 0, 0, 0, Mdfstr ),!.
% get_time( Nowstamp)
% ** dan bij hier opvraag als exact segment matcht dan is dat de modif date
% anders geef de modified van die dag key, Plus zet gelijk in mem
% de modified voor dat segment met de key van die dagkey
get_modif_agd_fi_or_mem(Dba, _Fnstr, Dkeya, Bgta, Endta, Mdfstr, 1):-
atom_length(Dba, Ale), Ale > 0, atom_number(Dba, Dbn),
read_dayk_tibg_te(Dkeya, Bgta, Endta, Dn, Bgn, Endnu),
get_mem_modif_ag(Dbn, Dn, Bgn, Endnu, Mdfstr ),!.
get_modif_agd_fi_or_mem(Dba, Fnstr, _Dkeya, _Bgta, _Endta, Mdfstr, 0):-
atom_length(Dba, Ale), Ale > 0, atom_number(Dba, Dbn), !,
fget_mdfdtf(Dba, Fnstr, Mdfstr),
% get_time( Sta), number_string(Sta, Mdfstr),
% gevaarlijk hier volledige reset of alleen voor de nul
retractall( mem_modif_agd(Dbn, 0, 0, 0, _ ) ),
assert( mem_modif_agd(Dbn, 0, 0, 0, Mdfstr ) ), !.
% 1621223380-1621224574.0973122
% 1621223544-1621224574.0973122
% 1621223805-1621224574.0973122
% 1621224452-1621224574.0973122
% 1621224574-1621224574.0973122
% mdfi-1621224574.0973122-ifdm1-
% zijn dus bijna gelijk
% set_modif_agd_mem_dtda_delres(Dba, Kposi),
% op zich logisch hij blijft tijd er zijn deletes geweest geven Totdat er nieuw wordt ingevoerd
str_find_er_zijn_deletes_geweest(Dba, Mdfstr, "er zijn deletes geweest sinds"):-
atom_length(Dba, Ale), Ale > 0, atom_number(Dba, Dbn),
number_string(Sta, Mdfstr), Stx is floor(Sta),
mmdf_ag_del( Dbn, Mdfnu, _Kpos),
% bezig_debug
% nl, write(Mdfnu), write("-"), write(Sta), nl,
Mdfnu >= Stx,!.
str_find_er_zijn_deletes_geweest(_, _, ""):-!.
% HIER op de regel aan eind meegeef de string er zijn deletes geweest, als dat zo is
% in mem zet iets als , er zijn deletes geweest sinds ? wordt te ingewikkeld, maar zoiets dus
% toch extra mem cluase
% mmdf_ag_del( Dbnu, Mdfnu, Respos)
% als hij dus in geheugen er 1 Na de opgegeven kan vinden, dan geeft hij bij de opvraag
% dus die tag er zijn deletes geweest sinds
% Alleen Wanneer kun je het record geheugen leeg gooien ?
% of , misschien soort zelf auto opschoon maken die dus alles kleiner dan vandaag
% Leeg gooit, dat moet het hast zijn !
% dus time now, dan 24 uur eraf trek, en dan alle recs die voor die datum liggen verwijderen
% dat kan dus hier , en dat kan ook op de plaats van deze functie ::
% summariz_mem_afterd hoeft hier dan niet meer als hij bij die andere staat
% kan waarsch net zo goed Ook helemaal retracten ? mmdf_ag_del
% ging hier fout Blijft oneindig zeggen dat er data ondertussen zijn gewijzigd
set_modif_agd_mem_dtda_delres(Dba, Kpos):-
atom_length(Dba, Ale), Ale > 0, atom_number(Dba, Dbn),
get_time( Sta), Mdfnu is ceil(Sta),
% kan hier nog 1 Sec erbij optellen voor de veiligheid
number_string(Mdfnu, Mdfstr),!,
% number_string(Sta, Mdfstr),!,
% deze leek te moeten , nu toch beiden zelfde , dan gaat wrsch ook fout
retractall( mem_modif_agd(Dbn, _, _, _, _ ) ),
assert( mem_modif_agd(Dbn, _, _, _, Mdfstr ) ),
asserta( mmdf_ag_del( Dbn, Mdfnu, Kpos) ).
% deze dus uitgezet , moet pas later of anders , nee moet dus toch wel
% !.
set_modif_agd_mem_dtda_delres(_Dba, _):- !.
% get_time( Nowstamp)
% mem_modif_agd(Dbnum, Dkeynum, Bgt_num, Endt_num, Mdfstr )
% laatste arg is output
% kruks is hier , dat, Als er dingen in mem staan , dan haal uit mem
% let op de dingen gaan dus over hoe doe je als hij nul of leeg is
% als niks is geinstantieerd dan file datum ,dan
% get_modif_agd_fi_or_mem(Dba, Fnstr, Dkeya, Bgta, Endta, Mdfstr),
% is hij modif in mem in het segment , zo nee geef de modified stamp van de gehele dag
% me clause is mem_modif_agd(Dbnum, Dkeynum, Bgt_num, Endt_num, Mdfstr )
% je moet dus nummer segmenten vergelijken of die passen en dan de modif str time geef
%---
% deze ook new
fget_mdfdtf(Dba, Fnstr, Mdfstr):- atom_string(Fna, Fnstr),
db_file_abs_at( Dba, Fna, Fnabs ), exists_file(Fnabs),!,
time_file(Fnabs, Tmsta), Tsta2 is ceil(Tmsta), number_string(Tsta2, Mdfstr).
fget_mdfdtf( _, _, "0"):-!.
% hij moet in Ag alleen van de Keyfile de de modif date geven
summarize_frecs(Fnabs, RecposLis0, KeypL):- exists_file(Fnabs),!,
% time_file(Fnabs, Tmsta),
% write("mdfi-"), write(Tmsta), write("-ifdm"), nl,
open(Fnabs, read, Sea, [encoding(unicode_le) ]),
summarize_frecs2(Sea, 1, RecposLis0, KeypL), close(Sea).
summarize_frecs(_, _, _):- !.
% string2_at_number(A, B, A2, B2) :- atom(B), atom_number(B, B2), number_string(A2, A), !.
% string2_at_number(A, B, A2, B2) :- number_string(A2, A), number_string(B2, B),!.
string2_number(A, B, A2, B2) :- string(A), string(B), number_string(A2, A), number_string(B2, B),!.
number2_string(A, B, A2, B2) :- number_string(A, A2), number_string(B, B2),!.
%---
readl_to_term(Sea, 1 ):- !, read_line_to_string(Sea, Sx), catch( term_string(Te, Sx), _, fail),
Te = forey_key_ema(Ema, Webnum_s, Webcode_s), string2_number(Webnum_s, Webcode_s, Webnum_i, Webcode_i), assert(forey_keyi_ema(Ema, Webnum_i, Webcode_i)).
% eerste args is ATOM ipv string , rest is alles wel string
readl_to_term(Sea, 2 ):- !, read_line_to_string(Sea, Sx), catch( term_string(Te, Sx), _, fail),
Te = forey_key(Keyi, Webnum_s, Webcode_s),
string2_number(Webnum_s, Webcode_s, Webnum_i, Webcode_i),
assert(forey_keyi(Keyi, Webnum_i, Webcode_i )).
%---
cons_foreig_key_ema2(Sea, Tpe):- not( at_end_of_stream(Sea) ), readl_to_term(Sea, Tpe ),!, cons_foreig_key_ema2(Sea, Tpe).
cons_foreig_key_ema2(Sea, Tpe):- not( at_end_of_stream(Sea) ), !, cons_foreig_key_ema2(Sea, Tpe).
cons_foreig_key_ema2(_, _):-!.
%--
cons_foreig_key_ema(Dba):- retractall(forey_keyi_ema(_, _, _ )), db_file_abs_at(Dba, 'foreig_key_ema', Fnabs ), exists_file(Fnabs),!,
open(Fnabs, read, Sea, [encoding(unicode_le) ]),
cons_foreig_key_ema2(Sea, 1), close(Sea).
cons_foreig_key_ema(_):-!.
%--
cons_foreig_key_map(Dba):- retractall(forey_keyi(_, _, _ )), db_file_abs_at(Dba, 'foreig_key_map', Fnabs ), exists_file(Fnabs),!,
open(Fnabs, read, Sea, [encoding(unicode_le) ]),
cons_foreig_key_ema2(Sea, 2), close(Sea).
cons_foreig_key_map(_):-!.
%----
% consul_foreig_keys(_):- !.
consul_foreig_keys(Acca):- !, cons_foreig_key_map(Acca), cons_foreig_key_ema(Acca).
%---
file_read_str(Db, Fbase, Str):- db_file_abs_at(Db, Fbase, Fnabs ), open(Fnabs, read, Sea, [encoding(unicode_le) ]),
read_line_to_string(Sea, Str), close(Sea).
% hier catch bij zetten
file_write_str(Db, Fbase, Str):- db_file_abs_at(Db, Fbase, Fnabs ),
open(Fnabs, write, Sea, [close_on_abort(true), encoding(unicode_le), lock(write)]),
write(Sea, Str), close(Sea).
%--
% Ftag = 'pb_ps_cde_increm'
auto_increment_value_fi(Db, Ftag, Key ):- db_file_abs_at(Db, Ftag, Fnabs ), exists_file(Fnabs),
file_read_str(Db, Ftag, Str), number_string(Nu, Str), Nu2 is Nu + 1, number_string(Nu2, Str2),
file_write_str(Db, Ftag, Str2),!, digi_to_zkey(Nu2, 7, Key).
auto_increment_value_fi(Db, Ftag, Key):- Cou = 10000, digi_to_zkey(Cou, 7, Key), number_string(Cou, Sy),
file_write_str(Db, Ftag, Sy),!.
%---
% table_txt_fie_ind_default(Tbn, Indexf1, Indexf2),
% mem::dbname_to_txtdb_fname(Db,Tbn,Rdb_txtdb_fn),
% rdbf::record_val(Indexf1,Fns,Vals,Indval1),
% rdbf::record_val(Indexf2,Fns,Vals,Indval2),
% trap(Stream = outputStream_file::append(Rdb_txtdb_fn),_,fail),
xtra_str_nwfi(Fnabs, _, ""):- exists_file(Fnabs),!. xtra_str_nwfi(_, Def, Def):- !.
% stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, Pos),!,
% als je bijbeho key pos in mem kan vinden , dan erase keys
% delete_tabel_apoi_record(_Dbs, _RcPos ):-!.
erase_afs_key(Dba, FkeyPos, "succeed") :- !, db_file_abs_at(Dba, 'pb_apointments_apnt_datum', Fnabs ),
% write(" deleted "),
% write(Fnabs),
open(Fnabs, update, Sea,[ encoding(unicode_le), lock(write)]),
erase_tra_key_in_file2(Sea, FkeyPos),
close(Sea).
erase_afs_key(_, _, _, "notdeleted") :- !.
% delete_tabel_apoi_record(Dba, Kposi, Res ):- erase_afs_key(Dba, Kposi, Res),!.
% catc_seek(Sea, Pos2):- catch( seek(Sea, Pos2, bof, _),_,fail),!.
%---
% Nog aanmaak rdb_backups map op webpara
% osdir_a('/rdb_tempv6/rdb_backups/', Osd),
% atomic_list_concat([Osd, Basefnat, '.txt'], TotFiname),
% lees_last_txt_uitfile(TotFiname, Oc, Txt):-!.
% hier dus uit file de tekst lees,
% format in file is :
% 201007075538;catst;0000202; text ans swi get
oef text;
% 201007075632;catst;0000202; text ans swi get
oef text;
% zelfde als lees_fdbcreat_date
% ass_fdbcreat_date(Dbnu, Appds, Sx):-
% split_string(Sx, ";", "", Lix), nth0(2, Lix, Appdsx ), Appdsx = Appds,
% nth0(0, Lix, Datustr ), !,
% pak derde arg , Mogen geen puntkomma in staan dus
log_to_file(Basefnat, Sx1, Sx2, Sx3, Sx4, N1,N2,N3,N4 ):- osdir_a('/rdb_tempv6/rdb_backups/', Osd),
atomic_list_concat([Osd, Basefnat, '.txt'], TotFiname), date_key_compact(Dkea),
catch( open(TotFiname, append, Sea,[ close_on_abort(true), encoding(utf8), lock(write)]), _, fail), !,
write(Sea, Dkea), write(Sea,";"), write(Sea, Sx1 ), write(Sea, ";"), write(Sea, Sx2), write(Sea, ";"), write(Sea, Sx3), write(Sea, ";"),
write(Sea, Sx4), write(" "), write(N1), write("."), write(N2), write("."), write(N3), write("."), write(N4),
write(Sea, "\n"), close(Sea).
log_to_file(_, _, _ , _, _, _,_,_,_):- !.
%---
table_record_txtdb_append_record_fixdl(Db, Tbn, Fns, Vals, Pos, Keyuns):- date_stamp_sec_short_year(Short_stamp, Keyuns),
db_file_abs_at(Db, Tbn, Fnabs ), xtra_str_nwfi(Fnabs, "\nbegin\n", Xtra), !, open(Fnabs, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
write(Sea, Xtra), seek(Sea, 0, eof, _),
stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, Pos),!,
write_vals_fixdl(Sea, Tbn, ['none','none','none'| Fns], [Short_stamp, "", ""| Vals]), write(Sea, "\n"), close(Sea).
table_record_txtdb_append_record_fixdl(_, _, _, _, 0, 0):-!.
%----
table_record_txtdb_append_record(Db, Tbn, _Fns, Vals, Pos, Keyuns):- date_stamp_sec_short_year(Short_stamp, Keyuns),
db_file_abs_at(Db, Tbn, Fnabs ), xtra_str_nwfi(Fnabs, "\nbegin\n", Xtra), !, open(Fnabs, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
write( Xtra), seek(Sea, 0, eof, _), stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, Pos),!,
write_vals(Sea, [Short_stamp, "", ""| Vals]), write(Sea, "\n"), close(Sea).
table_record_txtdb_append_record(_, _, _, _, 0, 0):-!.
% table_record_txtdb_append_record(Db, Tbn, _Fns, Vals, Pos, Keyuns):- date_stamp_sec_short_year(Short_stamp, Keyuns),
% db_file_abs_at(Db, Tbn, Fnabs ), !, open(Fnabs, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
% write(Sea, "\nbegin\n"),
% stream_property(Sea, position(Kpos)), stream_position_data(byte_count, Kpos, Pos),!,
% write_vals(Sea, [Short_stamp, "", ""| Vals]), write(Sea, "\n"), close(Sea).
%---
append_line_to_claufile(Fn, Line):- xtra_str_nwfi(Fn, "\nclauses\n", Xtra),
open(Fn, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
write(Sea, Xtra), write(Sea, Line), write(Sea,".\n"), close(Sea),!.
% append_line_to_claufile(Fn,Line):- open(Fn, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
% write(Sea, "\nclauses\n"), write(Sea, Line), write(Sea, ".\n"), close(Sea),!.
append_line_to_claufile(_,_):- !.
%--
%--
asser_emkey_only(Fkf, Emx, Nwebn, Nwebco):- term_string(forey_key_ema(Emx, Nwebn, Nwebco), Xs),
% forey_key_ema(Emx,"0010000","4961091119").
append_line_to_claufile( Fkf, Xs),!.
asser_emkey_only(_,_,_,_):-!.
%---
asser_forkey_only(Fkf, DocIdstr, Nwebn, Nwebco):- number_string( IdU , DocIdstr),
term_string(forey_key(IdU, Nwebn, Nwebco), Xs), append_line_to_claufile( Fkf, Xs),!.
asser_forkey_only(_,_,_,_):-!.
%---
asser_forey_key(Fkf, Emf, Docu, Emx, Nwebn, Nwebco):- !,
asser_forkey_only(Fkf, Docu, Nwebn, Nwebco),
asser_emkey_only(Emf, Emx, Nwebn, Nwebco).
%-- HIER nog beter catch ?
% db is string
% afs_keys_pos_to_mem( Dba, RecposLis0, KeypL),
% deze memem ontbreekt dus hier, anders hier via seek op vragen gaan kijken of bij listing kan
% bij de mem listing kan dus niet
% seek() alleen laatste is output
record_key_insert(Db, Tbn, Hea, Va, FPos, KeyRef, Lfpos):- fhas_key(Tbn, Hea), string_length(Va, Le), Le > 0,
db_key_file_abs_at(Db, Tbn, Hea, Fnabs ), xtra_str_nwfi(Fnabs, "\nbegin\n", Xtra),
open(Fnabs, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
seek(Sea, 0, eof, _),
stream_property(Sea, position(Haspos)), stream_position_data(byte_count, Haspos, Lfpos),!,
write(Sea, Xtra ),
number_string(FPos, P2), number_string(KeyRef, KeyRef2), write_vals(Sea,[Va, P2, KeyRef2]),!, write(Sea, "\n"), close(Sea).
record_key_insert(_, _, _, _, _, _, 0):- !.
%---
record_keys_insert(_, _, [], [], _, _):- !.
record_keys_insert(Db, Tbn, [Hea|RecFnames], [Va|RecFvals], FPos, KeyRef):-
record_key_insert(Db, Tbn, Hea, Va, FPos, KeyRef, Newkeypos),
asser_ag_apoi(Db, Tbn, FPos, Newkeypos),
record_keys_insert(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef).
%--
%---
% deze close on abort bij gezet
% mark_seek
table_record_txtdb_update_record_fixdl(Db, Tbn, Rposa, Fns, Vals, Posa, Keyuns):- date_stamp_sec_short_year(Short_stamp, Keyuns),
atom_number(Rposa, Posa), db_file_abs_at(Db, Tbn, Fnabs ), exists_file(Fnabs), !,
% open(Fnabs, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
open(Fnabs, update, Sea,[ encoding(unicode_le), lock(write), close_on_abort(true) ]),
Pos2 is Posa / 2,
seek(Sea, Pos2, bof, _),!,
write_vals_fixdl(Sea, Tbn, ['none','none','none'| Fns], [Short_stamp, "", ""| Vals]), write(Sea, "\n"), close(Sea).
table_record_txtdb_update_record_fixdl(_, _, _, _, _, 0, 0):-!.
% size_file(filenaam i , Size o)
update_table_record_real_txtdb_fixdl(Db, Tbn, Rposa, RecFnames, RecFvals, FPos, KeyRef ):- !,
table_record_txtdb_update_record_fixdl(Db, Tbn, Rposa, RecFnames, RecFvals, FPos, KeyRef).
%write(" inserted in pos "), write(FPos),
%record_keys_insert(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef).
%--
insert_table_record_real_txtdb_fixdl(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef):- !,
table_record_txtdb_append_record_fixdl(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef),
write(" inserted in pos "), write(FPos),
record_keys_insert(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef).
%--
% i,i,i,i, o,o
insert_table_record_real_txtdb(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef):- !,
table_record_txtdb_append_record(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef),
record_keys_insert(Db, Tbn, RecFnames, RecFvals, FPos, KeyRef).
%----
is_nonempty_or_zero(XtrK ):- number_string(Num, XtrK), Num > 0, !.
% is_empty_or_zero(_ ):- !.
mk_empty_str2( Cou, Ata, Hl, Nsli):- Cou < Ata, Cou2 is Cou + 1, mk_empty_str2( Cou2, Ata, [32|Hl], Nsli).
mk_empty_str2( _, _, Hl, Hl):- !.
%---
mk_empty_str( Ata, Ns):- mk_empty_str2( 0, Ata, [], Nsli), string_codes( Ns ,Nsli).
recva_fixdl(Va, Tbn, Fn, Va2):- has_frec_length(Tbn, Fn, Le), string_length(Va, Les), Les >= Le, sub_string(Va, 0, Le, _, Va2 ),!.
recva_fixdl(Va, Tbn, Fn, Va2):- has_frec_length(Tbn, Fn, Le), string_length(Va, Les), Le > Les, Df is Le - Les, !,
mk_empty_str( Df, Ns), string_concat(Va, Ns, Va2).
recva_fixdl(Va, _Tbn, _Fn, Va):-!.
write_vals_fixdl(_, _Tbn, [], []):-!.
write_vals_fixdl(Sea, Tbn, [Fn], [Va]):- recva_fixdl(Va, Tbn, Fn, Va2), write(Sea, Va2), !.
write_vals_fixdl(Sea, Tbn, [Fn|Fns], [Va|Vas]):- !, recva_fixdl(Va, Tbn, Fn, Va2), write(Sea, Va2), write(Sea, ";"),
write_vals_fixdl(Sea, Tbn, Fns, Vas).
% write_vals_fixdl(Sea, Tbn, ['none','none','none'| Fns], [Short_stamp, "", ""| Vals]):-
write_vals(_,[]):- !.
write_vals(Sea, [V]):- !, write(Sea, V).
write_vals(Sea, [V|Vals]):- write(Sea, V),write(Sea, ";"), write_vals(Sea, Vals).
% [13, 10, 9, 59]
% Clea :- Fv2 = string::replaceAll(Fv, "\n", ""),
% Fv3 = string::replaceAll(Fv2, "\r", ""),
% Clea = string::replaceAll(Fv3, ";", " ").
wr_doc_vals(_, [],[]):- !.
wr_doc_vals(Sea, [Fn], [Fv]):- !, write(Sea, Fn), write(Sea, "="), clean_doc_val(Fv, Fv2), write(Sea, Fv2) .
wr_doc_vals(Sea, [Fn|Fns],[Fv|Fvs]):- write(Sea, Fn), write(Sea, "="), clean_doc_val(Fv, Fv2), write(Sea, Fv2), write(Sea, "&"), wr_doc_vals(Sea, Fns,Fvs).
% trap(Sea = outputStream_file::append(Filename),_,fail),
record_key_append_txt(Filename, KeyStr, XtrKeyUns, Pos):- is_nonempty_or_zero(KeyStr ), is_nonempty_or_zero(XtrKeyUns ),!, open(Filename, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
number_string(Pos, P2), write_vals(Sea, [KeyStr, P2]),!, write(Sea,"\n"), write_vals(Sea, [ XtrKeyUns,P2]), write(Sea,"\n"), !, close( Sea ).
record_key_append_txt(Filename, KeyStr, _XtrKeyUns, Pos):- is_nonempty_or_zero(KeyStr ), !, open(Filename, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
number_string(Pos, P2), write_vals(Sea, [KeyStr, P2]),!, write(Sea,"\n"), !, close( Sea ).
% tagqw_ema
record_key_append_txt(Filename, KeyStr, _XtrKeyUns, Pos):- is_valid_email(KeyStr), !, open(Filename, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
number_string(Pos, P2), write_vals(Sea, [KeyStr, P2]),!, write(Sea,"\n"), !, close( Sea ).
record_key_append_txt(_,_,_,_):-!.
record_key_append_txt(Filename, KeyStr, _XtrKeyUns, Pos):- !, open(Filename, append, Sea,[ close_on_abort(true), encoding(unicode_le), lock(write)]),
number_string(Pos, P2), write_vals(Sea, [KeyStr,P2]),!, write(Sea,"\n"), close(Sea).
% XtrKeyUns <> 0,
% hier nog exist fiel bij