Matricsoft - software development | |||||||||||||
news - products - downloads - support / feedback | |||||||||||||
products > Quickdb > file operations | |||||||||||||
|
File operationsclass db { bool read_from_file(string const & filename); bool save_to_file(string const & filename); } Sample//all the data is defined... mydb.read_from_file("mysample.xml"); ... mydb.save_to_file("mysample.xml"); ... bool read_from_file(string const & filename)This method reads a file created with quickdb, in a XML format, and loads the data into the database (which is memory-based). Beware that all the data contained in the memory of the database is erased. Before using this method, all the information relating to the definition of the tables shall have been completed (if the file read contains information about tables or fields that are not defined in the database prioir to the call to read_from_file, an exception will be risen). //first of all we define the data model db mydb("jobs", 2);//name of the database and version of the data model //this information will be present in the file (during writing) //but of no use for the moment mydb.new_table(); mydb.add_field("name", db_string); mydb.add_field("sector", db_string); mydb.commit_table("company"); mydb.new_table(); mydb.add_field("name", db_string); mydb.add_field("surname", db_string); mydb.add_field("age", db_int); mydb.add_field_ref("IDcompany", "company"); mydb.commit_table("employee"); //important: each time you call this method, //you shall catch exceptions (if file does not exist, or whichever reason) mydb.read_from_file("myfile.xml"); //at this stage, all the data in the file has been loaded in memory Before the call to read_from_file, the information model shall be complete, however, the actual data is erased before calling this method (the reason: the relations). Afterwards, the database is loaded in memory and can be accessed normally. bool save_to_file(string const & filename)This method saves all the data inan object db into a file on disk. What is nice is that all the items are now reindexed, even and above all for the relations (however, the object in memory is not changed). //...many operations on mydb... mydb.save_to_file("myfile.xml"); Result: the data is kept on disk, in a XML format (you can give it the extension name you wish, it is not important). All the relations and the deleted records are updated on disk (not in memory). <database> <info> <name>jobs</name> <version>1</version> </info> <data> <employee> <record> <name>john</name> <surname>doe</surname> <age>12</age> </record> </employee> </data> </database> |
||||||||||||
Copyright (c) 2001-2002 Matricsoft info@matricsoft.com |