rtf1@cbnewse.ATT.COM (richard.t.ferber) (08/31/89)
Hello All, I am writing a simple database program in Turbo Pascal (version 5) that uses a TYPED file to store data records. One of the basic operations I want the program to do is to delete records in the file (along with add, update, etc.). After looking through the standard library I couldn't find a procedure to do this. I figure I'll have to set up a TempFile and copy all the records to it except the record to be deleted and them rename it to the original file. This doesn't seem optimal to me. Any advice or suggestions? Rick Ferber AT&T Bell Labs
mlw@pyr.gatech.EDU (Michael Williams) (08/31/89)
In article <833@cbnewse.ATT.COM> rtf1@cbnewse.ATT.COM (richard.t.ferber) writes: > >I am writing a simple database program in Turbo Pascal (version 5) that >uses a TYPED file to store data records. One of the basic operations I >want the program to do is to delete records in the file (along with add, >update, etc.). It depends on how you are storing your records. If you are trying to keep them in some kind of order, it will be necessary to 'slide' them all down one and call truncate at the last position in the file. Otherwise, you could just swap the last record for the one to be deleted, and then do the truncate. Another approach is to have a boolean 'used' in each record to simply mark deleted ones, taking care of the actual deletion at a later time to improve efficiency. Hope this helps ... -- Michael Williams Georgia Insitute of Technology, Atlanta Georgia, 30332 uucp: ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!mlw ARPA: mlw@pyr.gatech.edu
mg2n+@andrew.cmu.edu (Martin G. Greenberg) (08/31/89)
A bunch of other people and I are involved in a similar project involving a database, and you have basically two ways to accomplish add, delete, etc. on a typed file. 1) The method mentioned in the original message. This is probably the most straight forward, but if the database is very large, it is very slow and you can run out of disk space at times. 2) Take advantage of TP's allowing you to SEEK positions in a file. This way you can do bump everything down and add the new record, or bump a section of the file back (over-write the record to delete) and then TRUNCATE the file so that it is one record shorter. This all assumes that you actually want to remove the record and not just use a flag to mark it, or some such scheme. MGG
ncsmith@ndsuvax.UUCP (Timothy Lyle Smith) (09/05/89)
In article <833@cbnewse.ATT.COM> rtf1@cbnewse.ATT.COM (richard.t.ferber) writes: >I am writing a simple database program in Turbo Pascal (version 5) that >uses a TYPED file to store data records. One of the basic operations I >want the program to do is to delete records in the file (along with add, [stuff about lack of delete operation on TYPEd files] If you are going to be changing the size of the file often it would be quickest to mantain a freelist internal to the file. You could either sacrafice a record to be the head of the list or you could store the head of the list off in a different file. To link you freelist together you could cast a record type containing your link field onto the record that you are unlinking or linking from/to the free list. -- Tim Smith North Dakota State University, Fargo, ND 58105 UUCP: ...!uunet!ndsuvax!ncsmith | 90% of the people on this planet BITNET: ncsmith@ndsuvax.bitnet | are crazy and the rest of us are INTERNET: ncsmith@plains.NoDak.edu | in grave danger of contamination