AddPartition4Range genericviewpageviewsessionviewforwardtrackingcookiepreferences
* * $Id$ * * @author gERD Schaufelberger * @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_Decorator'); /** * AddPartition4Range * * Maintainance for Partitioned tables * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_Decorator_AddPartition4Range extends WBDatasource_Decorator { /** * Decorator's Parameter List * * Parameters: * - table: list of tables * - field: name column to find the year * * @var array */ protected $parameter = array( 'field' => 'year', 'table' => array(), ); /** * Database Connection * @var WBDatasource_SQL */ private $db; /** * Actually Decorate List Item * * @param array $item * @return void */ public function decorate(&$item) { return; if (empty($item[$this->parameter['field']])) { throw WBClass::create('WBException_Config', array( 'msg' => 'Could column ' . $this->parameter['field'] . ' must bot be empty', 'code' => 1, 'class' => __CLASS__ )); return; } if (empty($this->parameter['table'])) { throw WBClass::create('WBException_Config', array( 'msg' => 'List of tables must not be empty', 'code' => 2, 'class' => __CLASS__ )); return; } $next = intval($item[$this->parameter['field']]); $sql = 'ALTER TABLE %s ADD PARTITION (PARTITION p%d VALUES LESS THAN (%d))'; /** @var WBDatasource_Table */ $table = WBClass::create( 'WBDatasource_Table'); $this->db = WBClass::create( 'WBDatasource_SQL'); foreach ($this->parameter['table'] as $t) { $info = $table->getTableInfo($t); $query = sprintf($sql, $info['table'], $next, $next + 1); $this->db->query($query); } } }