import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 6320 2007-09-12 00:27:22Z bkarwin $
|
||||
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -41,13 +41,15 @@ require_once 'Zend/Db.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Db_Table_Abstract
|
||||
{
|
||||
|
||||
const ADAPTER = 'db';
|
||||
const DEFINITION = 'definition';
|
||||
const DEFINITION_CONFIG_NAME = 'definitionConfigName';
|
||||
const SCHEMA = 'schema';
|
||||
const NAME = 'name';
|
||||
const PRIMARY = 'primary';
|
||||
@ -75,6 +77,9 @@ abstract class Zend_Db_Table_Abstract
|
||||
const DEFAULT_CLASS = 'defaultClass';
|
||||
const DEFAULT_DB = 'defaultDb';
|
||||
|
||||
const SELECT_WITH_FROM_PART = true;
|
||||
const SELECT_WITHOUT_FROM_PART = false;
|
||||
|
||||
/**
|
||||
* Default Zend_Db_Adapter_Abstract object.
|
||||
*
|
||||
@ -82,6 +87,20 @@ abstract class Zend_Db_Table_Abstract
|
||||
*/
|
||||
protected static $_defaultDb;
|
||||
|
||||
/**
|
||||
* Optional Zend_Db_Table_Definition object
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
protected $_definition = null;
|
||||
|
||||
/**
|
||||
* Optional definition config name used in concrete implementation
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_definitionConfigName = null;
|
||||
|
||||
/**
|
||||
* Default cache for information provided by the adapter's describeTable() method.
|
||||
*
|
||||
@ -106,7 +125,7 @@ abstract class Zend_Db_Table_Abstract
|
||||
/**
|
||||
* The table name.
|
||||
*
|
||||
* @var array
|
||||
* @var string
|
||||
*/
|
||||
protected $_name = null;
|
||||
|
||||
@ -242,11 +261,33 @@ abstract class Zend_Db_Table_Abstract
|
||||
$config = array(self::ADAPTER => $config);
|
||||
}
|
||||
|
||||
foreach ($config as $key => $value) {
|
||||
if ($config) {
|
||||
$this->setOptions($config);
|
||||
}
|
||||
|
||||
$this->_setup();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* setOptions()
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
public function setOptions(Array $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
switch ($key) {
|
||||
case self::ADAPTER:
|
||||
$this->_setAdapter($value);
|
||||
break;
|
||||
case self::DEFINITION:
|
||||
$this->setDefinition($value);
|
||||
break;
|
||||
case self::DEFINITION_CONFIG_NAME:
|
||||
$this->setDefinitionConfigName($value);
|
||||
break;
|
||||
case self::SCHEMA:
|
||||
$this->_schema = (string) $value;
|
||||
break;
|
||||
@ -283,8 +324,51 @@ abstract class Zend_Db_Table_Abstract
|
||||
}
|
||||
}
|
||||
|
||||
$this->_setup();
|
||||
$this->init();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefinition()
|
||||
*
|
||||
* @param Zend_Db_Table_Definition $definition
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
public function setDefinition(Zend_Db_Table_Definition $definition)
|
||||
{
|
||||
$this->_definition = $definition;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefinition()
|
||||
*
|
||||
* @return Zend_Db_Table_Definition|null
|
||||
*/
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->_definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefinitionConfigName()
|
||||
*
|
||||
* @param string $definition
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
public function setDefinitionConfigName($definitionConfigName)
|
||||
{
|
||||
$this->_definitionConfigName = $definitionConfigName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefinitionConfigName()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefinitionConfigName()
|
||||
{
|
||||
return $this->_definitionConfigName;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -376,6 +460,9 @@ abstract class Zend_Db_Table_Abstract
|
||||
public function getReference($tableClassname, $ruleKey = null)
|
||||
{
|
||||
$thisClass = get_class($this);
|
||||
if ($thisClass === 'Zend_Db_Table') {
|
||||
$thisClass = $this->_definitionConfigName;
|
||||
}
|
||||
$refMap = $this->_getReferenceMapNormalized();
|
||||
if ($ruleKey !== null) {
|
||||
if (!isset($refMap[$ruleKey])) {
|
||||
@ -808,9 +895,9 @@ abstract class Zend_Db_Table_Abstract
|
||||
* object whose name is "<table>_<column>_seq".
|
||||
*/
|
||||
if ($this->_sequence === true && $this->_db instanceof Zend_Db_Adapter_Pdo_Pgsql) {
|
||||
$this->_sequence = "{$this->_name}_{$pkIdentity}_seq";
|
||||
$this->_sequence = $this->_db->quoteIdentifier("{$this->_name}_{$pkIdentity}_seq");
|
||||
if ($this->_schema) {
|
||||
$this->_sequence = $this->_schema . '.' . $this->_sequence;
|
||||
$this->_sequence = $this->_db->quoteIdentifier($this->_schema) . '.' . $this->_sequence;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -904,12 +991,17 @@ abstract class Zend_Db_Table_Abstract
|
||||
/**
|
||||
* Returns an instance of a Zend_Db_Table_Select object.
|
||||
*
|
||||
* @param bool $withFromPart Whether or not to include the from part of the select based on the table
|
||||
* @return Zend_Db_Table_Select
|
||||
*/
|
||||
public function select()
|
||||
public function select($withFromPart = self::SELECT_WITHOUT_FROM_PART)
|
||||
{
|
||||
require_once 'Zend/Db/Table/Select.php';
|
||||
return new Zend_Db_Table_Select($this);
|
||||
$select = new Zend_Db_Table_Select($this);
|
||||
if ($withFromPart == self::SELECT_WITH_FROM_PART) {
|
||||
$select->from($this->info(self::NAME), Zend_Db_Table_Select::SQL_WILDCARD, $this->info(self::SCHEMA));
|
||||
}
|
||||
return $select;
|
||||
}
|
||||
|
||||
/**
|
||||
|
131
libs/Zend/Db/Table/Definition.php
Normal file
131
libs/Zend/Db/Table/Definition.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Definition.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for SQL table interface.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Definition
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_tableConfigs = array();
|
||||
|
||||
/**
|
||||
* __construct()
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$this->setConfig($options);
|
||||
} elseif (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setConfig()
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @return Zend_Db_Table_Definition
|
||||
*/
|
||||
public function setConfig(Zend_Config $config)
|
||||
{
|
||||
$this->setOptions($config->toArray());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setOptions()
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Db_Table_Definition
|
||||
*/
|
||||
public function setOptions(Array $options)
|
||||
{
|
||||
foreach ($options as $optionName => $optionValue) {
|
||||
$this->setTableConfig($optionName, $optionValue);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tableName
|
||||
* @param array $tableConfig
|
||||
* @return Zend_Db_Table_Definition
|
||||
*/
|
||||
public function setTableConfig($tableName, array $tableConfig)
|
||||
{
|
||||
// @todo logic here
|
||||
$tableConfig[Zend_Db_Table::DEFINITION_CONFIG_NAME] = $tableName;
|
||||
$tableConfig[Zend_Db_Table::DEFINITION] = $this;
|
||||
|
||||
if (!isset($tableConfig[Zend_Db_Table::NAME])) {
|
||||
$tableConfig[Zend_Db_Table::NAME] = $tableName;
|
||||
}
|
||||
|
||||
$this->_tableConfigs[$tableName] = $tableConfig;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTableConfig()
|
||||
*
|
||||
* @param string $tableName
|
||||
* @return array
|
||||
*/
|
||||
public function getTableConfig($tableName)
|
||||
{
|
||||
return $this->_tableConfigs[$tableName];
|
||||
}
|
||||
|
||||
/**
|
||||
* removeTableConfig()
|
||||
*
|
||||
* @param string $tableName
|
||||
*/
|
||||
public function removeTableConfig($tableName)
|
||||
{
|
||||
unset($this->_tableConfigs[$tableName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* hasTableConfig()
|
||||
*
|
||||
* @param string $tableName
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTableConfig($tableName)
|
||||
{
|
||||
return (isset($this->_tableConfigs[$tableName]));
|
||||
}
|
||||
|
||||
}
|
@ -15,8 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 16541 2009-07-07 06:59:03Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ require_once 'Zend/Db/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Exception extends Zend_Db_Exception
|
||||
|
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Row.php 9101 2008-03-30 19:54:38Z thomas $
|
||||
* @version $Id: Row.php 16203 2009-06-21 18:56:17Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ require_once 'Zend/Db/Table/Row/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Row extends Zend_Db_Table_Row_Abstract
|
||||
|
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 6332 2007-09-13 00:35:08Z bkarwin $
|
||||
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -29,7 +29,7 @@ require_once 'Zend/Db.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
@ -116,12 +116,8 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
if (isset($config['table']) && $config['table'] instanceof Zend_Db_Table_Abstract) {
|
||||
$this->_table = $config['table'];
|
||||
$this->_tableClass = get_class($this->_table);
|
||||
} else if ($this->_tableClass !== null) {
|
||||
if (!class_exists($this->_tableClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($this->_tableClass);
|
||||
}
|
||||
$this->_table = new $this->_tableClass();
|
||||
} elseif ($this->_tableClass !== null) {
|
||||
$this->_table = $this->_getTableFromString($this->_tableClass);
|
||||
}
|
||||
|
||||
if (isset($config['data'])) {
|
||||
@ -545,20 +541,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
if (count($pkDiffData) > 0) {
|
||||
$depTables = $this->_getTable()->getDependentTables();
|
||||
if (!empty($depTables)) {
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
$pkNew = $this->_getPrimaryKey(true);
|
||||
$pkOld = $this->_getPrimaryKey(false);
|
||||
foreach ($depTables as $tableClass) {
|
||||
if (!class_exists($tableClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$t = new $tableClass(array('db' => $db));
|
||||
$t = $this->_getTableFromString($tableClass);
|
||||
$t->_cascadeUpdate($this->getTableClass(), $pkOld, $pkNew);
|
||||
}
|
||||
}
|
||||
@ -627,19 +613,9 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
*/
|
||||
$depTables = $this->_getTable()->getDependentTables();
|
||||
if (!empty($depTables)) {
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
$pk = $this->_getPrimaryKey();
|
||||
foreach ($depTables as $tableClass) {
|
||||
if (!class_exists($tableClass)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableClass);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$t = new $tableClass(array('db' => $db));
|
||||
$t = $this->_getTableFromString($tableClass);
|
||||
$t->_cascadeDelete($this->getTableClass(), $pk);
|
||||
}
|
||||
}
|
||||
@ -859,7 +835,8 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
*/
|
||||
protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
|
||||
{
|
||||
$map = $dependentTable->getReference(get_class($parentTable), $ruleKey);
|
||||
$parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
|
||||
$map = $dependentTable->getReference($parentTableName, $ruleKey);
|
||||
|
||||
if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
|
||||
$parentInfo = $parentTable->info();
|
||||
@ -886,18 +863,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($dependentTable)) {
|
||||
if (!class_exists($dependentTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($dependentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$dependentTable = new $dependentTable(array('db' => $db));
|
||||
$dependentTable = $this->_getTableFromString($dependentTable);
|
||||
}
|
||||
if (! $dependentTable instanceof Zend_Db_Table_Abstract) {
|
||||
|
||||
if (!$dependentTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($dependentTable);
|
||||
if ($type == 'object') {
|
||||
$type = get_class($dependentTable);
|
||||
@ -906,6 +875,13 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($dependentTable->getDefinition() == null)) {
|
||||
$dependentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if ($select === null) {
|
||||
$select = $dependentTable->select();
|
||||
} else {
|
||||
@ -943,18 +919,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($parentTable)) {
|
||||
if (!class_exists($parentTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($parentTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$parentTable = new $parentTable(array('db' => $db));
|
||||
$parentTable = $this->_getTableFromString($parentTable);
|
||||
}
|
||||
if (! $parentTable instanceof Zend_Db_Table_Abstract) {
|
||||
|
||||
if (!$parentTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($parentTable);
|
||||
if ($type == 'object') {
|
||||
$type = get_class($parentTable);
|
||||
@ -963,6 +931,13 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($parentTable->getDefinition() == null)) {
|
||||
$parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if ($select === null) {
|
||||
$select = $parentTable->select();
|
||||
} else {
|
||||
@ -971,6 +946,7 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
|
||||
$map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
|
||||
|
||||
// iterate the map, creating the proper wheres
|
||||
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
|
||||
$dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
|
||||
$value = $this->_data[$dependentColumnName];
|
||||
@ -979,8 +955,18 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
|
||||
$parentColumn = $parentDb->quoteIdentifier($parentColumnName, true);
|
||||
$parentInfo = $parentTable->info();
|
||||
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
|
||||
$select->where("$parentColumn = ?", $value, $type);
|
||||
|
||||
// determine where part
|
||||
$type = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
|
||||
$nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
|
||||
if ($value === null && $nullable == true) {
|
||||
$select->where("$parentColumn IS NULL");
|
||||
} elseif ($value === null && $nullable == false) {
|
||||
return null;
|
||||
} else {
|
||||
$select->where("$parentColumn = ?", $value, $type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $parentTable->fetchRow($select);
|
||||
@ -1001,18 +987,10 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
$db = $this->_getTable()->getAdapter();
|
||||
|
||||
if (is_string($intersectionTable)) {
|
||||
if (!class_exists($intersectionTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($intersectionTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$intersectionTable = new $intersectionTable(array('db' => $db));
|
||||
$intersectionTable = $this->_getTableFromString($intersectionTable);
|
||||
}
|
||||
if (! $intersectionTable instanceof Zend_Db_Table_Abstract) {
|
||||
|
||||
if (!$intersectionTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($intersectionTable);
|
||||
if ($type == 'object') {
|
||||
$type = get_class($intersectionTable);
|
||||
@ -1021,18 +999,17 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Intersection table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
if (is_string($matchTable)) {
|
||||
if (!class_exists($matchTable)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($matchTable);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
$matchTable = new $matchTable(array('db' => $db));
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($intersectionTable->getDefinition() == null)) {
|
||||
$intersectionTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if (is_string($matchTable)) {
|
||||
$matchTable = $this->_getTableFromString($matchTable);
|
||||
}
|
||||
|
||||
if (! $matchTable instanceof Zend_Db_Table_Abstract) {
|
||||
$type = gettype($matchTable);
|
||||
if ($type == 'object') {
|
||||
@ -1042,6 +1019,13 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Match table must be a Zend_Db_Table_Abstract, but it is $type");
|
||||
}
|
||||
|
||||
// even if we are interacting between a table defined in a class and a
|
||||
// table via extension, ensure to persist the definition
|
||||
if (($tableDefinition = $this->_table->getDefinition()) !== null
|
||||
&& ($matchTable->getDefinition() == null)) {
|
||||
$matchTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
|
||||
}
|
||||
|
||||
if ($select === null) {
|
||||
$select = $matchTable->select();
|
||||
} else {
|
||||
@ -1168,4 +1152,46 @@ abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
|
||||
throw new Zend_Db_Table_Row_Exception("Unrecognized method '$method()'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _getTableFromString
|
||||
*
|
||||
* @param string $tableName
|
||||
* @return Zend_Db_Table_Abstract
|
||||
*/
|
||||
protected function _getTableFromString($tableName)
|
||||
{
|
||||
|
||||
if ($this->_table instanceof Zend_Db_Table_Abstract) {
|
||||
$tableDefinition = $this->_table->getDefinition();
|
||||
|
||||
if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
|
||||
return new Zend_Db_Table($tableName, $tableDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
// assume the tableName is the class name
|
||||
if (!class_exists($tableName)) {
|
||||
try {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($tableName);
|
||||
} catch (Zend_Exception $e) {
|
||||
require_once 'Zend/Db/Table/Row/Exception.php';
|
||||
throw new Zend_Db_Table_Row_Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
if (($table = $this->_getTable())) {
|
||||
$options['db'] = $table->getAdapter();
|
||||
}
|
||||
|
||||
if (isset($tableDefinition) && $tableDefinition !== null) {
|
||||
$options[Zend_Db_Table_Abstract::DEFINITION] = $tableDefinition;
|
||||
}
|
||||
|
||||
return new $tableName($options);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 16541 2009-07-07 06:59:03Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ require_once 'Zend/Db/Table/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Row_Exception extends Zend_Db_Table_Exception
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Rowset.php 8064 2008-02-16 10:58:39Z thomas $
|
||||
* @version $Id: Rowset.php 16203 2009-06-21 18:56:17Z thomas $
|
||||
*/
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ require_once 'Zend/Db/Table/Rowset/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Rowset extends Zend_Db_Table_Rowset_Abstract
|
||||
|
@ -15,16 +15,16 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 5896 2007-07-27 20:04:24Z bkarwin $
|
||||
* @version $Id: Abstract.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Countable, ArrayAccess
|
||||
|
@ -15,8 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ require_once 'Zend/Db/Table/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Rowset_Exception extends Zend_Db_Table_Exception
|
||||
|
@ -16,9 +16,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Select
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Select.php 5308 2007-06-14 17:18:45Z bkarwin $
|
||||
* @version $Id: Select.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ require_once 'Zend/Db/Table/Abstract.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
@ -185,7 +185,7 @@ class Zend_Db_Table_Select extends Zend_Db_Select
|
||||
* Performs a validation on the select query before passing back to the parent class.
|
||||
* Ensures that only columns from the primary Zend_Db_Table are returned in the result.
|
||||
*
|
||||
* @return string This object as a SELECT string.
|
||||
* @return string|null This object as a SELECT string (or null if a string cannot be produced)
|
||||
*/
|
||||
public function assemble()
|
||||
{
|
||||
|
@ -15,8 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Select
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ require_once 'Zend/Db/Select/Exception.php';
|
||||
* @category Zend
|
||||
* @package Zend_Db
|
||||
* @subpackage Table
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
Reference in New Issue
Block a user