Python

GUI Programming with
      Python and Qt


Quick Links

Home
Python index
Database Objects
Kura (now maintained by Peter Bouda)
CGI scripting and MySQL
Kpybrowser
Python + KDE Tutorial
Python + KDE Resources
PyKDE example programs
Python and Qt2
PyKDE and PyQt news
A population simulation with Stackless Python
Drift: a language simulation in Python
Anonymous CVS access


Download

dbobj-2.1.tgz


Thanks

Chuck Esterbrook, author of Webware for Python for many helpful suggestions.


Changelog

  • 06-12-2002
    • Added dbobj-2.1
  • 06-04-2002
    • Added unittests.
  • 16-12-2000
    • Released version 1.1
  • 20-11-2000
    • Released version 1.01
  • 23-10-2000
    • Released version 1.0
    • Converted kura to a test application
    • Debugged restoring from xml repositories
  • 18-07-2000
    • Started writing manual
    • Started writing generic test script
    • added createTable to dbSql
    • marked all database dependent places
    • 10-07-2000
    • Added factory functions to the application object
    • Streamlined child/parent lookup functionality
    • Cleanup of the entire interface
  • 02-07-2000
    • Complicated child table support - now not only the tablename is needed, but a pair of keys, too.
    • Removed all support for complicated keys - every table should have a single-column primary key now. This means that the many-to-many LINK table type has disappeared.
  • 22-05-2000 - Version 0.6.0
    • followed Chuck's suggestion and changed db.dbObj to db.dbConn
    • Added xml repository parser and generator
  • 17-03-2000 - Version 0.5.0
    • added listHTML and recordHTML to dbobj.dbTable
  • 30-03-2000 - Version 0.4.0
    • Fixed a lot of bugs
  • 09-12-1999 - Version 0.3.0
    • Added getObject to dbApp
    • Removed nvl bug
    • hashed out unused code
  • 13-10-1999 - Version 0.2.0

© 1999 Boudewijn Rempt

 

Database Objects


Database Objects, or dbObj for short, is a dynamic object-oriented, repository based layer on top of the Python DB-API II spec.


Download

dbObj is developed in sync with Kura database application. When Kura demands new functionality, I will update dbobj. The current version is 2.1 - there might be bugs, but I haven't found them, and it is pretty full-featured.

dbobj-2.1.tgz

Changes since version 2.0: Added a file-based backend. See the textdb module.

dbobj-2.0.tgz

Changes since version 1.1: Added unittests. DbObj is now unashamedly MySQL-specific: database-indendence will be restored in the next version. A lot of convenienve functions have been added to the dbAppDef object. Started with cleaning up the code.

dbobj-1.1.tgz

Changes since version 1.0: Implemented the dbError exception object, added a createDefaultObject to dbAppDef together with further support for records filled with default fields. SQL DDL generation now really works, added a few features to the repository.


Architecture

DbObj wraps the DB-API II spec in several layers. At the bottom, there's a wrapper around the interface. the db.py module connects to the database. asks the database to execute queries and returns results. Nota bene: db.dbObj has been renamed to db.dbConn. But you almost never need to access that class, so that shouldn't hurt a bit.

SQL

At the next layer, sql.py wraps db.py. sql.py dynamically generates SQL statements for select, update, delete and insert. sql.py uses the data entered in the repository to automatically create joins between a base table and the associated lookup tables.

Database objects

Above sql.py, the dbobj.py module provides three classes: dbError, dbRecord and dbTable. dbError is to provide a flexible error handling mechanism, but is not usable at present. dbRecord is an abstract record object that knows how to update, delete or insert itself. It can present columns/values in a dictionary and check for referential integrity. The dbTable class represents the outcome of a query. The select function performs a query on the database, based on the fields present in a dbRecord object, and stores the result in a list of dbRecord objects.

Application specific classes

While the classes present in dbobj.py present a generic represention of database objects, the dbObj framework can also work with classes that are specific to the tables represented. For instance, the lng_language table can be represented by a lng_lngg module that contains the lng_language (dbRecord) and lng_languages(dbTable) classes, which might offer extra functionality, like an html presentation builder or complex business rules. These classes can be stored in a dictionary object:

Repository

The final layer is the repository. The repository describes the datamodel, enabling the other layers to dynamically approach the data in the database. The appobj.py module offers classes like dbPair, which links a pair of fields (for instance the foreign key field in the base table and the primary key field in the lookup table, dbRelation, which defines the relationship between tables, dbFieldDef, which defines the properties of fields, dbTableDef which stores the properties of tables, and finally dbAppdef, which contains the entire structure. Repositories can be saved to and restored from XML files.

The appObj class stores all application classes in a dictionary, enabling a very generic style of developing.

The repository must be built in application memory upon startup: this can happen either in code (for instance, by building a Python dictionary of objects), or by reading the repository from a file or a database. Currently, reading the repository from an XML definition file is supported.