Просмотр исходного кода

Added schema support. Fixes ZF-7347

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17157 44c647ce-9c0f-0410-b52a-842ac1e357ba
bittarman 16 лет назад
Родитель
Сommit
4dd62a93d2
1 измененных файлов с 17 добавлено и 5 удалено
  1. 17 5
      library/Zend/Validate/Db/Abstract.php

+ 17 - 5
library/Zend/Validate/Db/Abstract.php

@@ -47,7 +47,12 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
      */    
     protected $_messageTemplates = array(self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found', 
                                          self::ERROR_RECORD_FOUND    => 'A record matching %value% was found');     
- 
+
+    /**
+     * @var string
+     */ 
+    protected $_schema = null;
+     
     /**
      * @var string
      */    
@@ -57,7 +62,7 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
      * @var string
      */    
     protected $_field = '';    
-       
+    
     /**
      * @var mixed
      */   
@@ -77,7 +82,7 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
      * to define the where clause added to the sql.  
      * A database adapter may optionally be supplied to avoid using the registered default adapter. 
      * 
-     * @param string $table The database table to validate against
+     * @param string||array $table The database table to validate against, or array with table and schema keys
      * @param string $field The field to check for a match
      * @param string||array $exclude An optional where clause or field/value pair to exclude from the query
      * @param Zend_Db_Adapter_Abstract $adapter An optional database adapter to use.
@@ -88,8 +93,15 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
             $this->_adapter = $adapter;    
         }   
         $this->_exclude = $exclude;   
-        $this->_table   = (string) $table;    
         $this->_field   = (string) $field;   
+        
+        if (is_array($table)) {
+            $this->_table  = (isset($table['table'])) ? $table['table'] : '';
+            $this->_schema = (isset($table['schema'])) ? $table['schema'] : null;                
+        } else {
+            $this->_table = (string) $table;            
+        }
+
     }  
      
     /**
@@ -115,7 +127,7 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
          * Build select object
          */ 
         $select = new Zend_Db_Select($this->_adapter);
-        $select->from($this->_table, array($this->_field))
+        $select->from($this->_table, array($this->_field), $this->_schema)
                ->where($this->_adapter->quoteIdentifier($this->_field).' = ?', $value); 
         if ($this->_exclude !== null) { 
             if (is_array($this->_exclude)) {