Product Documentation

FairCom SQL for Python

Previous Topic

Next Topic

Python Tutorials

FairCom provides four simple tutorials designed to guide you through the basic use of the FairCom DB SQL Python database interface technology.

As with all other tutorials in the c-tree series, each of these database programming tutorials is implemented with four simple code procedures: Initialize(), Define(), Manage(), and Done().

No matter which FairCom interface language you use, FairCom follows this same high-level flow in all tutorials. This makes it easy for developers to "cross-over" from one language interface to another as these basic concepts apply to all.

Initialize()

Every language requires some form of initial "logon" or "connection" procedure to establish a session with the database. This is done in the Initialize() stage of the program.

Define()

Database definitions (DDL), Table/File schema definitions, Index definitions, Table/File creation, and Table/File open operations are all addressed in the Define() stage of the program.

Manage()

This stage of the program is where the database is operated on, as in managing your data. Adding/Reading/Updating/Deleting records/rows are handled in this stage of the program.

Done()

When the program ends, the database session should be closed. This stage handles the necessities to "de-init", by closing Tables/Files and issuing any required "logoff" or "disconnect" type procedures.

Presented here are tutorials that follow the "Initialize(), Define(), Manage(), and Done()" approach.

You can also view similar tutorials for all supported languages online.

The source code is located in:

<faircom>\drivers\python.sql\tutorials (or <faircom>\drivers\sql.python\tutorials)

Executing the Tutorials

To execute the tutorials, all you need to do is run it from Python. For example, to execute tutorial 2, type the following on a command-line:

python PY_tutorial2.py

Overview

Typically, FairCom DB provides four tutorials for each of its supported APIs. In the case of Python, only two of the tutorials have been implemented:

  • PY_tutorial2.py - This tutorial corresponds to Tutorial 2 in the other APIs. It demonstrates relational tables and indexing.
  • PY_tutorial4.py - This tutorial corresponds to Tutorial 4 in the other APIs. It demonstrates transaction processing.

The following presents a conceptual overview of these tutorials:

PY_tutorial2.py

Tutorial #2: Relational Model and Indexing

Here we now add a bit more complexity, introducing multiple tables, with related indices in order to form a simple "relational" database simulating an Order Entry system. Here is an overview of what will be created:

JDBC Relational Picture

  • Initialize() - Connects to the FairCom DB database engine.
  • Define() - Defines and creates the "custmast", "custordr", "ordritem" and the "itemmast" files/tables with related indices.
  • Manage() - Adds some related records/rows to all files/tables. Then queries this order database.
  • Done() - Disconnects from FairCom DB Database Engine.

PY_tutorial4.py

Tutorial #4: Transaction Processing

Here we demonstrate transaction control.

  • Initialize() - Connects to the FairCom DB database engine.
  • Define() - Defines and creates our four file/tables.
  • Manage() - Adds records/rows to multiple tables under transaction control.
  • Done() - Disconnects from FairCom DB Database Engine.

Use the help file navigation arrows at the top of your browser and the end of each topic (labeled NEXT and PREV) to progress through the tutorials.

Feel free to use these projects as a starting point for your next FairCom DB project!

In This Chapter

Additional Resources and Functionality

TOCIndex