Page 1 of 1

record.ID in DELETE

Posted: Thu Sep 15, 2005 1:21 am
by Gokul
Hi,

In the Delete statement given in the supporting PDF

DELETE [file.variable,] record.ID [ON ERROR statements]
[LOCKED statements]
[THEN statements] [ELSE statements].

What is record.ID?

I tried with a file abc.txt containing one record having value "Hello".

The Delete statement used to delete the record is

Code: Select all

OPENSEQ "/home/w951/temp/abc.txt" TO fwrote 
THEN
     DELETE fwrote,"Hello" 
     Then 
        Ans = status()
        CLOSESEQ fwrote
     End
END.
It gave me error "Line 8, Improper data type".

I even tried with

Code: Select all

DELETE fwrote,1
,but the same error.

What should be the value for the record.ID in the above case?

Thanks,
Gokul



[/code]

Posted: Thu Sep 15, 2005 1:27 am
by ArndW
Gokul,

the DELETE statement only works on hashed files; sequential files can only be read sequentially, so DELETEing a row using this statement cannot work. The only way to delete a line from a sequential file is to make a copy - meaning you can't update the file, but need to read and then write rows from 1 to {your row to be deleted-1} to the copy file, skip the row, and then copy the rest.

Posted: Thu Sep 15, 2005 1:28 am
by ray.wurlod
You can not use DELETE on a file opened with OPENSEQ.

You can only use DELETE on a file opened with OPEN or OPENPATH, which the documentation tells you; the file variable is assigned "in a previous OPEN statement".

If you are seeking a way to delete a line from a text file, you have essentially two choices.
  • One is to read the file a line at a time and write a copy, skipping the line in question. You could also do this with grep -v command.

    The other is to open the file's parent directory, read the file as if it were a record in a database table (the file name is the record "key"), LOCATE the line you want to delete, use a DELETE() function (or DEL statement) to remove that field, then write the "record" back to the "table".