C++ ODBC Genealogical Sample

The DBGene sample application uses a classic Prolog application idea to illustrate how the Amzi! Logic Server can be used to provide the services of Prolog in conventional application environments. Given a genealogical database of information about people, the application lets you pose queries about various relationships, such as sister, uncle, grandparent, and ancestor.

This implementation was built with three tools:

The glue for the application is the Amzi! Logic Server. The application:

To learn more see:

Using DBGene as stand-alone Prolog - How to run just the Prolog program.

Using DBGene with C++ front-end - How to use the sample, and how to put in your own family database.

Application Architecture - Details on the implementation, including annotated source code.

www.amzi.com - Additional demos, articles, freeware, evaluation copies and information about Amzi! Prolog + Logic Server.

We welcome any and all comments about this demo. Contact us at www.amzi.com

Running Stand-Alone Prolog version

Simply open the project in Eclipse and run the project, either interpreted or compiled. The dbgene.pro file can also be run as a single file. Follow the prompts.

Running an Prolog program that uses ODBC requires two things: 1) to load the LSX amzi/bin/aodbc.lsx; and 2) to load the PLM amzi/abin/aodbc.plm. These can be done directly in the source code of the application file:

% Load the LSX that provides the extended predicates
% for the ODBC interface. This could also be done
% from amzi.cfg, or from a Logic Server host language
% program.
:- loadlsx('aodbc.lsx').
% Make user the Prolog portion of the ODBC library,
% which provides a Prolog-like interface to the
% database, is loaded, and that its predicates are
% imported.
:- ensure_loaded(aodbc).
:- import(aodbc).

AODBC.LSX could also be loaded using amzi.cfg, but the direct loading method above is easier. See Amzi! runtime documentation for details on using amzi.cfg for loading LSXs.

AODBC.PLM could be linked with the program, which is preferred for running a compiled application. When that is done, the .plm is linked into the application .xpl file.

In the Eclipse project for DBGENE, you can also specify in the project properties that AODBC LSX and PLM are needed, and then, when running or building in Eclipse, the correct files will be loaded. Note that using ensure_loaded/1 means that aodbc.plm will be loaded only if it hasn't already been loaded, say by Eclipse or being linked into a .xpl file.

Building the C++ Sample

  1. Open the C++ Project in Visual Studio and build dbgene.exe
  2. Build the Prolog project by compiling dbgene.pro and linking it with the aodbc library.

Running the C++ Sample

To run it you need:

  1. ODBC 2.0 installed
  2. AODBC.LSX somewhere in your path (it is in amzi\bin).
  3. A data source named 'gene' defined in your 32-bit ODBC administrator (in the control panel) that uses the gene.mdb database included with this demo.


Using DBGene

To use DBGene, you must have ODBC installed and the Microsoft Access driver. Use the ODBC control panel to add a data source named 'gene' that accesses the gene.mdb.

DBGene automatically loads the ODBC database, 'gene' and the logic base, 'dbgene'. The middle listbox contains the names of the people in the gene database. The left hand listbox contains a list of the relations the dbgene logic base knows about. If you select a relation and an individual and push the 'Query' button, the names of the people who satisfy that relation appear in the right hand box.

If you have the tools to modify the database, which was created using Microsoft Access, you can fill it with individuals from your own family tree. Or you can replace the gene database with an ODBC database of your own choosing.


DBGENE Application Architecture

The DBGene application is composed of three components The database contains two tables, one defining people, with information such as a unique ID number, name, date-of-birth, and parents, and the other defining marriages, with the ID numbers of the individuals in each marriage.

The logic base contains rules that define relationships based on the database. These are rules that express what it means to be a sibling, uncle, ancestor, etc. At the base of each of these rules are Prolog predicates that map directly to the database, using the Logic Server ODBC extension.

The user interface contains list boxes that present the pertinent information from the logic base. That information is obtained from a C++ class that encapsulates the logic base services.


Database

The database used in this example is an Access database. If you have Access, you can edit it directly to reflect your own family tree. If you have a different database with an ODBC driver, you can create tables like these for your own family and assign the ODBC database name 'gene' to your database.

There are two tables in the database defined as follows.

Person

Marriage * - Fields that are used in this demonstration. Other fields are ignored.

The Sample People

The people in the sample database have decided to propagate maternal family names through the middle name, just as paternal family names are often propagated by the last name. That is, the children of a marriage take the middle name of the mother and the last name of the father. That way the daughters carry on the maternal family name and the sons carry on the paternal family names, and you can get a better sense by looking at the names who might be related to whom.

Individuals with the same middle and last name are the top of the ancestral tree and also have parents indicated by the PersonID 0.


Logic Base

This is the Prolog code used to define the genealogical logic base. To use it the host language must first open the ODBC connection by calling the db_open/1 predicate.

The code consists of these primary sections:

The query interface designed for use from a host language program. Other versions of the program have different interfaces.


User Interface

The Visual C++ interface consists of a simple dialog box and a class that encapsulates the Prolog services portion of the application, used to populate the list boxes of the dialog.

Some of the files in the application are pure boiler plate generated by the application wizard of Visual C++. That code is not included here. The code listed is:

progene.h - the header file for the class that encapsulates the Prolog services, based on the Logic Server C++ wrapper class.

progene.cpp - the implementation file for the ProGene class. Its primary function is to take one of the three list boxes of the application as input and fill it with the appropriate information derived from the Logic Base. API calls that loop through lists and queries are used to generate all the information required for each list box.

dbgendlg.cpp - the main dialog implementation that use the ProGene services. The OnInitDialog function calls ProGene to fill up the relations and individuals list boxes, and the OnQuery function passes the selected name and relation to ProGene, which then fills in the answers list box.


Copyright ©1987-2004 Amzi! inc. All Rights Reserved. Amzi! is a registered trademark and Logic Server and e-Prolog are trademarks of Amzi! inc.