PocketC 4 [3.61] DATABASE I/O All the database functions work on databases with any creator id/type, but use of resource databases may cause unexpected results. When creating a new database, the database will have creator id 'PktC' and type 'user'. An attempt to overwrite a database with a given name but different creator/type will fail. Only one database can be open at a time. dbopen(string name) opens the database named name, returns 0 on failure. The current record is set to 0. --- dbcreate(string name) creates and opens a database named name, returns 0 on failure. If another database of the same name and cid/type 'PktC' / 'user' exists, it will be overwritten. The current record is set to 0. --- dbrec(int recnum) sets the current record to rec and the current position to 0. If the record is greater than the current number of records, future reads will fail. However, the next write will create a new record at the end of the database and set the current record to it. --- dbnrecs() returns the number of records in the current database. --- dbsize() returns the size of the current record in bytes. --- dbwrite(data) write the value data at the end of the current record. data can be of any type, use casting to ensure that data is the correct type. Use caution when writing in the middle of a database with null-terminated strings, as they are of unknown length. --- dbread(char type) read a value from the current position in the database. A value must be read as the same type that it was written. Available types are 'c' char, 'i' int, 'f' float, 's' string. --- dbwritex(pointer ptr, string format) Using the current database, write data pointed to by ptr and described by format at the current position in the current record. format contains a list of data types, one per value following ptr. Data types are 'c' - a single byte, 'i2' - a 2-byte word, 'i4' - 4-byte double word, 'f' - a 4-byte float, 'sz' - a null-terminated string, 's#' - a string of length #. Returns the number of values written. --- dbreadx(pointer ptr, string format) Using the current database, read data of the the given format into the data pointed to by ptr. format is the same as dbwritex(). Returns the number of values read. --- dbpos() get the current location in the database. -1 indicates the end has been reached. --- dbseek(int loc) set the current location. If this value is greater than the length of the database, the next call to dbread() will set the position to -1. --- dbbackup(int flag) flag [0] clear backup bit, [1] set backup bit, [2] query backup bit. --- dbclose() close the current database. --- dbdelete() delete and close the current database. --- dberase() erases the content of the current record (but does not remove the record). --- dbdelrec(int recnum) deletes the specified record from the current database. This removes the contents of the record and sets its 'delete' bit, which will cause the record to be removed on the next HotSync. Returns 0 on error. --- dbarcrec(int recnum) archives the specified record from the current database. This maintains the contents of the record and sets its 'delete' bit, which will cause the record to be removed and archived on the next HotSync. Returns 0 on error. --- dbremrec(int recnum) removes the specified record from the current database. This removes all traces of the record. Returns 0 on error. --- dbenum(int first, string type, string creator) enumerates the databases installed on the device, by type and/or creator. Returns 0 if no more databases are available. The type and creator are each 4 character strings, or the empty string for a wildcard. To get the first database, you must set first=1. To get the subsequent matching databases you must set first=0.