home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / PROGRAMS.ARC / DUMPDBA.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  1.7 KB  |  56 lines

  1. /*****************************************************************************
  2.  
  3.         DUMP CONTENTS OF DATABASE TO TEXTFILE
  4.  
  5.  The predicate dumpdba can be used to dump the contents of an external
  6.  database into a textfile, if the database follow certain conditions.
  7.  
  8.  It is assumed that every chain in the database models a relation. It is
  9.  assumed that indexes can be generated from the relations, so the B+Trees
  10.  is not dumped.
  11.  
  12.  It is required that all terms in the database is stored under the same
  13.  domain !.
  14.  
  15.  The name of the domain is here called mydom, it should be substituted
  16.  by the actual name, and a proper declaration.
  17.  
  18.  The contents of the database is writen in the textfile, which is opened
  19.  by oufile. In each line a term and the name of the chain is written. The
  20.  term and the chain name is combined into the domain CHAINTERM. The database
  21.  can a later be loded again by using readterm with the CHAINTERM domain.
  22.  
  23.  
  24. *****************************************************************************/
  25.  
  26. DOMAINS
  27.   DB_SELECTOR    = mydba
  28.   CHAINTERM    = chain(STRING,mydom)
  29.   FILE        = outfile
  30.  
  31.   mydom        = city(CITYNO,CITYNAME);
  32.             person(FIRSTNAME,LASTNAME,STREET,CITYNO,CODE)
  33.   CITYNO, CITYNAME, FIRSTNAME, LASTNAME, STREET, CODE = STRING
  34.  
  35.  
  36. PREDICATES
  37.   wr(CHAINTERM)
  38.   dumpdba(STRING,STRING)
  39.  
  40. CLAUSES
  41.   wr(X):-write(X),nl.
  42.  
  43.   dumpdba(DBASE,OUTFILE):-
  44.     db_open(mydba,DBASE,in_file),
  45.     openwrite(outfile,OUTFILE),
  46.     writedevice(outfile),
  47.     db_chains(mydba,CHAIN),
  48.     chain_terms(mydba,CHAIN,mydom,TERM,_),
  49.     wr(chain(CHAIN,TERM)),
  50.     fail.
  51.   dumpdba(_,_):-
  52.     closefile(outfile),
  53.     db_close(mydba).
  54.  
  55. GOAL dumpdba("register.bin","register.txt").
  56.