QBasic database .dbf managment?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
m4rk0

QBasic database .dbf managment?

Post by m4rk0 »

Hello.
Can someone give me code which will erase rows from database...

For example I have database with 5000 rows, and I want to delete first 3500 of rows (records)?

Any example?

Thank You!
Quibbler

Post by Quibbler »

Are the fields delimited or are they fixed length?
Having dealt with .dbf files before I know the headers can also be a big problem - does it have headers?
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Best think I can tell you is to take a look here:

http://qbcm.hybd.net/issues/2-2/

Ethan Winer has a tutorial there that deals with the DBF file format and how to manage it.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Guest

Post by Guest »

@MystikShadows: Thanx, but there only DB CREATE, DB STRUCT, DB PACK, no DELETE :(

@Quibbler: Hm there is about 10 fields and almost all different. Some are for TEXT only, some for NUMBERS only...

Thanx anyway :)
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

ok in order to delete a record in a DBF you need to set it's deleted state. Once that's done, you can use DBPACK to physically delete those records from the database...Sorry forgot to mention that. DBF always worked that way. typically the first byte of that record is the deleted status.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Quibbler

Post by Quibbler »

Ok so I've found a program I used to read DBF files. It may give you some ideas. Of course there is no guarantee that all .dbf files follow this format. The header seems to be in 32 byte blocks if the first byte is hex0D then it means "start of data" otherwise the 17th byte gives the length of a field so adding up all the 17th bytes gives the total record length.

Code: Select all

CLS
DIM a AS STRING * 32
DIM b AS STRING * 1
OPEN "r", #1, "c:\data3\datafile.dbf", 32
GET #1, , a
FOR i = 1 TO 5000
GET #1, , a
IF ASC(LEFT$(a, 1)) = &HD THEN 100
j = ASC(MID$(a, 17, 1))
k = k + j
NEXT i
100 CLOSE #1
j = 0
srec = (i * 32) + 2
recl = k + 1
OPEN "b", #1, "c:\data3\datafile.dbf"
FOR i = srec TO 5000
GET #1, i, b
j = j + 1
q$ = q$ + b
IF j = recl THEN
count = count + 1
PRINT q$; " "; count
j = 0
q$ = ""
END IF
NEXT i
CLOSE #1
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

You can get the dbf format description from www.wotsit.org
And yes, to erase a record, just mark it as unused. The pack function copies the dbf in another one skiping the erased fields, then deletes the original.

BTW: Ethan winer dbf library is not portable to FB, as it's based in the FIELD instruction, not implemented in FB
Post Reply