Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

Zend_Db_Table_Abstract Class Reference

Inheritance diagram for Zend_Db_Table_Abstract:
Zend_Db_Table

Public Member Functions

 __construct ($config=array())
 setOptions (Array $options)
 setDefinition (Zend_Db_Table_Definition $definition)
 getDefinition ()
 setDefinitionConfigName ($definitionConfigName)
 getDefinitionConfigName ()
 setRowClass ($classname)
 getRowClass ()
 setRowsetClass ($classname)
 getRowsetClass ()
 addReference ($ruleKey, $columns, $refTableClass, $refColumns, $onDelete=null, $onUpdate=null)
 setReferences (array $referenceMap)
 getReference ($tableClassname, $ruleKey=null)
 setDependentTables (array $dependentTables)
 getDependentTables ()
 setDefaultSource ($defaultSource=self::DEFAULT_NONE)
 getDefaultSource ()
 setDefaultValues (Array $defaultValues)
 getDefaultValues ()
 getAdapter ()
 getMetadataCache ()
 setMetadataCacheInClass ($flag)
 metadataCacheInClass ()
 init ()
 info ($key=null)
 select ($withFromPart=self::SELECT_WITHOUT_FROM_PART)
 insert (array $data)
 isIdentity ($column)
 update (array $data, $where)
 _cascadeUpdate ($parentTableClassname, array $oldPrimaryKey, array $newPrimaryKey)
 delete ($where)
 _cascadeDelete ($parentTableClassname, array $primaryKey)
 find ()
 fetchAll ($where=null, $order=null, $count=null, $offset=null)
 fetchRow ($where=null, $order=null)
 fetchNew ()
 createRow (array $data=array(), $defaultSource=null)

Static Public Member Functions

static setDefaultAdapter ($db=null)
static getDefaultAdapter ()
static setDefaultMetadataCache ($metadataCache=null)
static getDefaultMetadataCache ()

Data Fields

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 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)
 _setSequence ($sequence)
 _setup ()
 _setupDatabaseAdapter ()
 _setupTableName ()
 _setupMetadata ()
 _getCols ()
 _setupPrimaryKey ()
 _getReferenceMapNormalized ()
 _where (Zend_Db_Table_Select $select, $where)
 _order (Zend_Db_Table_Select $select, $order)
 _fetch (Zend_Db_Table_Select $select)

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

Detailed Description

Definition at line 47 of file Abstract.php.


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.

Definition at line 255 of file Abstract.php.


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

Definition at line 1175 of file Abstract.php.

_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

Definition at line 1124 of file Abstract.php.

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

Definition at line 1507 of file Abstract.php.

_getCols (  ) [protected]

Retrieve table columns

Returns:
array

Definition at line 846 of file Abstract.php.

_getReferenceMapNormalized (  ) [protected]

Returns a normalized version of the reference map

Returns:
array

Definition at line 919 of file Abstract.php.

_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

Definition at line 1488 of file Abstract.php.

_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

Definition at line 579 of file Abstract.php.

_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

Definition at line 650 of file Abstract.php.

_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

Definition at line 723 of file Abstract.php.

_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

Definition at line 737 of file Abstract.php.

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

Definition at line 600 of file Abstract.php.

_setupDatabaseAdapter (  ) [protected]

Initialize database adapter.

Returns:
void

Definition at line 748 of file Abstract.php.

_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

See also:
Zend_Db_Table_Exception

Definition at line 788 of file Abstract.php.

static _setupMetadataCache ( metadataCache ) [static, protected]
Parameters:
mixed$metadataCacheEither a Cache object, or a string naming a Registry key
Returns:
Zend_Cache_Core
Exceptions:
Zend_Db_Table_Exception

Definition at line 695 of file Abstract.php.

_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".

Definition at line 863 of file Abstract.php.

_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

Definition at line 770 of file Abstract.php.

_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

Definition at line 1463 of file Abstract.php.

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

Definition at line 423 of file Abstract.php.

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

Definition at line 1410 of file Abstract.php.

delete ( where )

Deletes existing rows.

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

Definition at line 1162 of file Abstract.php.

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.

Definition at line 1304 of file Abstract.php.

fetchNew (  )

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

Returns:
Zend_Db_Table_Row_Abstract
Deprecated:
since 0.9.3 - use createRow() instead.

Definition at line 1398 of file Abstract.php.

fetchRow ( where = null,
order = 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.
Returns:
Zend_Db_Table_Row_Abstract|null The row results per the Zend_Db_Adapter fetch mode, or null if no row found.

Definition at line 1352 of file Abstract.php.

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

Definition at line 1221 of file Abstract.php.

getAdapter (  )

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.

Returns:
Zend_Db_Adapter_Abstract

Definition at line 590 of file Abstract.php.

static getDefaultAdapter (  ) [static]

Gets the default Zend_Db_Adapter_Abstract for all Zend_Db_Table objects.

Returns:
Zend_Db_Adapter_Abstract or null

Definition at line 570 of file Abstract.php.

static getDefaultMetadataCache (  ) [static]

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

Returns:
Zend_Cache_Core or null

Definition at line 634 of file Abstract.php.

getDefaultSource (  )

returns the default source flag that determines where defaultSources come from

Returns:
unknown

Definition at line 527 of file Abstract.php.

getDefinition (  )

getDefinition()

Returns:
Zend_Db_Table_Definition|null

Definition at line 347 of file Abstract.php.

getDefinitionConfigName (  )

getDefinitionConfigName()

Returns:
string

Definition at line 369 of file Abstract.php.

getDependentTables (  )
Returns:
array

Definition at line 501 of file Abstract.php.

getMetadataCache (  )

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

Returns:
Zend_Cache_Core or null

Definition at line 661 of file Abstract.php.

getReference ( tableClassname,
ruleKey = null 
)
Parameters:
string$tableClassname
string$ruleKeyOPTIONAL
Returns:
array
Exceptions:
Zend_Db_Table_Exception

Definition at line 460 of file Abstract.php.

getRowClass (  )
Returns:
string

Definition at line 388 of file Abstract.php.

getRowsetClass (  )
Returns:
string

Definition at line 407 of file Abstract.php.

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:
$keyThe specific info part to return OPTIONAL
Returns:
mixed

Definition at line 971 of file Abstract.php.

init (  )

Initialize object

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

Returns:
void

Definition at line 958 of file Abstract.php.

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.

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.

Definition at line 1022 of file Abstract.php.

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

Definition at line 1087 of file Abstract.php.

metadataCacheInClass (  )

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

Returns:
bool

Definition at line 685 of file Abstract.php.

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

Definition at line 1006 of file Abstract.php.

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

Definition at line 560 of file Abstract.php.

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

Definition at line 624 of file Abstract.php.

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

Definition at line 512 of file Abstract.php.

setDefaultValues ( Array $  defaultValues )

set the default values for the table class

Parameters:
array$defaultValues
Returns:
Zend_Db_Table_Abstract

Definition at line 538 of file Abstract.php.

setDefinition ( Zend_Db_Table_Definition definition )

setDefinition()

Parameters:
Zend_Db_Table_Definition$definition
Returns:
Zend_Db_Table_Abstract

Definition at line 336 of file Abstract.php.

setDefinitionConfigName ( definitionConfigName )

setDefinitionConfigName()

Parameters:
string$definition
Returns:
Zend_Db_Table_Abstract

Definition at line 358 of file Abstract.php.

setDependentTables ( array $  dependentTables )
Parameters:
array$dependentTables
Returns:
Zend_Db_Table_Abstract Provides a fluent interface

Definition at line 491 of file Abstract.php.

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

Definition at line 673 of file Abstract.php.

setOptions ( Array $  options )

setOptions()

Parameters:
array$options
Returns:
Zend_Db_Table_Abstract

Definition at line 278 of file Abstract.php.

setReferences ( array $  referenceMap )
Parameters:
array$referenceMap
Returns:
Zend_Db_Table_Abstract Provides a fluent interface

Definition at line 447 of file Abstract.php.

setRowClass ( classname )
Parameters:
string$classname
Returns:
Zend_Db_Table_Abstract Provides a fluent interface

Definition at line 378 of file Abstract.php.

setRowsetClass ( classname )
Parameters:
string$classname
Returns:
Zend_Db_Table_Abstract Provides a fluent interface

Definition at line 397 of file Abstract.php.

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.

Definition at line 1110 of file Abstract.php.


The documentation for this class was generated from the following file: