Link to home
Start Free TrialLog in
Avatar of Kristao
Kristao

asked on

Records

Hi

ok my app works with recors in file all is very well and works just fine, but how to delete record somewhere in middle of file?

exsample:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>file
1record, 2record, 3record, 4record, 5record, 6record, 7record
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<EoF

ok i want to delete recor 4 how to do that? I tried to do something like this:

seek (DB,4);
     rec.test1:='' '';
     rec.test2:='' '';
     rec.test3:='' '';
write(DB,rec);

but as you can see now record 4 is just emty record :)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>file
1record, 2record, 3record, 4emty, 5record, 6record, 7record
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<EoF

and if app will put records on table user will see on emty row

<<<table>>>
--C1--C2--C3
--R1--R1--R1
--R2--R2--R2
--R3--R3--R3
--Emty Row
--R5--R5--R5
--R6--R6--R6
--R7--R7--R7
>>>table<<<

thx
Avatar of kretzschmar
kretzschmar
Flag of Germany image

two possibilities

<<<table>>>
--C1--C2--C3
--R1--R1--R1
--R2--R2--R2
--R3--R3--R3
--Emty Row    //<--- remove and shift
--R5--R5--R5
--R6--R6--R6
--R7--R7--R7
>>>table<<<

<<<table>>>
--C1--C2--C3
--R1--R1--R1
--R2--R2--R2
--R3--R3--R3
--R5--R5--R5
--R6--R6--R6
--R7--R7--R7
>>>table<<<

or

<<<table>>>
--C1--C2--C3
--R1--R1--R1
--R2--R2--R2
--R3--R3--R3
--Emty Row       //<-- swap last into
--R5--R5--R5
--R6--R6--R6
--R7--R7--R7
>>>table<<<

<<<table>>>
--C1--C2--C3
--R1--R1--R1
--R2--R2--R2
--R3--R3--R3
--R7--R7--R7
--R5--R5--R5
--R6--R6--R6
>>>table<<<

which method do you prefere
(second one is faster, but you lose a sorting, if there is one)

meikl ;-)
use Seek to go back and write over the previous record from the position you want till the end of the file...
Avatar of KyleyHarris
KyleyHarris

The problem here is that they are all going to be slow if using a big file with lots of movement. Hence the concept of an index.


Simplistic approach.

Keep 2 seperate files which are essenstially must faster lookup files. One file could keep a list of offsets for deleted records, the second is a list of offsets for the non-deleted ones. Every now and then you do a pack.

Another simple option. (If modifying the record structure is an option)

add a Prev and Next fields to the record and create a linked list in your file. This way instead of deleting the record you just modify the Next value of the deleteds "Prev" record etc. this way you are not relying on physical location in file for a record.

Either way You would be best to create and use an index file for managing the records.

The standard DBF database method is that there is a 1 byte field for deleted at the start of each record. allowing for recycling of deleted records.
>The problem here is that they are all going to be slow if using a >big file with lots of movement. Hence the concept of an index.

not really, my second to do sample has allways the "same" performance, even on a huge file

well, digging out two samples

meikl ;-)


True. I was making the assumption that the data may well be stored in Order Specific detail. Your solution would get a similar speed to a link-list method, but without order.

Of course, they'd both work well enough if an index file was maintained.

Also. There are plenty of free databases around. so unless you're fixed on the current model. I'd really recommend using a database. Databases are not just things you use for a million records. They work well on small groups of data such as an embedded database like DBF or Flashfiler from turbopower
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kristao

ASKER

thx kretzschmar for fast answer :)

yep i tried all this before but my code was mesy, and the trick to check emty rows in table and hide them isn't for me, don't like it.