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!
QBasic database .dbf managment?
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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.
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
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
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
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
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