240 protected $_options = [
'type' =>
'INNODB',
'charset' =>
'utf8',
'collate' =>
'utf8_general_ci'];
250 $this->_tableName =
$name;
251 if ($this->_tableComment ===
null) {
252 $this->_tableComment =
$name;
265 $this->_schemaName =
$name;
277 $this->_tableComment = $comment;
289 if ($this->_tableName ===
null) {
290 throw new \Zend_Db_Exception(
'Table name is not defined');
341 $position = count($this->_columns);
349 $primaryPosition = 0;
378 if (is_array($size)) {
379 if (count($size) == 2) {
380 $size = array_values($size);
381 $precision = $size[0];
384 }
elseif (preg_match(
'#^(\d+),(\d+)$#', $size, $match)) {
385 $precision = $match[1];
411 throw new \Zend_Db_Exception(
'Invalid column data type "' .
$type .
'"');
414 if (array_key_exists(
'default',
$options)) {
417 if (array_key_exists(
'nullable',
$options)) {
418 $nullable = (bool)
$options[
'nullable'];
422 if (isset(
$options[
'primary_position'])) {
423 $primaryPosition = (int)
$options[
'primary_position'];
425 $primaryPosition = 0;
426 foreach ($this->_columns as $v) {
437 if ($comment ===
null) {
438 $comment = ucfirst(
$name);
441 $upperName = strtoupper(
$name);
442 $this->_columns[$upperName] = [
443 'COLUMN_NAME' =>
$name,
444 'COLUMN_TYPE' =>
$type,
445 'COLUMN_POSITION' => $position,
446 'DATA_TYPE' =>
$type,
447 'DEFAULT' => $default,
448 'NULLABLE' => $nullable,
451 'PRECISION' => $precision,
452 'UNSIGNED' => $unsigned,
453 'PRIMARY' => $primary,
454 'PRIMARY_POSITION' => $primaryPosition,
455 'IDENTITY' => $identity,
456 'COMMENT' => $comment,
474 public function addForeignKey($fkName, $column, $refTable, $refColumn, $onDelete =
null)
476 $upperName = strtoupper($fkName);
479 if (!isset($this->_columns[strtoupper($column)])) {
480 throw new \Zend_Db_Exception(
'Undefined column "' . $column .
'"');
493 $this->_foreignKeys[$upperName] = [
494 'FK_NAME' => $fkName,
495 'COLUMN_NAME' => $column,
496 'REF_TABLE_NAME' => $refTable,
497 'REF_COLUMN_NAME' => $refColumn,
498 'ON_DELETE' => $onDelete
523 foreach (
$fields as $columnData) {
525 $columnPos = $position;
526 if (is_string($columnData)) {
527 $columnName = $columnData;
528 }
elseif (is_array($columnData)) {
529 if (!isset($columnData[
'name'])) {
530 throw new \Zend_Db_Exception(
'Invalid index column data');
533 $columnName = $columnData[
'name'];
534 if (!empty($columnData[
'size'])) {
535 $columnSize = (int)$columnData[
'size'];
537 if (!empty($columnData[
'position'])) {
538 $columnPos = (int)$columnData[
'position'];
547 'NAME' => $columnName,
548 'SIZE' => $columnSize,
549 'POSITION' => $columnPos,
556 throw new \Zend_Db_Exception(
'Columns for index are not defined');
563 $this->_indexes[strtoupper(
566 'INDEX_NAME' => $indexName,
598 $upperName = strtoupper($column[
'COLUMN_NAME']);
599 $this->_columns[$upperName] = $column;
634 $this->_options[$key] =
$value;
647 if (!isset($this->_options[$key])) {
650 return $this->_options[$key];
672 return $a[
'POSITION'] - $b[
'POSITION'];
684 return $a[
'COLUMN_POSITION'] - $b[
'COLUMN_POSITION'];
695 uasort(
$columns, [$this,
'_sortIndexColumnPosition']);
697 foreach (array_keys(
$columns) as $columnId) {
698 $columns[$columnId][
'POSITION'] = $position;
712 uasort(
$columns, [$this,
'_sortColumnPosition']);
714 foreach (array_keys(
$columns) as $columnId) {
715 $columns[$columnId][
'COLUMN_POSITION'] = $position;
elseif(isset( $params[ 'redirect_parent']))
_sortIndexColumnPosition($a, $b)
addColumn($name, $type, $size=null, $options=[], $comment=null)
const TIMESTAMP_INIT_UPDATE
_normalizeIndexColumnPosition($columns)
_normalizeColumnPosition($columns)
addForeignKey($fkName, $column, $refTable, $refColumn, $onDelete=null)
addIndex($indexName, $fields, $options=[])
getColumns($normalized=true)
_sortColumnPosition($a, $b)
if(!isset($_GET['name'])) $name