На этом шаге мы рассмотрим вывод содержания базы данных.
Вы можете использовать предикат list_dba, определенный ниже, для вывода текущего состояния базы данных. Он имеет один аргумент - селектор просматриваемой открытой базы данных. Все термы в базе данных должны быть одного домена.
constants
filename="\\vip\\vpi\\programs\\register\\exe\\register.bin"
domains
db_selector=mydba
mydom=city(zipcode,cityname);
person(firstname,lastname,street,zipcode,code)
zipcode,cityname,firstname,lastname,street,code=string
predicates
listdba(db_selector)
nondeterm bt_keys(db_selector,bt_selector,string,ref)
nondeterm bt_keysloop(db_selector,bt_selector,string,ref)
clauses
listdba(Db_selector):-
nl,
write("********************************************"),nl,
write(" Database listing"),nl,
write("********************************************"),
b_statistics(Db_selector,NoOfTerms,MemSize,DbaSize,FreeSize),nl,nl,
write("Total number of records in the database: ",NoOfTerms),nl,
write("Number of bytes used in main memory: ",MemSize),nl,
write("Number of bytes used by the database: ",DbaSize),nl,
write("Number of bytes free on disk: ",FreeSize),nl,
fail.
listdba(Db_selector):-
db_chains(Db_selector,Chain),nl,nl,nl,nl,
write("******** Chain LISTING *************") ,nl,nl,
write("Name=",Chain),nl,nl,
write("CONTENT OF: ",Chain),nl,
write("------------\n"),
chain_terms(Db_selector,Chain,mydom,Term,Ref),
write("\n",Ref,":",Term),
fail.
listdba(Db_selector):-
bt_btrees(Db_selector,Btree), % Возврат имени каждого B+ дерева
bt_open(Db_selector,Btree,Bt_selector),
bt_statistics(Db_selector,Bt_selector,NoOfKeys,
NoOfPages,Dept,KeyLen,Order,PageSize),nl,nl,nl,
write("******** INDEX LISTING **************") ,nl,nl,
write("Name= ",Btree),nl,
write("NoOfKeys= ",NoOfKeys),nl,
write("NoOfPages= ",NoOfPages),nl,
write("Dept= ",Dept),nl,
write("Order= ",Order),nl,
write("KeyLen= ",KeyLen),nl,
write("PageSize= ",PageSize), nl,
write("CONTENT OF:",Btree),nl,
write ("--------------\n"),
bt_keys (Db_selector,Bt_selector,Key,Ref),
write("\n",Key, " - ",Ref),
fail.
listdba(_).
bt_keys(Db_selector,Bt_selector,Key, Ref):-
key_first(Db_selector,Bt_selector,_),
bt_keysloop(Db_selector,Bt_selector,Key,Ref).
bt_keysloop(Db_selector,Bt_selector,Key,Ref):-
key_current(Db_selector,Bt_selector,Key,Ref).
bt_keysloop(Db_selector,Bt_selector,Key,Ref):-
key_next(Db_selector,Bt_selector,_),
bt_keysloop(Db_selector,Bt_selector,Key, Ref).
goal
db_open(mydba, filename,in_file),
listdba(mydba).
На следующем шаге мы рассмотрим создание защищенной базы данных.