Delete Notes

Discussions about editing and cleaning data
Post Reply
YFT_CBSD
Posts: 54
Joined: January 3rd, 2023, 12:36 am

Delete Notes

Post by YFT_CBSD »

Hi All,

How can I delete notes in csdb using bch application?

Thanks
Gregory Martin
Posts: 1876
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Delete Notes

Post by Gregory Martin »

The ability to modify notes in CSPro logic is limited based on the three note-related functions. Here is an approach that creates a copy of the CSPro DB file, removes all notes uses SQLite, and then processes that file rather than the original file:
PROC DELETE_NOTES_FF

preproc

   
// create a copy of the input data file so that we don't modify the original data
   
string backup_file_path = Path.concat(Temp, maketext("data-backup-%d.csdb", timestamp()));
    filecopy(filename(DELETE_NOTES_DICT), backup_file_path);

    // open this data file as a SQLite file
   
numeric dbId = tonumber(CS.Sqlite.open(path := backup_file_path, openFlags := "readWrite"));

    // delete all rows from the `notes` table
   
CS.Sqlite.exec(db := dbId, sql := "DELETE FROM `notes`;");

    // close this file and reopen it as the data file that is processed during this batch application
   
CS.Sqlite.close(db := dbId);

    setfile(DELETE_NOTES_DICT, backup_file_path);

postproc

   
// delete the temporary data file
   
close(DELETE_NOTES_DICT);
    filedelete(backup_file_path);
You can see how this approach works in the attached application.
delete-notes.7z
(4.36 KiB) Downloaded 222 times
Post Reply