Package gnue :: Package appserver :: Module data :: Class record
[show private | hide private]

Class record


This class stands for a record in a database table. An instance of this class can be created via the recordset iterator, or by the connection.findRecord() method.
Method Summary
  __init__(self, cache, connections, database, table, row)
Create a new wrapper for a given record in the cache
  __repr__(self)
This function returns an official string representation of the record instance.
  getField(self, field, original)
Get the value for a field.
  initialized(self)
This function marks this record as 'initialized' so following changes will make it commitable.
  putField(self, field, value)
Put the value for a field.
  state(self)
Returns the state of the given record.
  _cache(self, field, value)
Write a field to the clean cache, but do not replace already cached values
  _fill(self, alias, fields, RecordSet)
Write the given fields from the given RecordSet object to the clean cache, but do not replace already cached values.

Method Details

__init__(self, cache, connections, database, table, row)
(Constructor)

Create a new wrapper for a given record in the cache
Parameters:
cache - the underlying cache instance
connections - GConnections instance which can return a handle to the current backend connection
database - name of the backend connection to be used
table - name of the table this record instance is a row of
row - id of the row represented by this record instance

__repr__(self)
(Representation operator)

This function returns an official string representation of the record instance.

getField(self, field, original=False)

Get the value for a field. If the value isn't cached, a new query to the database is issued to get the value.

The field name must be given as a unicode string. The result will be returned as the native Python datatype, in case of a string field it will be Unicode.
Parameters:
field - name of the field to get a value for
original - if True return an original value (either from the clean cache or freshly fetched from the backend). If False return a dirty or clean value (in that order)
Returns:
current or original value of the given field

initialized(self)

This function marks this record as 'initialized' so following changes will make it commitable.
Raises:
StateChangeError - if this function is called for a record having another state than 'initializing'.

putField(self, field, value)

Put the value for a field.

The field name must be given as a unicode string, value must be the native Python datatype of the field, in case of a string field it must be Unicode.
Parameters:
field - name of the field (as unicode string)
value - value to be set for the given field (native Python datatype)

state(self)

Returns the state of the given record. Returns one of the following results:
  • 'initializing': newly created record with initialization not yet finished
  • 'initialized': newly created and initialized records with no modifications
  • 'inserted': newly created record with modifications
  • 'changed': existing record with modifications
  • 'deleted': deleted record
  • 'clean': record is available and has no modifications
Returns:
current state of the record

_cache(self, field, value)

Write a field to the clean cache, but do not replace already cached values
Parameters:
field - name of the field
value - value of the field

_fill(self, alias, fields, RecordSet)

Write the given fields from the given RecordSet object to the clean cache, but do not replace already cached values.
Parameters:
alias - alias used for fields in the RecordSet, i.e. 't0', 't1', ...
fields - sequence of fieldnames to cache from the RecordSet
RecordSet - dictionary like object to retrieve the data from


GNUe Home

Private API

Developer's Corner