ParseDatabase

Databases
Aptilis 2

ParseDatabase(db[], dababase_in_a_string)

ParseDatabase will parse a database from a string and will put it into an array.
If you want to load a database from a file, have a look at LoadDatabase.

The function returns the number of records loaded.

IMPORTANT
Any parsing error will cause parsing to stop.

The database must be text with one record per line, the lines being separated by either a LineFeed (LF), or a a Carriage Return plus a LineFeed(CR/LF).
Each field should be enclosed in double quotes and separated from the next field by a comma. (See example 1) You cannot have a double quote within a field
Database files can be created with a simple text editor or exported from commercial database packages like Access, Paradox, etc...

From within an Aptilis programm, to create a database, you have to create records with makeRecord. Although they are printable as strings, database records are not directly usable. The way they are stored internally will vary from platform to platform, and you cannot safely make assumptions about the way a record is stored. (For example, integers may vary in size, as well as the way bits are organized within them). The special format that databases are stored in allows quick retrieval of information by Aptilis.
You must use getField or getAllFields to retrieve fields.
If you are concerned a large database you are using is hampering performances, you can free up the resources it's using, -once you are done with the database- by using clearArray on the array it's been parsed into.

Return value:
The number of records in the database or -1 in case of error, and _errno has some details.

There are other database functions that allow you to isolate one or all the fields from a record, (getField or getAllFields) and to search a database that has been loaded for a given record, according to one field (getRecordIndexByKey, getRecordIndexByNearKey).
Use sortDatabase to sort databases.

You can also create a database within Aptilis by putting records in an array, with makeRecord and then save the database with saveDatabase