AppendRecord

Databases
Aptilis 1

AppendRecord(FileName, Record)

AppendRecord allows you to add a single record at the end of an existing database.
While in variables, records are stored in a platform dependant, 'weird' format, that is not readily understandable by humans.
AppendRecord and saveDatabase convert this machine-friendly format into plain text that makes sense for us.

Return value:
The number of characters written, or -1 in case of error.

Example:


// just to be tidy
clearArray(r[])

// Animal, How many legs, feeds on
r[0] = makeRecord("Dog", "4", "Meat, old shoes")
r[1] = makeRecord("Cat", "4", "Jimmy the goldfish")
r[2] = makeRecord("Man", "2", "What's on the menu?")

saveDatabase("my_db.txt", r[])

// Oops! We forgot one! (The record could be added at any time)
forgottenRecord = makeRecord("Shark", "0", "People")
appendRecord("my_db.txt", forgottenRecord$)
The file 'my_db.txt' now contains:
"Dog","4","Meat, old shoes"
"Cat","4","Jimmy the goldfish"
"Man","2","What's on the menu?"
"Shark","0","People"