public function batchUpdate(Array $dataSet, $withAll=false, $maxLength=4*1024*1024, $runValidation=true)
    {
        $count = 0;
        $sqlBatch = '';
        
        foreach ($dataSet as $key => &$each) {

            // Data format
            list($attributes, $condition) = $each;

            // Check attributes
            if (!is_array($attributes) || !$attributes)
                continue; 

            // Validation
            if ($runValidation && false===$attributes=$this->validate($attributes, true))
                continue; 

            // WithAll helper
            if ($withAll===true) {
                $this->withAll();
            }
                
            // Model Condition
            $query = $this->_findByCondition($condition);

            $attributes = $this->_attrEventBeforeUpdate($attributes);

            // Pack query then move it to write DB from read DB
            $sql = $this->_dbr->set($attributes)->get_compiled_update();
            $this->_dbr->reset_query();

            // Last batch check: First single query & Max length
            // The first single query needs to be sent ahead to prevent the limitation that PDO transaction could not 
            // use multiple SQL line in one query, but allows if the multi-line query is behind a single query. 
            if (($count==0 && $sqlBatch) || strlen($sqlBatch)>=$maxLength) {
                // Each batch of query
                $result = $this->_db->query($sqlBatch);
                $sqlBatch = "";
                $count = ($result) ? $count + 1 : $count;
            }
            
            // Keep Combining query
            $sqlBatch .= "{$sql};\n";
        }

        // Last batch of query
        $result = $this->_db->query($sqlBatch);

        return ($result) ? $count + 1 : $count;
    }
public function batchUpdate(Array $dataSet, $withAll=false, $maxLength=4*1024*1024, $runValidation=true)
    {
        $count = 0;
        $sqlBatch = '';
        
        foreach ($dataSet as $key => &$each) {

            // Data format
            list($attributes, $condition) = $each;

            // Check attributes
            if (!is_array($attributes) || !$attributes)
                continue; 

            // Validation
            if ($runValidation && false===$attributes=$this->validate($attributes, true))
                continue; 

            // WithAll helper
            if ($withAll===true) {
                $this->withAll();
            }
                
            // Model Condition
            $query = $this->_findByCondition($condition);

            $attributes = $this->_attrEventBeforeUpdate($attributes);

            // Pack query then move it to write DB from read DB
            $sql = $this->_dbr->set($attributes)->get_compiled_update();
            $this->_dbr->reset_query();

            // Last batch check: First single query & Max length
            // The first single query needs to be sent ahead to prevent the limitation that PDO transaction could not 
            // use multiple SQL line in one query, but allows if the multi-line query is behind a single query. 
            if (($count==0 && $sqlBatch) || strlen($sqlBatch)>=$maxLength) {
                // Each batch of query
                $result = $this->_db->query($sqlBatch);
                $sqlBatch = "";
                $count = ($result) ? $count + 1 : $count;
            }
            
            // Keep Combining query
            $sqlBatch .= "{$sql};\n";
        }

        // Last batch of query
        $result = $this->_db->query($sqlBatch);

        return ($result) ? $count + 1 : $count;
    }
public function batchUpdate ( Array $ dataSet , $ withAll = false , $ maxLength = 4 * 1024 * 1024 , $ runValidation = true ) { $ count = 0 ; $ sqlBatch = '' ; foreach ( $ dataSet as $ key => & $ each ) { // Data format list ( $ attributes , $ condition ) = $ each ; // Check attributes if ( ! is_array ( $ attributes ) || ! $ attributes ) continue ; // Validation if ( $ runValidation && false === $ attributes = $ this -> validate ( $ attributes , true ) ) continue ; // WithAll helper if ( $ withAll === true ) { $ this -> withAll ( ) ; } // Model Condition $ query = $ this -> _findByCondition ( $ condition ) ; $ attributes = $ this -> _attrEventBeforeUpdate ( $ attributes ) ; // Pack query then move it to write DB from read DB $ sql = $ this -> _dbr -> set ( $ attributes ) -> get_compiled_update ( ) ; $ this -> _dbr -> reset_query ( ) ; // Last batch check: First single query & Max length // The first single query needs to be sent ahead to prevent the limitation that PDO transaction could not  // use multiple SQL line in one query, but allows if the multi-line query is behind a single query.  if ( ( $ count == 0 && $ sqlBatch ) || strlen ( $ sqlBatch ) >= $ maxLength ) { // Each batch of query $ result = $ this -> _db -> query ( $ sqlBatch ) ; $ sqlBatch = "" ; $ count = ( $ result ) ? $ count + 1 : $ count ; } // Keep Combining query $ sqlBatch .= "{$sql};\n" ; } // Last batch of query $ result = $ this -> _db -> query ( $ sqlBatch ) ; return ( $ result ) ? $ count + 1 : $ count ; }
Update a batch of update queries into combined query strings.

@param array $dataSet [[[Attributes], [Condition]], ]
@param boolean $withAll withAll() switch helper
@param integer $maxLenth MySQL max_allowed_packet
@param boolean $runValidation Whether to perform validation (calling validate()) before manipulate the record.
@return integer Count of successful query pack(s)
@example
$result = $this->Model->batchUpdate([
[['title'=>'A1', 'modified'=>'1'], ['id'=>1]],
[['title'=>'A2', 'modified'=>'1'], ['id'=>2]],
];);
Update a batch of update queries into combined query strings .