protected function createName() { $inputs[] = $this->table->getDatabase(); $inputs[] = $this->table->getCommonName(); $inputs[] = 'I'; $inputs[] = count($this->table->getIndices()) + 1; // @TODO replace the factory by a real object $this->name = NameFactory::generateName(NameFactory::CONSTRAINT_GENERATOR, $inputs); }
/** * @param Table $table * * @return bool */ protected function hasCompositeNumberRangeBehavior(Table $table) { if ($table->hasBehavior(self::BEHAVIOR_NAME)) { if ($table->hasBehavior('concrete_inheritance')) { // we're a child in a concrete inheritance $parentTableName = $table->getBehavior('concrete_inheritance')->getParameter('extends'); $parentTable = $table->getDatabase()->getTable($parentTableName); if ($parentTable->hasBehavior(self::BEHAVIOR_NAME)) { //we're a child of a concrete inheritance structure, so we're going to skip this //round here because this behavior has also been attached by the parent table. return false; } } return true; } return false; }
/** * Load foreign keys for this table. */ protected function addForeignKeys(Table $table) { $database = $table->getDatabase(); $dataFetcher = $this->dbh->query("SELECT ccu1.TABLE_NAME, ccu1.COLUMN_NAME, ccu2.TABLE_NAME AS FK_TABLE_NAME, ccu2.COLUMN_NAME AS FK_COLUMN_NAME\n FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu1 INNER JOIN\n INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc1 ON tc1.CONSTRAINT_NAME = ccu1.CONSTRAINT_NAME AND\n CONSTRAINT_TYPE = 'Foreign Key' INNER JOIN\n INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1 ON rc1.CONSTRAINT_NAME = tc1.CONSTRAINT_NAME INNER JOIN\n INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu2 ON ccu2.CONSTRAINT_NAME = rc1.UNIQUE_CONSTRAINT_NAME\n WHERE (ccu1.table_name = '" . $table->getName() . "')"); $foreignKeys = array(); // local store to avoid duplicates foreach ($dataFetcher as $row) { $lcol = $this->cleanDelimitedIdentifiers($row['COLUMN_NAME']); $ftbl = $this->cleanDelimitedIdentifiers($row['FK_TABLE_NAME']); $fcol = $this->cleanDelimitedIdentifiers($row['FK_COLUMN_NAME']); $foreignTable = $database->getTable($ftbl); $foreignColumn = $foreignTable->getColumn($fcol); $localColumn = $table->getColumn($lcol); if (!isset($foreignKeys[$name])) { $fk = new ForeignKey($name); $fk->setForeignTableCommonName($foreignTable->getCommonName()); $fk->setForeignSchemaName($foreignTable->getSchema()); //$fk->setOnDelete($fkactions['ON DELETE']); //$fk->setOnUpdate($fkactions['ON UPDATE']); $table->addForeignKey($fk); $foreignKeys[$name] = $fk; } $foreignKeys[$name]->addReference($localColumn, $foreignColumn); } }
/** * Returns the database object the current column is in. * * @return Database */ private function getDatabase() { return $this->parentTable->getDatabase(); }
/** * Load foreign keys for this table. */ protected function addForeignKeys(Table $table, $oid) { $database = $table->getDatabase(); $stmt = $this->dbh->prepare("SELECT\n conname,\n confupdtype,\n confdeltype,\n CASE nl.nspname WHEN 'public' THEN cl.relname ELSE nl.nspname||'.'||cl.relname END as fktab,\n array_agg(DISTINCT a2.attname) AS fkcols,\n CASE nr.nspname WHEN 'public' THEN cr.relname ELSE nr.nspname||'.'||cr.relname END as reftab,\n array_agg(DISTINCT a1.attname) AS refcols\n FROM pg_constraint ct\n JOIN pg_class cl ON cl.oid=conrelid\n JOIN pg_class cr ON cr.oid=confrelid\n JOIN pg_namespace nl ON nl.oid = cl.relnamespace\n JOIN pg_namespace nr ON nr.oid = cr.relnamespace\n LEFT JOIN pg_catalog.pg_attribute a1 ON a1.attrelid = ct.confrelid\n LEFT JOIN pg_catalog.pg_attribute a2 ON a2.attrelid = ct.conrelid\n WHERE\n contype='f'\n AND conrelid = ?\n AND a2.attnum = ANY (ct.conkey)\n AND a1.attnum = ANY (ct.confkey)\n GROUP BY conname, confupdtype, confdeltype, fktab, reftab\n ORDER BY conname"); $stmt->bindValue(1, $oid); $stmt->execute(); $foreignKeys = array(); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $name = $row['conname']; $localTable = $row['fktab']; $localColumns = explode(',', trim($row['fkcols'], '{}')); $foreignTableName = $row['reftab']; $foreignColumns = explode(',', trim($row['refcols'], '{}')); // On Update switch ($row['confupdtype']) { case 'c': $onupdate = ForeignKey::CASCADE; break; case 'd': $onupdate = ForeignKey::SETDEFAULT; break; case 'n': $onupdate = ForeignKey::SETNULL; break; case 'r': $onupdate = ForeignKey::RESTRICT; break; default: case 'a': // NOACTION is the postgresql default $onupdate = ForeignKey::NONE; break; } // On Delete switch ($row['confdeltype']) { case 'c': $ondelete = ForeignKey::CASCADE; break; case 'd': $ondelete = ForeignKey::SETDEFAULT; break; case 'n': $ondelete = ForeignKey::SETNULL; break; case 'r': $ondelete = ForeignKey::RESTRICT; break; default: case 'a': // NOACTION is the postgresql default $ondelete = ForeignKey::NONE; break; } $foreignTable = $database->getTable($foreignTableName); $localTable = $database->getTable($localTable); if (!$foreignTable) { continue; } if (!isset($foreignKeys[$name])) { $fk = new ForeignKey($name); $fk->setForeignTableCommonName($foreignTable->getCommonName()); if ($table->guessSchemaName() != $foreignTable->guessSchemaName()) { $fk->setForeignSchemaName($foreignTable->getSchema()); } $fk->setOnDelete($ondelete); $fk->setOnUpdate($onupdate); $table->addForeignKey($fk); $foreignKeys[$name] = $fk; } $max = count($localColumns); for ($i = 0; $i < $max; $i++) { $foreignKeys[$name]->addReference($localTable->getColumn($localColumns[$i]), $foreignTable->getColumn($foreignColumns[$i])); } } }
/** * Returns the resolved foreign Table model object. * * @return Table */ public function getForeignTable() { if ($database = $this->parentTable->getDatabase()) { return $database->getTable($this->getForeignTableName()); } }
/** * Returns the computed difference between two table objects. * * @param Table $fromTable * @param Table $toTable * @param boolean $caseInsensitive * @return TableDiff|Boolean */ public static function computeDiff(Table $fromTable, Table $toTable, $caseInsensitive = false) { $tc = new self(); $tc->setFromTable(clone $fromTable); $tc->setToTable(clone $toTable); if ($toTable->getDatabase() || $fromTable->getDatabase()) { $platform = $toTable->getDatabase()->getPlatform() ?: $fromTable->getDatabase()->getPlatform(); if ($platform) { $platform->normalizeTable($tc->getFromTable()); $platform->normalizeTable($tc->getToTable()); } } $differences = 0; $differences += $tc->compareColumns($caseInsensitive); $differences += $tc->comparePrimaryKeys($caseInsensitive); $differences += $tc->compareIndices($caseInsensitive); $differences += $tc->compareForeignKeys($caseInsensitive); return $differences > 0 ? $tc->getTableDiff() : false; }
/** * Sets up the Column object based on the attributes that were passed to loadFromXML(). * @see parent::loadFromXML() */ protected function setupObject() { try { $dom = $this->getAttribute("domain"); if ($dom) { $this->getDomain()->copy($this->getTable()->getDatabase()->getDomain($dom)); } else { $type = strtoupper($this->getAttribute("type")); if ($type) { if ($platform = $this->getPlatform()) { $this->getDomain()->copy($this->getPlatform()->getDomainForType($type)); } else { // no platform - probably during tests $this->setDomain(new Domain($type)); } } else { if ($platform = $this->getPlatform()) { $this->getDomain()->copy($this->getPlatform()->getDomainForType(self::DEFAULT_TYPE)); } else { // no platform - probably during tests $this->setDomain(new Domain(self::DEFAULT_TYPE)); } } } $this->name = $this->getAttribute("name"); $this->phpName = $this->getAttribute("phpName"); $this->phpType = $this->getAttribute("phpType"); if ($this->getAttribute("prefix", null) !== null) { $this->namePrefix = $this->getAttribute("prefix"); } elseif ($this->getTable()->getAttribute('columnPrefix', null) !== null) { $this->namePrefix = $this->getTable()->getAttribute('columnPrefix'); } else { $this->namePrefix = ''; } // Accessor visibility if ($this->getAttribute('accessorVisibility', null) !== null) { $this->setAccessorVisibility($this->getAttribute('accessorVisibility')); } elseif ($this->getTable()->getAttribute('defaultAccessorVisibility', null) !== null) { $this->setAccessorVisibility($this->getTable()->getAttribute('defaultAccessorVisibility')); } elseif ($this->getTable()->getDatabase()->getAttribute('defaultAccessorVisibility', null) !== null) { $this->setAccessorVisibility($this->getTable()->getDatabase()->getAttribute('defaultAccessorVisibility')); } else { $this->setAccessorVisibility(self::DEFAULT_VISIBILITY); } // Mutator visibility if ($this->getAttribute('mutatorVisibility', null) !== null) { $this->setMutatorVisibility($this->getAttribute('mutatorVisibility')); } elseif ($this->getTable()->getAttribute('defaultMutatorVisibility', null) !== null) { $this->setMutatorVisibility($this->getTable()->getAttribute('defaultMutatorVisibility')); } elseif ($this->getTable()->getDatabase()->getAttribute('defaultMutatorVisibility', null) !== null) { $this->setMutatorVisibility($this->getTable()->getDatabase()->getAttribute('defaultMutatorVisibility')); } else { $this->setMutatorVisibility(self::DEFAULT_VISIBILITY); } $this->peerName = $this->getAttribute("peerName"); // retrieves the method for converting from specified name to a PHP name, defaulting to parent tables default method $this->phpNamingMethod = $this->getAttribute("phpNamingMethod", $this->parentTable->getDatabase()->getDefaultPhpNamingMethod()); $this->isPrimaryString = $this->booleanValue($this->getAttribute("primaryString")); $this->isPrimaryKey = $this->booleanValue($this->getAttribute("primaryKey")); $this->isNodeKey = $this->booleanValue($this->getAttribute("nodeKey")); $this->nodeKeySep = $this->getAttribute("nodeKeySep", "."); $this->isNestedSetLeftKey = $this->booleanValue($this->getAttribute("nestedSetLeftKey")); $this->isNestedSetRightKey = $this->booleanValue($this->getAttribute("nestedSetRightKey")); $this->isTreeScopeKey = $this->booleanValue($this->getAttribute("treeScopeKey")); $this->isNotNull = $this->booleanValue($this->getAttribute("required"), false) || $this->isPrimaryKey; // primary keys are required //AutoIncrement/Sequences $this->isAutoIncrement = $this->booleanValue($this->getAttribute("autoIncrement")); $this->isLazyLoad = $this->booleanValue($this->getAttribute("lazyLoad")); // Add type, size information to associated Domain object $this->getDomain()->replaceSqlType($this->getAttribute("sqlType")); if (!$this->getAttribute("size") && $this->getDomain()->getType() == 'VARCHAR' && $this->hasPlatform() && !$this->getAttribute("sqlType") && !$this->getPlatform()->supportsVarcharWithoutSize()) { $size = 255; } else { $size = $this->getAttribute("size"); } $this->getDomain()->replaceSize($size); $this->getDomain()->replaceScale($this->getAttribute("scale")); $defval = $this->getAttribute("defaultValue", $this->getAttribute("default")); if ($defval !== null && strtolower($defval) !== 'null') { $this->getDomain()->setDefaultValue(new ColumnDefaultValue($defval, ColumnDefaultValue::TYPE_VALUE)); } elseif ($this->getAttribute("defaultExpr") !== null) { $this->getDomain()->setDefaultValue(new ColumnDefaultValue($this->getAttribute("defaultExpr"), ColumnDefaultValue::TYPE_EXPR)); } if ($this->getAttribute('valueSet', null) !== null) { $valueSet = explode(',', $this->getAttribute("valueSet")); $valueSet = array_map('trim', $valueSet); $this->valueSet = $valueSet; } $this->inheritanceType = $this->getAttribute("inheritance"); $this->isInheritance = $this->inheritanceType !== null && $this->inheritanceType !== "false"; // here we are only checking for 'false', so don't // use boleanValue() $this->description = $this->getAttribute("description"); } catch (Exception $e) { throw new EngineException("Error setting up column " . var_export($this->getAttribute("name"), true) . ": " . $e->getMessage()); } }
protected function addParentColumn(Table $table, $id_name) { $name = $this->getParameter('parent_name'); //Остановился тут if (!$table->getColumnForeignKeys($name)) { //var_dump($table->getColumnForeignKeys('parent_id')); //foreach($table->getForeignKeys() as $column) { // var_dump($column->getForeignColumns(), $column->getName()); //} } foreach ($table->getDatabase()->getTables() as $table) { //echo $table->getName()."\n"; } //exit; }
/** * Returns a configured data model builder class for specified table and * based on type ('ddl', 'sql', etc.). * * @param Table $table * @param string $type * @return DataModelBuilder */ public function getConfiguredBuilder(Table $table, $type) { $classname = $table->getDatabase()->getPlatform()->getBuilderClass($type); if (!$classname) { $classname = $this->getBuilderClassName($type); } $builder = new $classname($table); $builder->setGeneratorConfig($this); return $builder; }
/** * Load foreign keys for this table. */ protected function addForeignKeys(Table $table) { $database = $table->getDatabase(); $stmt = $this->dbh->query("SHOW CREATE TABLE `" . $table->getName() . "`"); $row = $stmt->fetch(PDO::FETCH_NUM); $foreignKeys = array(); // local store to avoid duplicates // Get the information on all the foreign keys $regEx = '/CONSTRAINT `([^`]+)` FOREIGN KEY \\((.+)\\) REFERENCES `([^`]*)` \\((.+)\\)(.*)/'; if (preg_match_all($regEx, $row[1], $matches)) { $tmpArray = array_keys($matches[0]); foreach ($tmpArray as $curKey) { $name = $matches[1][$curKey]; $rawlcol = $matches[2][$curKey]; $ftbl = $matches[3][$curKey]; $rawfcol = $matches[4][$curKey]; $fkey = $matches[5][$curKey]; $lcols = array(); foreach (preg_split('/`, `/', $rawlcol) as $piece) { $lcols[] = trim($piece, '` '); } $fcols = array(); foreach (preg_split('/`, `/', $rawfcol) as $piece) { $fcols[] = trim($piece, '` '); } //typical for mysql is RESTRICT $fkactions = array('ON DELETE' => ForeignKey::RESTRICT, 'ON UPDATE' => ForeignKey::RESTRICT); if ($fkey) { //split foreign key information -> search for ON DELETE and afterwords for ON UPDATE action foreach (array_keys($fkactions) as $fkaction) { $result = NULL; preg_match('/' . $fkaction . ' (' . ForeignKey::CASCADE . '|' . ForeignKey::SETNULL . ')/', $fkey, $result); if ($result && is_array($result) && isset($result[1])) { $fkactions[$fkaction] = $result[1]; } } } // restrict is the default foreach ($fkactions as $key => $action) { if ($action == ForeignKey::RESTRICT) { $fkactions[$key] = null; } } $localColumns = array(); $foreignColumns = array(); $foreignTable = $database->getTable($ftbl, true); foreach ($fcols as $fcol) { $foreignColumns[] = $foreignTable->getColumn($fcol); } foreach ($lcols as $lcol) { $localColumns[] = $table->getColumn($lcol); } if (!isset($foreignKeys[$name])) { $fk = new ForeignKey($name); $fk->setForeignTableCommonName($foreignTable->getCommonName()); $fk->setForeignSchemaName($foreignTable->getSchema()); $fk->setOnDelete($fkactions['ON DELETE']); $fk->setOnUpdate($fkactions['ON UPDATE']); $table->addForeignKey($fk); $foreignKeys[$name] = $fk; } for ($i = 0; $i < count($localColumns); $i++) { $foreignKeys[$name]->addReference($localColumns[$i], $foreignColumns[$i]); } } } }
/** * Load foreign keys for this table. */ protected function addForeignKeys(Table $table) { $database = $table->getDatabase(); $dataFetcher = $this->dbh->query(sprintf('SHOW CREATE TABLE %s', $this->getPlatform()->doQuoting($table->getName()))); $row = $dataFetcher->fetch(); $foreignKeys = array(); // local store to avoid duplicates // Get the information on all the foreign keys $pattern = '/CONSTRAINT `([^`]+)` FOREIGN KEY \\((.+)\\) REFERENCES `([^\\s]+)` \\((.+)\\)(.*)/'; if (preg_match_all($pattern, $row[1], $matches)) { $tmpArray = array_keys($matches[0]); foreach ($tmpArray as $curKey) { $name = $matches[1][$curKey]; $rawlcol = $matches[2][$curKey]; $ftbl = str_replace('`', '', $matches[3][$curKey]); $rawfcol = $matches[4][$curKey]; $fkey = $matches[5][$curKey]; $lcols = array(); foreach (preg_split('/`, `/', $rawlcol) as $piece) { $lcols[] = trim($piece, '` '); } $fcols = array(); foreach (preg_split('/`, `/', $rawfcol) as $piece) { $fcols[] = trim($piece, '` '); } // typical for mysql is RESTRICT $fkactions = array('ON DELETE' => ForeignKey::RESTRICT, 'ON UPDATE' => ForeignKey::RESTRICT); if ($fkey) { // split foreign key information -> search for ON DELETE and afterwords for ON UPDATE action foreach (array_keys($fkactions) as $fkaction) { $result = null; preg_match('/' . $fkaction . ' (' . ForeignKey::CASCADE . '|' . ForeignKey::SETNULL . ')/', $fkey, $result); if ($result && is_array($result) && isset($result[1])) { $fkactions[$fkaction] = $result[1]; } } } // restrict is the default foreach ($fkactions as $key => $action) { if (ForeignKey::RESTRICT === $action) { $fkactions[$key] = null; } } $localColumns = array(); $foreignColumns = array(); if ($table->guessSchemaName() != $database->getSchema() && false == strpos($ftbl, $database->getPlatform()->getSchemaDelimiter())) { $ftbl = $table->guessSchemaName() . $database->getPlatform()->getSchemaDelimiter() . $ftbl; } $foreignTable = $database->getTable($ftbl, true); if (!$foreignTable) { continue; } foreach ($fcols as $fcol) { $foreignColumns[] = $foreignTable->getColumn($fcol); } foreach ($lcols as $lcol) { $localColumns[] = $table->getColumn($lcol); } if (!isset($foreignKeys[$name])) { $fk = new ForeignKey($name); $fk->setForeignTableCommonName($foreignTable->getCommonName()); if ($table->guessSchemaName() != $foreignTable->guessSchemaName()) { $fk->setForeignSchemaName($foreignTable->guessSchemaName()); } $fk->setOnDelete($fkactions['ON DELETE']); $fk->setOnUpdate($fkactions['ON UPDATE']); $table->addForeignKey($fk); $foreignKeys[$name] = $fk; } $max = count($localColumns); for ($i = 0; $i < $max; $i++) { $foreignKeys[$name]->addReference($localColumns[$i], $foreignColumns[$i]); } } } }
/** * Load foreign keys for this table. */ protected function addForeignKeys(Table $table) { $database = $table->getDatabase(); $dataFetcher = $this->dbh->query("select fk.name as CONSTRAINT_NAME, lcol.name as COLUMN_NAME, rtab.name as FK_TABLE_NAME, rcol.name as FK_COLUMN_NAME\n from sys.foreign_keys as fk \n inner join sys.foreign_key_columns ref on ref.constraint_object_id = fk.object_id\n inner join sys.columns lcol on lcol.object_id = ref.parent_object_id and lcol.column_id = ref.parent_column_id\n inner join sys.columns rcol on rcol.object_id = ref.referenced_object_id and rcol.column_id = ref.referenced_column_id\n inner join sys.tables rtab on rtab.object_id = ref.referenced_object_id\n where fk.parent_object_id = OBJECT_ID('" . $table->getName() . "')"); $dataFetcher->setStyle(\PDO::FETCH_ASSOC); $foreignKeys = []; // local store to avoid duplicates foreach ($dataFetcher as $row) { $name = $this->cleanDelimitedIdentifiers($row['CONSTRAINT_NAME']); $lcol = $this->cleanDelimitedIdentifiers($row['COLUMN_NAME']); $ftbl = $this->cleanDelimitedIdentifiers($row['FK_TABLE_NAME']); $fcol = $this->cleanDelimitedIdentifiers($row['FK_COLUMN_NAME']); $foreignTable = $database->getTable($ftbl); $foreignColumn = $foreignTable->getColumn($fcol); $localColumn = $table->getColumn($lcol); if (!isset($foreignKeys[$name])) { $fk = new ForeignKey($name); $fk->setForeignTableCommonName($foreignTable->getCommonName()); $fk->setForeignSchemaName($foreignTable->getSchema()); //$fk->setOnDelete($fkactions['ON DELETE']); //$fk->setOnUpdate($fkactions['ON UPDATE']); $table->addForeignKey($fk); $foreignKeys[$name] = $fk; } $foreignKeys[$name]->addReference($localColumn, $foreignColumn); } }
protected function addForeignKeys(Table $table) { $stmt = $this->dbh->query('PRAGMA foreign_key_list("' . $table->getName() . '")'); $lastId = null; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($lastId !== $row['id']) { $fk = new ForeignKey(); $tableName = $row['table']; $tableSchema = ''; if (false !== ($pos = strpos($tableName, '§'))) { $tableName = substr($tableName, $pos + 2); $tableSchema = substr($tableName, 0, $pos); } $fk->setForeignTableCommonName($tableName); if ($table->getDatabase()->getSchema() != $tableSchema) { $fk->setForeignSchemaName($tableSchema); } $fk->setOnDelete($row['on_delete']); $fk->setOnUpdate($row['on_update']); $table->addForeignKey($fk); $lastId = $row['id']; } $fk->addReference($row['from'], $row['to']); } }
protected function addForeignKeys(Table $table) { $database = $table->getDatabase(); $stmt = $this->dbh->query('PRAGMA foreign_key_list("' . $table->getName() . '")'); $lastId = null; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($lastId !== $row['id']) { $fk = new ForeignKey(); $onDelete = $row['on_delete']; if ($onDelete && 'NO ACTION' !== $onDelete) { $fk->setOnDelete($onDelete); } $onUpdate = $row['on_update']; if ($onUpdate && 'NO ACTION' !== $onUpdate) { $fk->setOnUpdate($onUpdate); } $foreignTable = $database->getTable($row['table'], true); if (!$foreignTable) { continue; } $table->addForeignKey($fk); $fk->setForeignTableCommonName($foreignTable->getCommonName()); if ($table->guessSchemaName() != $foreignTable->guessSchemaName()) { $fk->setForeignSchemaName($foreignTable->guessSchemaName()); } $lastId = $row['id']; } $fk->addReference($row['from'], $row['to']); } }
protected function getTableOptions(Table $table) { $dbVI = $table->getDatabase()->getVendorInfoForType('mysql'); $tableVI = $table->getVendorInfoForType('mysql'); $vi = $dbVI->getMergedVendorInfo($tableVI); $tableOptions = array(); // List of supported table options // see http://dev.mysql.com/doc/refman/5.5/en/create-table.html $supportedOptions = array('AutoIncrement' => 'AUTO_INCREMENT', 'AvgRowLength' => 'AVG_ROW_LENGTH', 'Charset' => 'CHARACTER SET', 'Checksum' => 'CHECKSUM', 'Collate' => 'COLLATE', 'Connection' => 'CONNECTION', 'DataDirectory' => 'DATA DIRECTORY', 'Delay_key_write' => 'DELAY_KEY_WRITE', 'DelayKeyWrite' => 'DELAY_KEY_WRITE', 'IndexDirectory' => 'INDEX DIRECTORY', 'InsertMethod' => 'INSERT_METHOD', 'KeyBlockSize' => 'KEY_BLOCK_SIZE', 'MaxRows' => 'MAX_ROWS', 'MinRows' => 'MIN_ROWS', 'Pack_Keys' => 'PACK_KEYS', 'PackKeys' => 'PACK_KEYS', 'RowFormat' => 'ROW_FORMAT', 'Union' => 'UNION'); foreach ($supportedOptions as $name => $sqlName) { $parameterValue = null; if ($vi->hasParameter($name)) { $parameterValue = $vi->getParameter($name); } elseif ($vi->hasParameter($sqlName)) { $parameterValue = $vi->getParameter($sqlName); } // if we have a param value, then parse it out if (!is_null($parameterValue)) { // if the value is numeric, then there is no need for quotes $parameterValue = is_numeric($parameterValue) ? $parameterValue : $this->quote($parameterValue); $tableOptions[] = sprintf('%s=%s', $sqlName, $parameterValue); } } return $tableOptions; }
/** * Appends the generated <table> XML node to its parent node. * * @param Table $table The Table model instance * @param \DOMNode $parentNode The parent DOMNode object */ private function appendTableNode(Table $table, \DOMNode $parentNode) { $tableNode = $parentNode->appendChild($this->document->createElement('table')); $tableNode->setAttribute('name', $table->getCommonName()); $database = $table->getDatabase(); $schema = $table->getSchema(); if ($schema && $schema !== $database->getSchema()) { $tableNode->setAttribute('schema', $schema); } if (IdMethod::NO_ID_METHOD !== ($idMethod = $table->getIdMethod())) { $tableNode->setAttribute('idMethod', $idMethod); } if ($phpName = $table->getPhpName()) { $tableNode->setAttribute('phpName', $phpName); } $package = $table->getPackage(); if ($package && !$table->isPackageOverriden()) { $tableNode->setAttribute('package', $package); } if ($namespace = $table->getNamespace()) { $tableNode->setAttribute('namespace', $namespace); } if ($table->isSkipSql()) { $tableNode->setAttribute('skipSql', 'true'); } if ($table->isAbstract()) { $tableNode->setAttribute('abstract', 'true'); } if ($interface = $table->getInterface()) { $tableNode->setAttribute('interface', $interface); } if ($table->isCrossRef()) { $tableNode->setAttribute('isCrossRef', 'true'); } $phpNamingMethod = $table->getPhpNamingMethod(); if ($phpNamingMethod && $phpNamingMethod !== $database->getDefaultPhpNamingMethod()) { $tableNode->setAttribute('phpNamingMethod', $phpNamingMethod); } if ($baseClass = $table->getBaseClass()) { $tableNode->setAttribute('baseClass', $baseClass); } if ($baseQueryClass = $table->getBaseQueryClass()) { $tableNode->setAttribute('baseQueryClass', $baseQueryClass); } if ($table->isReadOnly()) { $tableNode->setAttribute('readOnly', 'true'); } if ($table->isReloadOnInsert()) { $tableNode->setAttribute('reloadOnInsert', 'true'); } if ($table->isReloadOnUpdate()) { $tableNode->setAttribute('reloadOnUpdate', 'true'); } if (null !== ($referenceOnly = $table->isForReferenceOnly())) { $tableNode->setAttribute('forReferenceOnly', $referenceOnly ? 'true' : 'false'); } if ($alias = $table->getAlias()) { $tableNode->setAttribute('alias', $alias); } if ($description = $table->getDescription()) { $tableNode->setAttribute('description', $description); } $defaultStringFormat = $table->getDefaultStringFormat(); if (Table::DEFAULT_STRING_FORMAT !== $defaultStringFormat) { $tableNode->setAttribute('defaultStringFormat', $defaultStringFormat); } $defaultAccessorVisibility = $table->getDefaultAccessorVisibility(); if ($defaultAccessorVisibility !== Table::VISIBILITY_PUBLIC) { $tableNode->setAttribute('defaultAccessorVisibility', $defaultAccessorVisibility); } $defaultMutatorVisibility = $table->getDefaultMutatorVisibility(); if ($defaultMutatorVisibility !== Table::VISIBILITY_PUBLIC) { $tableNode->setAttribute('defaultMutatorVisibility', $defaultMutatorVisibility); } foreach ($table->getColumns() as $column) { $this->appendColumnNode($column, $tableNode); } foreach ($table->getForeignKeys() as $foreignKey) { $this->appendForeignKeyNode($foreignKey, $tableNode); } foreach ($table->getIdMethodParameters() as $parameter) { $this->appendIdMethodParameterNode($parameter, $tableNode); } foreach ($table->getIndices() as $index) { $this->appendIndexNode($index, $tableNode); } foreach ($table->getUnices() as $index) { $this->appendUniqueIndexNode($index, $tableNode); } foreach ($table->getVendorInformation() as $vendorInformation) { $this->appendVendorInformationNode($vendorInformation, $tableNode); } foreach ($table->getBehaviors() as $behavior) { $this->appendBehaviorNode($behavior, $tableNode); } }