• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Db/Table/Select.php

00001 <?php
00002 
00028 require_once 'Zend/Db/Select.php';
00029 
00030 
00034 require_once 'Zend/Db/Table/Abstract.php';
00035 
00036 
00046 class Zend_Db_Table_Select extends Zend_Db_Select
00047 {
00053     protected $_info;
00054 
00060     protected $_integrityCheck = true;
00061 
00067     protected $_table;
00068 
00074     public function __construct(Zend_Db_Table_Abstract $table)
00075     {
00076         parent::__construct($table->getAdapter());
00077 
00078         $this->setTable($table);
00079     }
00080 
00086     public function getTable()
00087     {
00088         return $this->_table;
00089     }
00090 
00097     public function setTable(Zend_Db_Table_Abstract $table)
00098     {
00099         $this->_adapter = $table->getAdapter();
00100         $this->_info    = $table->info();
00101         $this->_table   = $table;
00102 
00103         return $this;
00104     }
00105 
00115     public function setIntegrityCheck($flag = true)
00116     {
00117         $this->_integrityCheck = $flag;
00118         return $this;
00119     }
00120 
00126     public function isReadOnly()
00127     {
00128         $readOnly = false;
00129         $fields   = $this->getPart(Zend_Db_Table_Select::COLUMNS);
00130         $cols     = $this->_info[Zend_Db_Table_Abstract::COLS];
00131 
00132         if (!count($fields)) {
00133             return $readOnly;
00134         }
00135 
00136         foreach ($fields as $columnEntry) {
00137             $column = $columnEntry[1];
00138             $alias = $columnEntry[2];
00139 
00140             if ($alias !== null) {
00141                 $column = $alias;
00142             }
00143 
00144             switch (true) {
00145                 case ($column == self::SQL_WILDCARD):
00146                     break;
00147 
00148                 case ($column instanceof Zend_Db_Expr):
00149                 case (!in_array($column, $cols)):
00150                     $readOnly = true;
00151                     break 2;
00152             }
00153         }
00154 
00155         return $readOnly;
00156     }
00157 
00171     public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
00172     {
00173         if ($name instanceof Zend_Db_Table_Abstract) {
00174             $info = $name->info();
00175             $name = $info[Zend_Db_Table_Abstract::NAME];
00176             if (isset($info[Zend_Db_Table_Abstract::SCHEMA])) {
00177                 $schema = $info[Zend_Db_Table_Abstract::SCHEMA];
00178             }
00179         }
00180 
00181         return $this->joinInner($name, null, $cols, $schema);
00182     }
00183 
00190     public function assemble()
00191     {
00192         $fields  = $this->getPart(Zend_Db_Table_Select::COLUMNS);
00193         $primary = $this->_info[Zend_Db_Table_Abstract::NAME];
00194         $schema  = $this->_info[Zend_Db_Table_Abstract::SCHEMA];
00195 
00196 
00197         if (count($this->_parts[self::UNION]) == 0) {
00198 
00199             // If no fields are specified we assume all fields from primary table
00200             if (!count($fields)) {
00201                 $this->from($primary, self::SQL_WILDCARD, $schema);
00202                 $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS);
00203             }
00204 
00205             $from = $this->getPart(Zend_Db_Table_Select::FROM);
00206 
00207             if ($this->_integrityCheck !== false) {
00208                 foreach ($fields as $columnEntry) {
00209                     list($table, $column) = $columnEntry;
00210 
00211                     // Check each column to ensure it only references the primary table
00212                     if ($column) {
00213                         if (!isset($from[$table]) || $from[$table]['tableName'] != $primary) {
00214                             require_once 'Zend/Db/Table/Select/Exception.php';
00215                             throw new Zend_Db_Table_Select_Exception('Select query cannot join with another table');
00216                         }
00217                     }
00218                 }
00219             }
00220         }
00221 
00222         return parent::assemble();
00223     }
00224 }

Generated on Thu Apr 19 2012 17:01:17 for openbiz by  doxygen 1.7.2