OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME

GETTING STARTED

This document is your starting point in using OOFILE, if you know a bit about database concepts.

If you don't know much about databases, you should first read Database Concepts for an introduction to database concepts, and how they map to OOFILE

See also:
- Installation to install OOFILE, the samples and c-tree.
- The example programs that illustrate one key concept each.
- The feature index for a full list of the currently available features


STEPS IN CREATING A SIMPLE DATABASE

1) #include "oofile.h"

2) declare your database tables,
ie: DECLARE_CLASS(myTable)...

3) define a database "connection" variable, eg:
dbConnect_ctree myDatabase

4) (MUST be after 3) in your code) - define table variables, eg:
myTable aTableInTheConnection;

5) create or open a database connection, eg:
myDatabase.createConnection("a file on disk");

SIMPLE EXAMPLE

DECLARE_CLASS(dbPatients)

dbChar LastName, Othernames;
dbLong Salary;

dbPatients() :

LastName(40, "Last Name", kIndexed),
Othernames(80, "Other names"),
Salary("Salary")
 

{};


};

// declaring the concrete variables
dbConnect_ctree theDatabase;
dbPatients Patients;

int main() {

theDatabase.newConnection("Simple.db");
Patients.newRecord();
Patients.LastName = "Dent";
Patients.Salary = 99000;
Patients.saveRecord();
cout << theDatabase; // displays our record on the screen
return 0;

}

RELATIONSHIPS

One of the big features of an ODBMS is modelling the relationships between objects. OOFILE allows you to model relations in a pure ODBMS sense, using object identifiers, or explicitly perform runtime joins over database fields. This would be mainly used by people porting existing database structures.

EXTRA STEPS IN CREATING RELATIONSHIPS

6) Declare the classes that traverse the relationship, eg:
DECLARE_REF(dbPatients) declares a Ref which refers to just one Patient

7) Include a member in each table for the relationships, eg in Visits:
dbPatientsRef Patient;

8) *After* defining the variables for the tables (see point 4) define a dbRelationship for each relationship, that says which tables are related.

The following example extends our first effort and adds a related table with a 1-N relationship between Patients and Visits:

DECLARE_REF(dbPatients)
DECLARE_SET(dbVisits)

DECLARE_CLASS(dbPatients)

dbChar LastName, Othernames;
dbVisitsSet Visits;
dbLong Salary;

dbPatients() :

LastName(40, "Last Name", kIndexed),
Othernames(80, "Other names"),
Salary("Salary")


{};


};

DECLARE_CLASS(dbVisits)

dbPatientsRef Patient;
dbDate VisitDate;
dbText Why;

dbVisits() :

VisitDate("VisitDate", kIndexed),
Why("Reason for Visit")


{};


};

// declaring the concrete variables
dbConnect_ctree theDatabase;
dbPatients Patients;
dbVisits Visits;
dbRelationship(Patients.Visits, Visits.Patient);

int main() {

theDatabase.newConnection("Sample2.db");
Patients.newRecord();
Patients.LastName = "Dent";
Patients.Visits->newRecord();
Patients.Visits->VisitDate = "12th May";
Patients.Visits->Why = "Flu";
Patients.Visits->newRecord();
Patients.Visits->VisitDate = "1st June 96";
Patients.Visits->Why = "Stress and incipient Computer Phobia";
Patients.saveRecord(); // also saves the related records
cout << theDatabase;
return 0;


}

RECOMMENDED EXPERIMENTS

Copy the OOFTest project and try building each of the different sample programs. Vary some of the operations slightly, eg: change the search criteria in tests 1, 7 & 12 to get different records returned.

Write down a simple database schema, eg: an Address book, and try to write the OOFILE class declaration.

Once you have your database schema compiling, add some data and dump out the database to the console (see test 1).

Write a few simple search expressions for your database, using inline constants, and dump the results (see tests 1, 7, & 12).

Take your search expressions and change the constants to variables. Put your search inside a loop and display the results to the console, so you can read in different search values and see the results. (test 7 has some searches using variables, inside methods)

Add a related table to your database (if you will be using relationships) and try adding and deleting child records. (see tests 2, 6 & 9)

GUI Experiments

Look at the first version of FileAndFind. Try adding an edit field to the dialog, which is linked to a new dbChar field in the database. (Note: if you change the database schema, you are not currently able to open old databases.)

Change the FileAndFind browse window to display a different set of fields.

Mac AppMaker users:
Take the FileAndFind example AppMaker project, and add a couple of extra editing fields, linked to the database. Try generating and running the result.

Compose a simple application yourself, with just a few editable fields. Add OOFILE declarations of the data and link the fields to the database. It will probably be easier to build a little console application like our samples, to enter and dump the test data, without the complications of debugging your GUI.


Feature index

(c) Copyright A.D. Software 1994-2003 (All Rights Reserved).
Last Updated: 5th May 2003