start.htmTEXTBlWdJNJNa[ Quick Start

Back to index


GETTING STARTED

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

See also:
- install.txt to install OOFILE, the samples and c-tree.
- dbbegin.txt for a discussion of database concepts, and how they map to OOFILE.
- the programs in the 'samples' directory, which illustrate one key concept each.

STEPS IN CREATING A SIMPLE DATABASE

1) #include "oofile.hpp"

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.

NOT-RECOMMENDED

Using the debugger to trace the OOFILE code through database operations. Unless you are an experienced c++ programmer, it is very easy to get lost in the relationship between the fields, tables and backend classes.

I'm a great fan of ACI's ObjectMaster. Depending on your environment, you may have a similar tool for browsing code. The most useful parts of a tool are being able to quickly drill-down a method call to see where it goes.


Back to index


Z Macintosh HD start.htmPartSIT!PartSIT!u Macintosh HDMove&Rename@@@zF  w%w%w%    w%w%w%  "a/Q  w%w%w%'  (  w%w%w%/  0  w%w%w%;  <  w%w%w%s   w%w%w%   w%w%w%  w%w%w%   w%w%w%    w%w%w%  !  w%w%w%%  ^  w%w%w%b    w%w%w%    w%w%w%     w%w%w% 5  w%w%w%:  ;  w%w%w%>  X  w%w%w%[  }  w%w%w%    w%w%w%    w%w%w%    w%w%w%  >  w%w%w%B  e  w%w%w%h    w%w%w%    w%w%w%    w%w%w%   w%w%w%    w%w%w%    w%w%w%    w%w%w%     w%w%w%  0  w%w%w%4  5  w%w%w%9  I  w%w%w%M  N  w%w%w%R  S  w%w%w%\  j  w%w%w%n  o  w%w%w%s    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%  )  w%w%w%-  L  w%w%w%P  m  w%w%w%p  q  w%w%w%u    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%     w%w%w%$  e  w%w%w%i  s  w%w%w%y  {  w%w%w%~    w%w%w%   w%w%w%    w%w%w%    w%w%w%    w%w%w%  0  w%w%w%4  }  w%w%w%    w%w%w%    w%w%w%  z  w%w%w% }   w%w%w%     w%w%w%   1  w%w%w% 4  5  w%w%w% 9  R  w%w%w% V  W  w%w%w% [  y  w%w%w% }  ~  w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%     w%w%w%     w%w%w%   ,  w%w%w% 0  1  w%w%w% 5  I  w%w%w% R  S  w%w%w% W  [  w%w%w% d  h  w%w%w% k  l  w%w%w% p   w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%   "  w%w%w% &  '  w%w%w% +  F  w%w%w% O  P  w%w%w% T  X  w%w%w% a  e  w%w%w% h   w%w%w%    w%w%w%    w%w%w%    w%w%w%   #  w%w%w% &  '  w%w%w% +  7  w%w%w% ;  <  w%w%w% @  i  w%w%w% m  n  w%w%w% r   w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%     w%w%w%     w%w%w%  .  w%w%w%1  2  w%w%w%6  T  w%w%w%X  Y  w%w%w%]    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%    w%w%w%  8  w%w%w%<  =  w%w%w%A  K  w%w%w%T  V  w%w%w%_ v  w%w%w%  K  w%w%w%P    w%w%w%  /  w%w%w%4    w%w%w%    w%w%w%  H  w%w%w%Q `  w%w%w%j  O  w%w%w%T    w%w%w%    w%w%w%  R  w%w%w%W    w%w%w%   w%w%w%    w%w%w%  f  w%w%w%k  l  w%w%w%    w%w%w%    w%w%w%    w%w%w%  Z0rZstylsoup&88592202h