Package twisted :: Package enterprise :: Module sqlreflector :: Class SQLReflector

[show private | hide private]
[frames | no frames]

## Class SQLReflector

       Reflector --+
                   |
    Augmentation --+
                   |
                  SQLReflector

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.

Method Summary
| ``__init__`(self, dbpool, rowClasses)` Initialize me against a database.
| `__getstate__(self)` (inherited from `Reflector`)
| `__setstate__(self, state)` (inherited from `Reflector`)
| ``addToCache`(self, rowObject)` NOTE: Should this be recursive?! requires better container knowledge... (inherited from `Reflector`)
| ``addToParent`(self, parentRow, rows, tableName)` util method used by reflectors. (inherited from `Reflector`)
| ``buildDeleteSQL`(self, tableInfo)` Build the SQL to delete a row from the table.
| ``buildInsertSQL`(self, tableInfo)` (Internal) Build SQL to insert a new row.
| ``buildUpdateSQL`(self, tableInfo)` (Internal) Build SQL to update a RowObject.
| ``buildWhereClause`(self, relationship, row)` util method used by reflectors. (inherited from `Reflector`)
| `createSchema(self)` (inherited from `Augmentation`)
| ``deleteRow`(self, rowObject)` delete the row for this object from the database.
| ``deleteRowSQL`(self, rowObject)` build SQL to delete me from the db.
| ``escape_string`(self, text)` Escape a string for use in an SQL statement.
| `findInCache(self, rowClass, kw)` (inherited from `Reflector`)
| `findTypeFor(self, tableName, columnName)`
| ``getTableInfo`(self, rowObject)` Get a TableInfo record about a particular instance. (inherited from `Reflector`)
| ``insertRow`(self, rowObject)` insert a new row for this object instance.
| ``insertRowSQL`(self, rowObject)` build SQL to insert my current state.
| ``loadObjectsFrom`(self, tableName, parentRow, data, whereClause, forceChildren)` Load a set of RowObjects from a database.
| ``operationDone`(self, done)` Example callback for database operation success. (inherited from `Augmentation`)
| ``operationError`(self, error)` Example callback for database operation failure. (inherited from `Augmentation`)
| ``populateSchemaFor`(self, tableInfo)` This is called once for each registered rowClass to add it and its foreign key relationships for that rowClass to the schema. (inherited from `Reflector`)
| ``quote_value`(self, value, type)` Format a value for use in an SQL statement.
| ``removeFromCache`(self, rowObject)` NOTE: should this be recursive!?? (inherited from `Reflector`)
| `runInteraction(self, interaction, *args, **kw)` (inherited from `Augmentation`)
| `runOperation(self, *args, **kw)` (inherited from `Augmentation`)
| `runQuery(self, *args, **kw)` (inherited from `Augmentation`)
| `schemaCreated(self, result)` (inherited from `Augmentation`)
| `schemaNotCreated(self, error)` (inherited from `Augmentation`)
| ``updateRow`(self, rowObject)` update my contents to the database.
| ``updateRowSQL`(self, rowObject)` build SQL to update my current state.

Class Variable Summary
`dict` | `conditionalLabels`
`int` | `populated`

Method Details

### __init__(self, dbpool, rowClasses)
(Constructor)

Initialize me against a database.

### buildDeleteSQL(self, tableInfo)

Build the SQL to delete a row from the table.

### buildInsertSQL(self, tableInfo)

(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.

### buildUpdateSQL(self, tableInfo)

(Internal) Build SQL to update a RowObject.

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

### deleteRow(self, rowObject)

delete the row for this object from the database.

### deleteRowSQL(self, rowObject)

build SQL to delete me from the db.

### escape_string(self, text)

Escape a string for use in an SQL statement. The default implementation escapes ' with '' and \ with \. Redefine this function in a subclass if your database server uses different escaping rules.

### insertRow(self, rowObject)

insert a new row for this object instance.

### insertRowSQL(self, rowObject)

build SQL to insert my current state.

### loadObjectsFrom(self, tableName, parentRow=None, data=None, whereClause=None, forceChildren=0)

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. Example:

     |  class EmployeeRow(row.RowObject):
     |      pass
     |
     |  def gotEmployees(employees):
     |      for emp in employees:
     |          emp.manager = "fred smith"
     |          manager.updateRow(emp)
     |
     |  reflector.loadObjectsFrom("employee",
     |                          data = userData,
     |                          whereClause = [("manager" , EQUAL, "fred smith")]
     |                          ).addCallback(gotEmployees)

NOTE: the objects and all children should be loaded in a single transaction. NOTE: can specify a parentRow _OR_ a whereClause.

### quote_value(self, value, type)

Format a value for use in an SQL statement.

  Parameters:
    `value` - a value to format as data in SQL.
    `type` - a key in util.dbTypeMap.

### updateRow(self, rowObject)

update my contents to the database.

### updateRowSQL(self, rowObject)

build SQL to update my current state.

Class Variable Details

### conditionalLabels

  Type:
    `dict`
  Value:

        {0: '=', 1: '<', 2: '>', 3: 'like'}

### populated

  Type:
    `int`
  Value:

        0

Generated by Epydoc 1.1 on Thu May 8 13:16:25 2003 | http://epydoc.sf.net