Matricsoft - software development
products > Quickdb > database operations
description
database creation
table creation
record creation
record retrieval
record operations
file operations
database operations
definition operations
exceptions
relations
header file

Database operations

class db
{
    void   erase_data();

    void   delete_table(int table_index);
    int    get_number_tables(); 
    
    bool   table_exist(int table_number);
    
    int    get_table_index(string const & table_name);
    string get_table_name(int table_index);
}

Sample

mydb.erase_data();//erase all the data of the database

int nb_tables=mydb.get_number_tables();
for (int i=0;i<nb_tables;i++)
{
    if (mydb.table_exist(i))
        mydb.delete_table(i);
}
int index=mydb.get_table_index("company");
string name=mydb.get_table_name(0);

void erase_data()

This method erases all the data in the database (it is not destroyed, however, all data is destroyed, and the indexes are put to 0). This method is used if you use a reference or an object and not a pointeur.

db mydb("jobs"); //db created
...
mydb.erase_data();//db erased
//if you have a pointer, you may prefer this: (it is cleaner)
db * otherdb =new db("jobs");
...
delete otherdb;

void delete_table(int table_number)

This method deletes a table (all the data and the definition) from a database. It is normally not used (the only case is where you create a database manager).

int get_number_tables()

This method returns the number of tables in a database. It normally corresponds to the actual number of tables (except if you delete tables, but this is a rare case).

int nb_tables=mydb.get_number_tables();
for (int i=0;i<nb_tables;i++)
{ 
   ...
}

bool table_exist(int table_number)

This method returns true if the table exists, otherwise false (if the table has not been created or has been deleted). Normally not used if you do not delete tables.

int n_tables=mydb.get_number_tables();
for (int i=0;i<nb_tables;i++)
{
    if (mydb.tables_exist(i))
    {
         ...
    }
    else
    {
         ...
    }
}

int get_table_index(string const & table_name)

This method returns the index of a given table.

int index=mydb.get_table_index("company");
//the same table is accessible via the index or the name

string get_table_name(int table_index)

This method returns the name of a given table.

string table_name=mydb.get_table_name(0);
//we get the name of the table 0