LoadDatabase |
Databases | |
Aptilis 1 |
LoadDatabase(DestinationArrayName[], FileName[, login, password])
LoadDatabase will load a database from a file and will put it into an array.
If you want to parse a database yourself from a string, have a look at
ParseDatabase.
LoadDatabase does not need the login and password parameters,
unless you are trying to load the database over the ftp protocol:
loadDatabase(db[], "ftp://ftp.server.com/somedir/anotherdir/aDatabase.txt", "login", "password")
Protocols supported: ftp and file.
The function returns the number of records loaded,
or -1 if there has been an error, in which case you
can have a look at _errno$ for details about what went
wrong with the file.
IMPORTANT
Any parsing error will cause loading to stop.
The database
must be a text file 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 how a record is stored. (For
example, integers may vary in size, as well as the way bits are
organized within them)
You must use getField or
getAllFields
to retrieve fields.
If you are concerned a large database you loaded 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 loaded into.
Return value:
The number of records in the database or -1 in case of error, and
_errno has some details.
Example 1:
a database:
What loaddatabase does is to load each line (=record) of
the database in an element of the array you have specified.
Example 2:
Loading the above database, assuming we are on
a windows type machine.
// Backslash is a special character! n = loaddatabase(db[], "c:\\databases\\cars\\cars.txt") print("There are ", int(n), " records")
There are 3 records |
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