Zend Framework  1.12
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Zend_Db_Table_Abstract Class Reference

Public Member Functions

 __construct ($config=array())
 Constructor.
 
 setOptions (Array $options)
 setOptions()
 
 setDefinition (Zend_Db_Table_Definition $definition)
 setDefinition()
 
 getDefinition ()
 getDefinition()
 
 setDefinitionConfigName ($definitionConfigName)
 setDefinitionConfigName()
 
 getDefinitionConfigName ()
 getDefinitionConfigName()
 
 setRowClass ($classname)
 
 getRowClass ()
 
 setRowsetClass ($classname)
 
 getRowsetClass ()
 
 addReference ($ruleKey, $columns, $refTableClass, $refColumns, $onDelete=null, $onUpdate=null)
 Add a reference to the reference map.
 
 setReferences (array $referenceMap)
 
 getReference ($tableClassname, $ruleKey=null)
 
 setDependentTables (array $dependentTables)
 
 getDependentTables ()
 
 setDefaultSource ($defaultSource=self::DEFAULT_NONE)
 set the defaultSource property - this tells the table class where to find default values
 
 getDefaultSource ()
 returns the default source flag that determines where defaultSources come from
 
 setDefaultValues (Array $defaultValues)
 set the default values for the table class
 
 getDefaultValues ()
 
 getAdapter ()
 Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.
 
 getMetadataCache ()
 Gets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
 
 setMetadataCacheInClass ($flag)
 Indicate whether metadata should be cached in the class for the duration of the instance.
 
 metadataCacheInClass ()
 Retrieve flag indicating if metadata should be cached for duration of instance.
 
 init ()
 Initialize object.
 
 info ($key=null)
 Returns table information.
 
 select ($withFromPart=self::SELECT_WITHOUT_FROM_PART)
 Returns an instance of a Zend_Db_Table_Select object.
 
 insert (array $data)
 Inserts a new row.
 
 isIdentity ($column)
 Check if the provided column is an identity of the table.
 
 update (array $data, $where)
 Updates existing rows.
 
 _cascadeUpdate ($parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey)
 Called by a row object for the parent table's class during save() method.
 
 delete ($where)
 Deletes existing rows.
 
 _cascadeDelete ($parentTableClassname, array $primaryKey)
 Called by parent table's class during delete() method.
 
 find ()
 Fetches rows by primary key.
 
 fetchAll ($where=null, $order=null, $count=null, $offset=null)
 Fetches all rows.
 
 fetchRow ($where=null, $order=null, $offset=null)
 Fetches one row in an object of type Zend_Db_Table_Row_Abstract, or returns null if no row matches the specified criteria.
 
 fetchNew ()
 Fetches a new blank row (not from the database).
 
 createRow (array $data=array(), $defaultSource=null)
 Fetches a new blank row (not from the database).
 

Static Public Member Functions

static setDefaultAdapter ($db=null)
 Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.
 
static getDefaultAdapter ()
 Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.
 
static setDefaultMetadataCache ($metadataCache=null)
 Sets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
 
static getDefaultMetadataCache ()
 Gets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
 
static getTableFromString ($tableName, Zend_Db_Table_Abstract $referenceTable=null)
 

Public Attributes

const ADAPTER = 'db'
 
const DEFINITION = 'definition'
 
const DEFINITION_CONFIG_NAME = 'definitionConfigName'
 
const SCHEMA = 'schema'
 
const NAME = 'name'
 
const PRIMARY = 'primary'
 
const COLS = 'cols'
 
const METADATA = 'metadata'
 
const METADATA_CACHE = 'metadataCache'
 
const METADATA_CACHE_IN_CLASS = 'metadataCacheInClass'
 
const ROW_CLASS = 'rowClass'
 
const ROWSET_CLASS = 'rowsetClass'
 
const REFERENCE_MAP = 'referenceMap'
 
const DEPENDENT_TABLES = 'dependentTables'
 
const SEQUENCE = 'sequence'
 
const COLUMNS = 'columns'
 
const REF_TABLE_CLASS = 'refTableClass'
 
const REF_COLUMNS = 'refColumns'
 
const ON_DELETE = 'onDelete'
 
const ON_UPDATE = 'onUpdate'
 
const CASCADE = 'cascade'
 
const CASCADE_RECURSE = 'cascadeRecurse'
 
const RESTRICT = 'restrict'
 
const SET_NULL = 'setNull'
 
const DEFAULT_NONE = 'defaultNone'
 
const DEFAULT_CLASS = 'defaultClass'
 
const DEFAULT_DB = 'defaultDb'
 
const SELECT_WITH_FROM_PART = true
 
const SELECT_WITHOUT_FROM_PART = false
 

Protected Member Functions

 _setAdapter ($db)
 
 _setMetadataCache ($metadataCache)
 Sets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().
 
 _setSequence ($sequence)
 Sets the sequence member, which defines the behavior for generating primary key values in new rows.
 
 _setup ()
 Turnkey for initialization of a table object.
 
 _setupDatabaseAdapter ()
 Initialize database adapter.
 
 _setupTableName ()
 Initialize table and schema names.
 
 _setupMetadata ()
 Initializes metadata.
 
 _getCols ()
 Retrieve table columns.
 
 _setupPrimaryKey ()
 Initialize primary key from metadata.
 
 _getReferenceMapNormalized ()
 Returns a normalized version of the reference map.
 
 _where (Zend_Db_Table_Select $select, $where)
 Generate WHERE clause from user-supplied string or array.
 
 _order (Zend_Db_Table_Select $select, $order)
 Generate ORDER clause from user-supplied string or array.
 
 _fetch (Zend_Db_Table_Select $select)
 Support method for fetching rows.
 

Static Protected Member Functions

static _setupAdapter ($db)
 
static _setupMetadataCache ($metadataCache)
 

Protected Attributes

 $_definition = null
 
 $_definitionConfigName = null
 
 $_db
 
 $_schema = null
 
 $_name = null
 
 $_cols
 
 $_primary = null
 
 $_identity = 1
 
 $_sequence = true
 
 $_metadata = array()
 
 $_metadataCache = null
 
 $_metadataCacheInClass = true
 
 $_rowClass = 'Zend_Db_Table_Row'
 
 $_rowsetClass = 'Zend_Db_Table_Rowset'
 
 $_referenceMap = array()
 
 $_dependentTables = array()
 
 $_defaultSource = self::DEFAULT_NONE
 
 $_defaultValues = array()
 

Static Protected Attributes

static $_defaultDb
 
static $_defaultMetadataCache = null
 

Constructor & Destructor Documentation

__construct (   $config = array())

Constructor.

Supported params for $config are:

  • db = user-supplied instance of database connector, or key name of registry instance.
  • name = table name.
  • primary = string or array of primary key(s).
  • rowClass = row class name.
  • rowsetClass = rowset class name.
  • referenceMap = array structure to declare relationship to parent tables.
  • dependentTables = array of child tables.
  • metadataCache = cache for information from adapter describeTable().
Parameters
mixed$configArray of user-specified config options, or just the Db Adapter.
Returns
void

Allow a scalar argument to be the Adapter object or Registry key.

Member Function Documentation

_cascadeDelete (   $parentTableClassname,
array  $primaryKey 
)

Called by parent table's class during delete() method.

Parameters
string$parentTableClassname
array$primaryKey
Returns
int Number of affected rows

Execute cascading deletes against dependent tables

_cascadeUpdate (   $parentTableClassname,
array  $oldPrimaryKey,
array  $newPrimaryKey 
)

Called by a row object for the parent table's class during save() method.

Parameters
string$parentTableClassname
array$oldPrimaryKey
array$newPrimaryKey
Returns
int
_fetch ( Zend_Db_Table_Select  $select)
protected

Support method for fetching rows.

Parameters
Zend_Db_Table_Select$selectquery options.
Returns
array An array containing the row results in FETCH_ASSOC mode.
_getCols ( )
protected

Retrieve table columns.

Returns
array
_getReferenceMapNormalized ( )
protected

Returns a normalized version of the reference map.

Returns
array
_order ( Zend_Db_Table_Select  $select,
  $order 
)
protected

Generate ORDER clause from user-supplied string or array.

Parameters
string | array$orderOPTIONAL An SQL ORDER clause.
Returns
Zend_Db_Table_Select
_setAdapter (   $db)
protected
Parameters
mixed$dbEither an Adapter object, or a string naming a Registry key
Returns
Zend_Db_Table_Abstract Provides a fluent interface
_setMetadataCache (   $metadataCache)
protected

Sets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

If $metadataCache is null, then no metadata cache is used. Since there is no opportunity to reload metadata after instantiation, this method need not be public, particularly because that it would have no effect results in unnecessary API complexity. To configure the metadata cache, use the metadataCache configuration option for the class constructor upon instantiation.

Parameters
mixed$metadataCacheEither a Cache object, or a string naming a Registry key
Returns
Zend_Db_Table_Abstract Provides a fluent interface
_setSequence (   $sequence)
protected

Sets the sequence member, which defines the behavior for generating primary key values in new rows.

  • If this is a string, then the string names the sequence object.
  • If this is boolean true, then the key uses an auto-incrementing or identity mechanism.
  • If this is boolean false, then the key is user-defined. Use this for natural keys, for example.
Parameters
mixed$sequence
Returns
Zend_Db_Table_Adapter_Abstract Provides a fluent interface
_setup ( )
protected

Turnkey for initialization of a table object.

Calls other protected methods for individual tasks, to make it easier for a subclass to override part of the setup logic.

Returns
void
static _setupAdapter (   $db)
staticprotected
Parameters
mixed$dbEither an Adapter object, or a string naming a Registry key
Returns
Zend_Db_Adapter_Abstract
Exceptions
Zend_Db_Table_Exception
_setupDatabaseAdapter ( )
protected

Initialize database adapter.

Returns
void
Exceptions
Zend_Db_Table_Exception
_setupMetadata ( )
protected

Initializes metadata.

If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata information. Returns true if and only if the metadata are loaded from cache.

Returns
boolean
Exceptions
Zend_Db_Table_Exception
static _setupMetadataCache (   $metadataCache)
staticprotected
Parameters
mixed$metadataCacheEither a Cache object, or a string naming a Registry key
Returns
Zend_Cache_Core
Exceptions
Zend_Db_Table_Exception
_setupPrimaryKey ( )
protected

Initialize primary key from metadata.

If $_primary is not defined, discover primary keys from the information returned by describeTable().

Returns
void
Exceptions
Zend_Db_Table_Exception

Special case for PostgreSQL: a SERIAL key implicitly uses a sequence object whose name is "<table>_<column>_seq".

_setupTableName ( )
protected

Initialize table and schema names.

If the table name is not set in the class definition, use the class name itself as the table name.

A schema name provided with the table name (e.g., "schema.table") overrides any existing value for $this->_schema.

Returns
void
_where ( Zend_Db_Table_Select  $select,
  $where 
)
protected

Generate WHERE clause from user-supplied string or array.

Parameters
string | array$whereOPTIONAL An SQL WHERE clause.
Returns
Zend_Db_Table_Select
addReference (   $ruleKey,
  $columns,
  $refTableClass,
  $refColumns,
  $onDelete = null,
  $onUpdate = null 
)

Add a reference to the reference map.

Parameters
string$ruleKey
string | array$columns
string$refTableClass
string | array$refColumns
string$onDelete
string$onUpdate
Returns
Zend_Db_Table_Abstract
createRow ( array  $data = array(),
  $defaultSource = null 
)

Fetches a new blank row (not from the database).

Parameters
array$dataOPTIONAL data to populate in the new row.
string$defaultSourceOPTIONAL flag to force default values into new row
Returns
Zend_Db_Table_Row_Abstract
delete (   $where)

Deletes existing rows.

Parameters
array | string$whereSQL WHERE clause(s).
Returns
int The number of rows deleted.

Execute cascading deletes against dependent tables

fetchAll (   $where = null,
  $order = null,
  $count = null,
  $offset = null 
)

Fetches all rows.

Honors the Zend_Db_Adapter fetch mode.

Parameters
string | array | Zend_Db_Table_Select$whereOPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
string | array$orderOPTIONAL An SQL ORDER clause.
int$countOPTIONAL An SQL LIMIT count.
int$offsetOPTIONAL An SQL LIMIT offset.
Returns
Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
fetchNew ( )

Fetches a new blank row (not from the database).

Returns
Zend_Db_Table_Row_Abstract
Deprecated:
since 0.9.3 - use createRow() instead.
fetchRow (   $where = null,
  $order = null,
  $offset = null 
)

Fetches one row in an object of type Zend_Db_Table_Row_Abstract, or returns null if no row matches the specified criteria.

Parameters
string | array | Zend_Db_Table_Select$whereOPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
string | array$orderOPTIONAL An SQL ORDER clause.
int$offsetOPTIONAL An SQL OFFSET value.
Returns
Zend_Db_Table_Row_Abstract|null The row results per the Zend_Db_Adapter fetch mode, or null if no row found.
find ( )

Fetches rows by primary key.

The argument specifies one or more primary key value(s). To find multiple rows by primary key, the argument must be an array.

This method accepts a variable number of arguments. If the table has a multi-column primary key, the number of arguments must be the same as the number of columns in the primary key. To find multiple rows in a table with a multi-column primary key, each argument must be an array with the same number of elements.

The find() method always returns a Rowset object, even if only one row was found.

Parameters
mixed$keyThe value(s) of the primary keys.
Returns
Zend_Db_Table_Rowset_Abstract Row(s) matching the criteria.
Exceptions
Zend_Db_Table_Exception
getAdapter ( )

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.

Returns
Zend_Db_Adapter_Abstract
static getDefaultAdapter ( )
static

Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Returns
Zend_Db_Adapter_Abstract or null
static getDefaultMetadataCache ( )
static

Gets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Returns
Zend_Cache_Core or null
getDefaultSource ( )

returns the default source flag that determines where defaultSources come from

Returns
unknown
getDefaultValues ( )
getDefinition ( )

getDefinition()

Returns
Zend_Db_Table_Definition|null
getDefinitionConfigName ( )
getDependentTables ( )
Returns
array
getMetadataCache ( )

Gets the metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

Returns
Zend_Cache_Core or null
getReference (   $tableClassname,
  $ruleKey = null 
)
Parameters
string$tableClassname
string$ruleKeyOPTIONAL
Returns
array
Exceptions
Zend_Db_Table_Exception
getRowClass ( )
Returns
string
getRowsetClass ( )
Returns
string
static getTableFromString (   $tableName,
Zend_Db_Table_Abstract  $referenceTable = null 
)
static
info (   $key = null)

Returns table information.

You can elect to return only a part of this information by supplying its key name, otherwise all information is returned as an array.

Parameters
string$keyThe specific info part to return OPTIONAL
Returns
mixed
Exceptions
Zend_Db_Table_Exception
init ( )

Initialize object.

Called from __construct() as final step of object instantiation.

Returns
void
insert ( array  $data)

Inserts a new row.

Parameters
array$dataColumn-value pairs.
Returns
mixed The primary key of the row inserted.

Zend_Db_Table assumes that if you have a compound primary key and one of the columns in the key uses a sequence, it's the _first_ column in the compound key.

If this table uses a database sequence object and the data does not specify a value, then get the next ID from the sequence and add it to the row. We assume that only the first column in a compound primary key takes a value from a sequence.

If the primary key can be generated automatically, and no value was specified in the user-supplied data, then omit it from the tuple.

Note: this checks for sensible values in the supplied primary key position of the data. The following values are considered empty: null, false, true, '', array()

INSERT the new row.

Fetch the most recent ID generated by an auto-increment or IDENTITY column, unless the user has specified a value, overriding the auto-increment mechanism.

Return the primary key value if the PK is a single column, else return an associative array of the PK column/value pairs.

isIdentity (   $column)

Check if the provided column is an identity of the table.

Parameters
string$column
Exceptions
Zend_Db_Table_Exception
Returns
boolean
See Also
Zend_Db_Table_Exception
metadataCacheInClass ( )

Retrieve flag indicating if metadata should be cached for duration of instance.

Returns
bool
select (   $withFromPart = self::SELECT_WITHOUT_FROM_PART)

Returns an instance of a Zend_Db_Table_Select object.

Parameters
bool$withFromPartWhether or not to include the from part of the select based on the table
Returns
Zend_Db_Table_Select
static setDefaultAdapter (   $db = null)
static

Sets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Parameters
mixed$dbEither an Adapter object, or a string naming a Registry key
Returns
void
static setDefaultMetadataCache (   $metadataCache = null)
static

Sets the default metadata cache for information returned by Zend_Db_Adapter_Abstract::describeTable().

If $defaultMetadataCache is null, then no metadata cache is used by default.

Parameters
mixed$metadataCacheEither a Cache object, or a string naming a Registry key
Returns
void
setDefaultSource (   $defaultSource = self::DEFAULT_NONE)

set the defaultSource property - this tells the table class where to find default values

Parameters
string$defaultSource
Returns
Zend_Db_Table_Abstract
setDefaultValues ( Array  $defaultValues)

set the default values for the table class

Parameters
array$defaultValues
Returns
Zend_Db_Table_Abstract
setDefinition ( Zend_Db_Table_Definition  $definition)
setDefinitionConfigName (   $definitionConfigName)

setDefinitionConfigName()

Parameters
string$definition
Returns
Zend_Db_Table_Abstract
setDependentTables ( array  $dependentTables)
Parameters
array$dependentTables
Returns
Zend_Db_Table_Abstract Provides a fluent interface
setMetadataCacheInClass (   $flag)

Indicate whether metadata should be cached in the class for the duration of the instance.

Parameters
bool$flag
Returns
Zend_Db_Table_Abstract
setOptions ( Array  $options)

setOptions()

Parameters
array$options
Returns
Zend_Db_Table_Abstract
setReferences ( array  $referenceMap)
Parameters
array$referenceMap
Returns
Zend_Db_Table_Abstract Provides a fluent interface
setRowClass (   $classname)
Parameters
string$classname
Returns
Zend_Db_Table_Abstract Provides a fluent interface
setRowsetClass (   $classname)
Parameters
string$classname
Returns
Zend_Db_Table_Abstract Provides a fluent interface
update ( array  $data,
  $where 
)

Updates existing rows.

Parameters
array$dataColumn-value pairs.
array | string$whereAn SQL WHERE clause, or an array of SQL WHERE clauses.
Returns
int The number of rows updated.

Member Data Documentation

$_cols
protected
$_db
protected
$_defaultDb
staticprotected
$_defaultMetadataCache = null
staticprotected
$_defaultSource = self::DEFAULT_NONE
protected
$_defaultValues = array()
protected
$_definition = null
protected
$_definitionConfigName = null
protected
$_dependentTables = array()
protected
$_identity = 1
protected
$_metadata = array()
protected
$_metadataCache = null
protected
$_metadataCacheInClass = true
protected
$_name = null
protected
$_primary = null
protected
$_referenceMap = array()
protected
$_rowClass = 'Zend_Db_Table_Row'
protected
$_rowsetClass = 'Zend_Db_Table_Rowset'
protected
$_schema = null
protected
$_sequence = true
protected
const ADAPTER = 'db'
const CASCADE = 'cascade'
const CASCADE_RECURSE = 'cascadeRecurse'
const COLS = 'cols'
const COLUMNS = 'columns'
const DEFAULT_CLASS = 'defaultClass'
const DEFAULT_DB = 'defaultDb'
const DEFAULT_NONE = 'defaultNone'
const DEFINITION = 'definition'
const DEFINITION_CONFIG_NAME = 'definitionConfigName'
const DEPENDENT_TABLES = 'dependentTables'
const METADATA = 'metadata'
const METADATA_CACHE = 'metadataCache'
const METADATA_CACHE_IN_CLASS = 'metadataCacheInClass'
const NAME = 'name'
const ON_DELETE = 'onDelete'
const ON_UPDATE = 'onUpdate'
const PRIMARY = 'primary'
const REF_COLUMNS = 'refColumns'
const REF_TABLE_CLASS = 'refTableClass'
const REFERENCE_MAP = 'referenceMap'
const RESTRICT = 'restrict'
const ROW_CLASS = 'rowClass'
const ROWSET_CLASS = 'rowsetClass'
const SCHEMA = 'schema'
const SELECT_WITH_FROM_PART = true
const SELECT_WITHOUT_FROM_PART = false
const SEQUENCE = 'sequence'
const SET_NULL = 'setNull'