Table of Contents

Class: DBReflector | Twisted-0.17.4/twisted/enterprise/row.py
--- | ---

### I reflect on a database and load RowObjects from it.

In order to do this, I interrogate a relational database to extract schema information and interface with RowObject class objects that can interact with specific tables. Currently this works only with PostgreSQL databases, but this functionality will hopefully be extended

Base Classes |
--- | ---
adbapi.Augmentation

Methods |
--- | ---

__init__ __setstate__ _cbSelectData _objectLoader _populate _populateRowClass _transPopulateClasses | buildDeleteSQL buildInsertSQL buildSelectSQL buildUpdateSQL deleteRow deleteRowSQL getTableInfo | insertRow insertRowSQL loadObjectsFrom selectRow selectRowSQL updateRow updateRowSQL

| __init__

    __init__ (
            self,
            dbpool,
            stubs,
            populatedCallback,
            )

### Initialize me against a database.

#### Arguments:

- dbpool: a database pool.

- stubs: a set of definitions of classes to construct, of the form [ (StubClass, databaseTableName, KeyColumns) ]

  Each StubClass is a user-defined class that the constructed class will be constructed from. It should be derived from RowObject.

| __setstate__

    __setstate__ ( self,  state )

| _cbSelectData

    _cbSelectData (
            self,
            data,
            rowObject,
            )

Exceptions |
--- | ---
DBError( "select data included more than one row" ) DBError( "select data was empty" )

| _objectLoader

    _objectLoader (
            self,
            transaction,
            tableName,
            keyColumns,
            data,
            rowClass,
            whereClause,
            factoryMethod,
            )

worker method to load objects from a table.

| _populate

    _populate ( self )

| _populateRowClass

    _populateRowClass (
            self,
            transaction,
            rowClass,
            tableName,
            keyColumns,
            )

construct all the SQL for database operations on <tableName> and populate the class <rowClass> with that info. NOTE: works with Postgresql for now... NOTE: 26 - 29 are system column types that you shouldn't use...

Exceptions |
--- | ---
e

| _transPopulateClasses

    _transPopulateClasses ( self,  transaction )

Used to construct the row classes in a single interaction.

Exceptions |
--- | ---
DBError( "Stub class must be derived from RowClass" )

| buildDeleteSQL

    buildDeleteSQL (
            self,
            tableName,
            keyColumns,
            )

Build the SQL to delete a row from the table.

| buildInsertSQL

    buildInsertSQL (
            self,
            tableName,
            columns,
            )

### (Internal) Build SQL to insert a new row.

Returns: SQL that is used to insert a new row for a rowObject instance not created from the database.

| buildSelectSQL

    buildSelectSQL (
            self,
            rowClass,
            tableName,
            columns,
            keyColumns,
            )

(Internal) Build SQL to select a row for an existing rowObject.

Exceptions |
--- | ---
DBError("Error: %r while formatting %s" %( dbe.args [ 0 ], rowClass ) )

| buildUpdateSQL

    buildUpdateSQL (
            self,
            rowClass,
            tableName,
            columns,
            keyColumns,
            )

### (Internal) Build SQL to update a RowObject.

Returns: SQL that is used to contruct a rowObject class.

| deleteRow

    deleteRow ( self,  rowObject )

delete the row for this object from the database.

| deleteRowSQL

    deleteRowSQL ( self,  rowObject )

build SQL to delete me from the db.

| getTableInfo

    getTableInfo ( self,  rowObject )

### Get a TableInfo record about a particular instance.

#### Arguments:

- rowObject: a RowObject instance of a class previously registered with me.

This record contains various information about the instance's class as registered with this reflector.

#### Raises:

- twisted.enterprise.row.DBError: raised if this class was not previously registered.

Exceptions |
--- | ---
DBError("class %s was not registered with %s" %( rowObject.__class__, self ) )

| insertRow

    insertRow ( self,  rowObject )

insert a new row for this object instance.

| insertRowSQL

    insertRowSQL ( self,  rowObject )

build SQL to insert my current state.

| loadObjectsFrom

    loadObjectsFrom (
            self,
            tableName,
            keyColumns,
            data,
            rowClass,
            whereClause="1 = 1",
            factoryMethod=defaultFactoryMethod,
            )

### Load a set of RowObjects from a database.

Create a set of python objects of <rowClass> from the contents of a table populated with appropriate data members. The constructor for <rowClass> must take no args. Example to use this:

                class EmployeeRow(row.RowObject):
                    pass

                def gotEmployees(employees):
                    for emp in employees:
                        emp.manager = "fred smith"
                        manager.updateRow(emp)

                manager.loadObjectsFrom("employee",
                                        ["employee_name", "varchar"],
                                        userData,
                                        employeeFactory,
                                        EmployeeRow,
                                        "employee_name like 'm%%'"
                                        ).addCallback(gotEmployees)

NOTE: this functionality is experimental. be careful.

| selectRow

    selectRow ( self,  rowObject )

load this rows current values from the database.

| selectRowSQL

    selectRowSQL ( self,  rowObject )

| updateRow

    updateRow ( self,  rowObject )

update my contents to the database.

| updateRowSQL

    updateRowSQL ( self,  rowObject )

build SQL to update my current state.

Table of Contents

This document was automatically generated on Sat Apr 20 01:30:47 2002 by HappyDoc version 2.0