|
Definition operations
class db
{
EType get_field_type(string const & table_name, string const & field_name);
int get_field_index(string const & table_name, string const & field_name);
string get_field_name(string const & table_name, int field_number);
int get_number_field(string const & table_name);
string get_field_ref_relation(string const & table_name, int field_number);}
class db //equivalent methods with indexes:
{
EType get_field_type(int table_number, string const & field_name);
int get_field_index(int table_number, string const & field_name);
string get_field_name(int table_number, int field_number);
int get_number_field(int table_number);
string get_field_ref_relation(int table_number, int field_number);}
Sample
//note: these methods are used internally by quickdb
//They may be useful however...(but not in normal operations)
EType mytype=mydb.get_field_type("company", "name");
switch (mytype)
{
case db_int:
//this is an int field...
break;
case db_long:
//this is a long field...
break;
case db_string:
//this is a string field...
break;
}
int index=mydb.get_field_index("company", "name");
string myname=mydb.get_field_string("company", index);
int nb_fields=mydb.get_number_fields("company");
for (int i=0;i<nb_fields;i++)
{
//do something for each field
}
EType get_field_type(string const & table_name, string const & field_name)
EType get_field_type(int table_number, string const & field_name)
This method returns the type of a field in a table (for instance int, long, string...). The type "EType" is an enumeration defined here.
int get_field_index(string const & table_name, string const & field_name)
int get_field_index(int table_number, string const & field_name)
This method returns the field index given a field name.
int field_index=mydb.get_field_index("company", "name");
string get_field_name(string const & table_name, int field_number)
string get_field_name(int table_number, int field_number)
This method returns the field name given a field index.
string field_name=mydb.get_field_name("company", 0);
int get_number_field(string const & table_name)
int get_number_field(int table_number)
This method gives the number of fields of a given table.
int nb_fields=mydb.get_number_fields("company");
string get_field_ref_relation(string const & table_name, int field_number)
string get_field_ref_relation(int table_number, int field_number)
In the case where a table has a relation with another table, you can get the name of the related table (the "father" table).
//let's suppose we have 2 tables defined this way:
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);//returns 0
mydb.add_field("surname", db_string);//returns 1
mydb.add_field("age", db_int);//returns 2
mydb.add_field_ref("IDcompany", "company");/returns 3
mydb.commit_table("employee");
string myresult=mydb.get_field_ref_relation("employee", 3);
//if you do not know it is the 3rd field:
int field_number=mydb.get_field_index("IDcompany");
string myresult=mydb.get_field_ref_relation("employee", field_number);
//the result of this function shall be "company"
//(because this field is related to the table company)
|