public function __construct(B2DBStatement $statement) { try { $this->crit = $statement->getCriteria(); if ($this->crit instanceof B2DBCriteria) { if ($this->crit->action == 'insert') { $this->insert_id = $statement->getInsertID(); } elseif ($this->crit->action == 'select') { while ($row = $statement->fetch()) { $this->rows[] = new B2DBRow($row, $statement); } $this->max_ptr = count($this->rows); $this->int_ptr = 0; } elseif ($this->crit->action = 'count') { $value = $statement->fetch(); $this->num_col = $value['num_col']; } } } catch (Exception $e) { throw $e; } }
/** * Perform upgrade for a table, by comparing one table to an old version * of the same table * * @param B2DBTable $old_table */ public function upgrade(B2DBTable $old_table) { if ($old_table->getVersion() != $this->getVersion() - 1) { throw new B2DBException('Cannot upgrade from ' . get_class($old_table) . ' version ' . $old_table->getVersion() . ', must be version ' . ($this->getVersion() - 1)); } $old_columns = $old_table->getColumns(); $new_columns = $this->getColumns(); $added_columns = array_diff_key($new_columns, $old_columns); $altered_columns = array_diff($old_columns, $new_columns); $dropped_columns = array_keys(array_diff_key($old_columns, $new_columns)); $sqls = array(); foreach ($added_columns as $column => $details) { $sqls[] = $this->_getAddColumnSQL($column, $details); } if (count($sqls)) { foreach ($sqls as $sqlStmt) { $statement = B2DBStatement::getPreparedStatement($sqlStmt); $res = $statement->performQuery('alter'); } } $this->_migrateData($old_table); $sqls = array(); foreach ($altered_columns as $column) { $sqls[] = $this->_getAlterColumnSQL($column, $new_columns[$column]); } foreach ($dropped_columns as $column) { $sqls[] = $this->_getDropColumnSQL($column); } if (count($sqls)) { foreach ($sqls as $sqlStmt) { $statement = B2DBStatement::getPreparedStatement($sqlStmt); $res = $statement->performQuery('alter'); } } }
/** * Return the associated B2DBCriteria * * @return B2DBCriteria */ public function getCriteria() { return $this->_statement->getCriteria(); }