home *** CD-ROM | disk | FTP | other *** search
- REM --------------------------------------------------------\
- This program demonstrates the use of Btrieve from a CB86 program
- REM --------------------------------------------------------\
- Define the Btrieve calling sequence:
- DEF BTRV(OP%,POSBLK$,DATABUF$,DATALEN$,KEYBUF$,KEYNUM%) EXTERNAL
- INTEGER BTRV
- FEND
- REM --------------------------------------------------------\
- Define the routine to set an integer into a string:
- DEF ISET(A$,POS%,I%) EXTERNAL
- INTEGER ISET
- REM --------------------------------------------------------\
- calling sequence: \
- STATUS%=ISET(A$,POS%,I%) \
- where \
- STATUS% - return status, \
- 0 = normal completion \
- -1 = invalid parmeters, string not modified \
- A$ - string, must be initialized \
- POS% - starting position in string, (first byte=1) \
- I% - integer to be inserted \
- --------------------------------------------------------
- FEND
- REM --------------------------------------------------------\
- Define the routine to get an integer from a string:
- DEF IGET(A$,POS%) EXTERNAL
- INTEGER IGET
- REM --------------------------------------------------------\
- calling sequence: \
- I%=IGET(A$,POS%) \
- where \
- A$ - string from which to extract 2 bytes \
- POS% - starting position in string, (first byte=1) \
- I% - integer to receive data, set to zero when \
- parameters are invalid \
- --------------------------------------------------------
- FEND
- OP%=14
- POS.BLK$=STRING$(4097," ")
- DATA.BUF$=STRING$(4097," ")
- Z$="??"
- DATA.LEN$="??"
- CALL ISET(Z$,1,0)
- FILE.DEF$=STRING$(50,Z$)
- CALL ISET(FILE.DEF$,1,64) :\ record length = 64
- CALL ISET(FILE.DEF$,3,512) :\ page size = 512
- CALL ISET(FILE.DEF$,5,1) :\ 1 key
- CALL ISET(FILE.DEF$,17,1) :\ key starts in first byte
- CALL ISET(FILE.DEF$,19,2) :\ key is 2 bytes long
- CALL ISET(FILE.DEF$,21,0004H) :\ key is binary
- CALL ISET(DATA.LEN$,1,50)
- KEY.BUF$="TEST.BTR"
- KEY.NUM%=0
- REM --------------------------------------------------------\
- create a btrieve file \
- --------------------------------------------------------
- STATUS%=BTRV(OP%,POS.BLK$,FILE.DEF$,DATA.LEN$,KEY.BUF$,KEY.NUM%)
- PRINT "Data Buffer Length = "; IGET(DATA.LEN$,1)
- PRINT "Create status = "; STATUS%
- REM --------------------------------------------------------\
- open the btrieve file \
- --------------------------------------------------------
- CALL ISET(DATA.LEN$,1,0)
- STATUS%=BTRV(0,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,0)
- PRINT "Data Buffer Length = "; IGET(DATA.LEN$,1)
- PRINT "Open status = "; STATUS%
- REM --------------------------------------------------------\
- insert 1 record \
- --------------------------------------------------------
- DATA.BUF$="??This is record number one." + STRING$(64-28,".")
- CALL ISET(DATA.LEN$,1,64)
- CALL ISET(DATA.BUF$,1,101)
- STATUS%=BTRV(2,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,KEY.NUM%)
- PRINT "Data Buffer Length = "; IGET(DATA.LEN$,1)
- PRINT "Insert status = "; STATUS%
- REM --------------------------------------------------------\
- read that record \
- --------------------------------------------------------
- DATA.BUF2$=STRING$(64," ")
- CALL ISET(DATA.LEN$,1,65)
- STATUS%=BTRV(12,POS.BLK$,DATA.BUF2$,DATA.LEN$,KEY.BUF$,0)
- PRINT "Data Buffer Length = ";IGET(DATA.LEN$,1)
- PRINT "Read status = "; STATUS%
- IF (IGET(KEY.BUF$,1) = 101) AND (DATA.BUF$ = DATA.BUF2$) \
- THEN PRINT "Get Lowest OK. Key.Buf = "; IGET(KEY.BUF$,1) \
- ELSE PRINT "Get Lowest Failed. Key.Buf = "; IGET(KEY.BUF$,1)
- REM --------------------------------------------------------\
- get a btrieve error \
- --------------------------------------------------------
- DATA.BUF$=" "
- CALL ISET(DATA.LEN$,1,1)
- STATUS%=BTRV(12,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,0)
- PRINT "Data Buffer Length = ";IGET(DATA.LEN$,1)
- IF STATUS% = 22 \
- THEN PRINT "Error return OK. Status = "; STATUS% \
- ELSE PRINT "Error return failed. Status = "; STATUS%
- REM --------------------------------------------------------\
- get the file status \
- --------------------------------------------------------
- DATA.BUF$=STRING$(50,Z$)
- CALL ISET(DATA.LEN$,1,65)
- STATUS%=BTRV(15,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,0)
- PRINT "Data Buffer Length = ";IGET(DATA.LEN$,1)
- CALL ISET(FILE.DEF$,7,1) :\ #recs = 1
- CALL ISET(FILE.DEF$,23,1) :\ #keys = 1
- IF DATA.BUF$ = FILE.DEF$ \
- THEN PRINT "File stat's OK. Status = "; STATUS% \
- ELSE PRINT "File stat's failed. Status = "; STATUS%
- NRECS=(IGET(DATA.BUF$,9)*65536) + IGET(DATA.BUF$,7)
- NKEYS=(IGET(DATA.BUF$,25)*65536) + IGET(DATA.BUF$,23)
- PRINT "Number of records = "; NRECS
- PRINT "Number of unique keys for key 0 = "; NKEYS
- REM --------------------------------------------------------\
- close the btrieve file \
- --------------------------------------------------------
- STATUS%=BTRV(1,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,0)
- PRINT "Data Buffer Length = ";IGET(DATA.LEN$,1)
- PRINT "Close status = "; STATUS%
- REM --------------------------------------------------------\
- stop btrieve & check to be sure \
- --------------------------------------------------------
- STATUS%=BTRV(25,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,0)
- STATUS2%=BTRV(25,POS.BLK$,DATA.BUF$,DATA.LEN$,KEY.BUF$,0)
- PRINT "Data Buffer Length = ";IGET(DATA.LEN$,1)
- IF (STATUS% = 0) AND (STATUS2% = 20) \
- THEN PRINT "File manager unloaded."; STATUS%; "/"; STATUS2% \
- ELSE PRINT "File manager unload failed."; STATUS%; "/"; STATUS2%
- STOP
- END