BASIC Driver does not Delete records

I am using the BASIC Driver to write out some data to a CSV file and am having 2 problems. I am using C8 Legacy

  1. Even though the data file has the CREATE attribute in the dictionary, it will not create the file if it does not exist

  2. I cannot delete records from the csv file. Here is the code I am using:

DataDumpToCSV       ROUTINE
    ! empty the DataDump file
    OPEN(DataDump) ; OPEN(TileChildren) ; OPEN(TileParents)
    SET(DataDump) 
    LOOP !UNTIL ERRORCODE()
            !MESSAGE('Start of Data Dump Delete Routine')
        NEXT(DataDump) ; IF ERRORCODE() THEN BREAK. !; MESSAGE(CSV:TileID & '|' & CSV:ChildTileID)
        DELETE(DataDump)
    END

When I uncomment (?) the MESSAGE statement, I can see that the records are being read, but not deleted. It is not throwing any errors (until EOF). I can write to the file in a later piece of code.

Any ideas? I do not want to buy and templates …

ty

Hi Mark

you cannot delete records using the BASIC driver. Have a look in the help under supported commands.

also show your code for create.

eg something like

CREATE(DataDump)
if errorcode() then message(…).

one final thing - always check errorcode() after I/O. eg after your open and delete as well as your next (where you did check it). I presume delete would throw an error given it is listed as unsupported.

cheers

Geoff R

Thanks Geoff - I read through the Data Driver Help and the Delete and must have missed that I cannot delete from a BASIC driver. UGH - No errors during compile or run …

thanks - will try to work it further

Geoff, I just implemented your suggested changes and all is well. thank you!

The default for OPEN(file) is Exclusive i.e. DenyAll. This can easily result in an Error 5 “Access Denied” if another Thread or EXE has the file open. Safer to use SHARE(file) that is DenyNone.

As Geoff said checking for errors is the only way to know why code is failing. I’ll extend his example a bit, your message should show the Code and Text.

CREATE(DataDump)
if errorcode() then 
   message('Create DataDump failed with error '& ErrorCode() &' '& Error() …)
end

It should gracefully handle the error, i.e. close filed and exit. On an Error 5 your the message could tell them to close the file if they have it open in another program (like Excel) and have a Retry button.