From: cconstantine@galaxy.gov.bc.ca
Newsgroups: comp.sys.mac.programmer,comp.sys.mac.databases
Subject: please help with database programming!
Date: 26 Sep 92 14:50:42 -0700
Organization: BC Systems Corporation

HELP!!!  I'm going to be working on a rather large project with a few of my
friends at work.  They want me to design the interface (Probalby in MPW C - but
I'm going to start with THINK C 5.0.3) for a data manipulation program that
they will be doing in FORTAN.  That's fine, I can do the interface without a
hitch.  I'm having problems with another area though.  They also want me to
write the C code that will read in the Database file (in dBase IV or
FoxBase+/FoxPro [pc and mac]) that the data is in.  I've go the description of
a standard .dbf file header (following) but I can't really figure out for the
life of me how to set up the data structure(s) that will read in the header
information so that I can get to the file.  Has anyone ever tried this before??
Any sample code is muchly appreciated and you'll be credited (although  it's
not going to be a comercial product, I'll definately let my co-workers know
that you helped me with this area)

Here is what I have for the .dbf file header and field descriptor bytes:

Byte	Contents		Meaning
----------------------------------------
0	1 byte			Valid dBase IV file; bits 0-2 indicate version
				number, bits 3-5 are reserved for SQL, bits 6
				and 7 indicate the presence of a memo file.

1-3	3 bytes			Date of last update; formatted as YYMMDD

4-7	32-bit number		Number of records in the database file

8-9	16-bit number		Number of bytes in the header

10-11	16-bit number		number of bytes in the record

12-13	1 bytes			Reserved

14	1 byte			Flag indicating incomplete transaction*

15	1 byte			Encryption flag**

16-27	12 bytes		Reserved for dBase IV on LAN

28	1 byte			Production .mdx file flag; 01H if there is a
				production .mdx file, 00H if not (H=HEX)

29-31	3 bytes			Reserved

32-n***	32 bytes each		Field descriptor array (the structure of this
				array follows later)

n+1	1 byte			ODH as the field terminator (H=HEX)

* The ISMARKED() function checks this flag.  BEGIN TRANSACTION sets it to 01,
END TRANSACTION and ROLLBACK reset it to 00.

** If this flag is set to 01H, the message Database encrypted appears. 
Changing this flag to 00H removed the message, but does not decrypt the file.

*** n is the last byte in teh field descriptor array.  The size of the array
depends on the number of fiels in the database file.


Field Descriptor:

Byte	Contents		Meaning
-----------------------------------------

0-10	11 bytes		Field name in ASCII (zero-filled)

11	1 byte			Field type in ASCII (C,D,F,L,M, or N)

12-15	4 bytes			Reserved

16	1 byte			Field length in binary

17	1 byte			Field decimal conut in binary

18-19	2 bytes			Reserved

20	1 byte 			Work area ID

21-31	11 bytes		Reserved



DATABASE RECORDS:
	The records follow the header in the database file.  Data records are
preceded by one byte; that is, a space (20H) if the record is not deleted, an
asterisk (2AH) if the record is deleted.  Fields are packed into records
without field separators or record terminators.  The end of the file is marked
by a single byte, with the endo-of-file marker an ASCII 26 (1AH) character.




I'm sorry this is so long, but I'v no experience in real database programming.

Thanks for any help, sample code (preferably in THINK C) that may be available. 
Can anyone even point me to an anonymous ftp site that may have such code. 
Thanks in advance!!!! :->


-- 
Carl B. Constantine
CCONSTANTINE@galaxy.gov.bc.ca
	"Opinions are mine only!!"