public function getPrimaryKeyDDL(Table $table) { if ($table->hasPrimaryKey()) { $pattern = 'CONSTRAINT %s PRIMARY KEY (%s)'; return sprintf($pattern, $this->quoteIdentifier($this->getPrimaryKeyName($table)), $this->getColumnListDDL($table->getPrimaryKey())); } }
public function testTable() { $b = new Behavior(); $this->assertNull($b->getTable(), 'Behavior Table is null by default'); $t = new Table(); $t->setCommonName('fooTable'); $b->setTable($t); $this->assertEquals($b->getTable(), $t, 'setTable() sets the name, and getTable() gets it'); }
/** * Adds a unique constraint to the table to enforce uniqueness of the slug_column * * @param Table $table */ protected function addUniqueConstraint(Table $table) { $unique = new Unique($this->getColumnForParameter('slug_column')); $unique->setName($table->getCommonName() . '_slug'); $unique->addColumn($table->getColumn($this->getParameter('slug_column'))); if ($this->getParameter('scope_column')) { $unique->addColumn($table->getColumn($this->getParameter('scope_column'))); } $table->addUnique($unique); }
public function testTableNamespaceAndDbNamespace() { $d = new Database('fooDb'); $d->setNamespace('Baz'); $t = new Table('fooTable'); $t->setNamespace('Foo\\Bar'); $d->addTable($t); $builder = new TestableOMBuilder2($t); $this->assertEquals('Baz\\Foo\\Bar', $builder->getNamespace(), 'Builder namespace is composed from the database and table namespaces when both are set'); }
/** * @return void */ protected function _before() { $config = new QuickGeneratorConfig(); $table = new Table('Foo'); $column = new Column('testColumn', PropelTypes::INTEGER); $table->addColumn($column); $table->setNamespace('Unit\\Spryker\\Zed\\Propel\\Business\\Builder\\QueryBuilder'); $table->setDatabase(new Database('TestDB', new DefaultPlatform())); foreach ($this->getFilesToGenerate() as $fileName => $builderClass) { $builder = new $builderClass($table); $builder->setGeneratorConfig($config); $this->writePropelFile($builder, $fileName); } }
/** * Returns whether or not this column has a platform adapter. * * @return boolean */ public function hasPlatform() { if (null === $this->parentTable) { return false; } return $this->parentTable->getPlatform() ? true : false; }
protected function addFixLevels(&$script) { $objectClassName = $this->objectClassName; $queryClassName = $this->queryClassName; $tableMapClassName = $this->tableMapClassName; $useScope = $this->behavior->useScope(); $script .= "\n/**\n * Update the tree to allow insertion of a leaf at the specified position\n *"; if ($useScope) { $script .= "\n * @param integer \$scope scope column value"; } $script .= "\n * @param ConnectionInterface \$con Connection to use.\n */\nstatic public function fixLevels(" . ($useScope ? "\$scope, " : "") . "ConnectionInterface \$con = null)\n{\n \$c = new Criteria();"; if ($useScope) { $script .= "\n \$c->add({$objectClassName}::SCOPE_COL, \$scope, Criteria::EQUAL);"; } $script .= "\n \$c->addAscendingOrderByColumn({$objectClassName}::LEFT_COL);\n \$dataFetcher = {$queryClassName}::create(null, \$c)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find(\$con);\n "; if (!$this->table->getChildrenColumn()) { $script .= "\n // set the class once to avoid overhead in the loop\n \$cls = {$tableMapClassName}::getOMClass(false);"; } $script .= "\n \$level = null;\n // iterate over the statement\n while (\$row = \$dataFetcher->fetch()) {\n\n // hydrate object\n \$key = {$tableMapClassName}::getPrimaryKeyHashFromRow(\$row, 0);\n /** @var \$obj {$objectClassName} */\n if (null === (\$obj = {$tableMapClassName}::getInstanceFromPool(\$key))) {"; if ($this->table->getChildrenColumn()) { $script .= "\n // class must be set each time from the record row\n \$cls = {$tableMapClassName}::getOMClass(\$row, 0);\n \$cls = substr('.'.\$cls, strrpos('.'.\$cls, '.') + 1);\n " . $this->builder->buildObjectInstanceCreationCode('$obj', '$cls') . "\n \$obj->hydrate(\$row);\n {$tableMapClassName}::addInstanceToPool(\$obj, \$key);"; } else { $script .= "\n " . $this->builder->buildObjectInstanceCreationCode('$obj', '$cls') . "\n \$obj->hydrate(\$row);\n {$tableMapClassName}::addInstanceToPool(\$obj, \$key);"; } $script .= "\n }\n\n // compute level\n // Algorithm shamelessly stolen from sfPropelActAsNestedSetBehaviorPlugin\n // Probably authored by Tristan Rivoallan\n if (\$level === null) {\n \$level = 0;\n \$i = 0;\n \$prev = array(\$obj->getRightValue());\n } else {\n while (\$obj->getRightValue() > \$prev[\$i]) {\n \$i--;\n }\n \$level = ++\$i;\n \$prev[\$i] = \$obj->getRightValue();\n }\n\n // update level in node if necessary\n if (\$obj->getLevel() !== \$level) {\n \$obj->setLevel(\$level);\n \$obj->save(\$con);\n }\n }\n \$dataFetcher->close();\n}\n"; }
/** * Build the fields in the FormType. * * @param Table $table Table from which the fields will be extracted. * * @return string The FormType code. */ protected function buildFormFields(Table $table) { $buildCode = ''; foreach ($table->getColumns() as $column) { if ($column->isPrimaryKey()) { continue; } $name = $column->getPhpName(); // Use foreignKey table name, so the TypeGuesser gets it right if ($column->isForeignKey()) { /** @var ForeignKey $foreignKey */ $foreignKey = current($column->getForeignKeys()); $name = $foreignKey->getForeignTable()->getPhpName(); } $buildCode .= sprintf("\n \$builder->add('%s');", lcfirst($name)); } return $buildCode; }
/** * Returns the list of other foreign keys starting on the same table. * Used in many-to-many relationships. * * @return ForeignKey[] */ public function getOtherFks() { $fks = []; foreach ($this->parentTable->getForeignKeys() as $fk) { if ($fk !== $this) { $fks[] = $fk; } } return $fks; }
public function objectAttributes(ObjectBuilder $builder) { $tableName = $this->table->getName(); $objectClassName = $builder->getObjectClassName(); $script = "\n/**\n * Queries to be executed in the save transaction\n * @var array\n */\nprotected \$nestedSetQueries = array();\n\n/**\n * Internal cache for children nodes\n * @var null|ObjectCollection\n */\nprotected \$collNestedSetChildren = null;\n\n/**\n * Internal cache for parent node\n * @var null|{$objectClassName}\n */\nprotected \$aNestedSetParent = null;\n\n/**\n * Left column for the set\n */\nconst LEFT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('left_column') . "';\n\n/**\n * Right column for the set\n */\nconst RIGHT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('right_column') . "';\n\n/**\n * Level column for the set\n */\nconst LEVEL_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('level_column') . "';\n"; if ($this->behavior->useScope()) { $script .= "\n/**\n * Scope column for the set\n */\nconst SCOPE_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('scope_column') . "';\n"; } return $script; }
/** * Convenience method to returns the Platform class for this table (database). * @return PlatformInterface */ public function getPlatform() { if (null === $this->platform) { // try to load the platform from the table $table = $this->getTable(); if ($table && ($database = $table->getDatabase())) { $this->setPlatform($database->getPlatform()); } } if (!$this->table->isIdentifierQuotingEnabled()) { $this->platform->setIdentifierQuoting(false); } return $this->platform; }
public function endElement($parser, $name) { if ('index' === $name) { $this->currTable->addIndex($this->currIndex); } else { if ('unique' === $name) { $this->currTable->addUnique($this->currUnique); } } if (self::DEBUG) { print 'endElement(' . $name . ") called\n"; } $this->popCurrentSchemaTag(); }
protected function validateTableColumns(Table $table) { if (!$table->hasPrimaryKey() && !$table->isSkipSql()) { $this->errors[] = sprintf('Table "%s" does not have a primary key defined. Propel requires all tables to have a primary key.', $table->getName()); } $phpNames = []; foreach ($table->getColumns() as $column) { if (in_array($column->getPhpName(), $phpNames)) { $this->errors[] = sprintf('Column "%s" declares a phpName already used in table "%s"', $column->getName(), $table->getName()); } $phpNames[] = $column->getPhpName(); } }
public function getAddTableDDL(Table $table) { $tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : ''; $lines = array(); foreach ($table->getColumns() as $column) { $lines[] = $this->getColumnDDL($column); } if ($table->hasPrimaryKey() && count($table->getPrimaryKey()) > 1) { $lines[] = $this->getPrimaryKeyDDL($table); } foreach ($table->getUnices() as $unique) { $lines[] = $this->getUniqueDDL($unique); } $sep = ",\n "; $pattern = "\n%sCREATE TABLE %s\n(\n %s\n);\n"; return sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines)); }
/** * Adds the switch-statement for looking up the array-key name for toArray * @see toArray */ protected function addToArrayKeyLookUp($phpName, Table $table, $plural) { if ($phpName == "") { $phpName = $table->getPhpName(); } $camelCaseName = $table->getCamelCaseName(); $fieldName = $table->getName(); if ($plural) { $phpName = $this->getPluralizer()->getPluralForm($phpName); $camelCaseName = $this->getPluralizer()->getPluralForm($camelCaseName); $fieldName = $this->getPluralizer()->getPluralForm($fieldName); } return "\n switch (\$keyType) {\n case TableMap::TYPE_CAMELNAME:\n \$key = '" . $camelCaseName . "';\n break;\n case TableMap::TYPE_FIELDNAME:\n \$key = '" . $fieldName . "';\n break;\n default:\n \$key = '" . $phpName . "';\n }\n "; }
public function testGetPrimaryKeyDDLCompositeKey() { $table = new Table('foo'); $column1 = new Column('bar1'); $column1->setPrimaryKey(true); $table->addColumn($column1); $column2 = new Column('bar2'); $column2->setPrimaryKey(true); $table->addColumn($column2); $expected = 'PRIMARY KEY ([bar1],[bar2])'; $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table)); }
/** * Builds the DDL SQL to drop the primary key of a table. * * @param Table $table * @return string */ public function getDropPrimaryKeyDDL(Table $table) { if (!$table->hasPrimaryKey()) { return ''; } $pattern = "\nALTER TABLE %s DROP PRIMARY KEY;\n"; return sprintf($pattern, $this->quoteIdentifier($table->getName())); }
/** * Computes the table namespace based on the current relative or * absolute table namespace and the database namespace. * * @param Table $table * @return string */ private function computeTableNamespace(Table $table) { $namespace = $table->getNamespace(); if ($this->isAbsoluteNamespace($namespace)) { $namespace = ltrim($namespace, '\\'); $table->setNamespace($namespace); return $namespace; } if ($namespace = $this->getNamespace()) { if ($table->getNamespace()) { $namespace .= '\\' . $table->getNamespace(); } $table->setNamespace($namespace); } return $namespace; }
public function testCompareSeveralRenamedSameColumns() { $t1 = new Table(); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $t1->addColumn($c1); $c2 = new Column('col2'); $c2->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c2->getDomain()->replaceSize(255); $t1->addColumn($c2); $c3 = new Column('col3'); $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c3->getDomain()->replaceSize(255); $t1->addColumn($c3); $t2 = new Table(); $c4 = new Column('col4'); $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c4->getDomain()->replaceSize(255); $t2->addColumn($c4); $c5 = new Column('col5'); $c5->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c5->getDomain()->replaceSize(255); $t2->addColumn($c5); $c6 = new Column('col3'); $c6->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c6->getDomain()->replaceSize(255); $t2->addColumn($c6); // col1 and col2 were renamed $tc = new TableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->compareColumns(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(2, $nbDiffs); $this->assertEquals([[$c1, $c4], [$c2, $c5]], $tableDiff->getRenamedColumns()); $this->assertEquals([], $tableDiff->getAddedColumns()); $this->assertEquals([], $tableDiff->getRemovedColumns()); $this->assertEquals([], $tableDiff->getModifiedColumns()); }
/** * Returns the string representation of this object. * * @return string */ public function __toString() { $ret = ''; $ret .= sprintf(" %s:\n", $this->fromTable->getName()); if ($addedColumns = $this->getAddedColumns()) { $ret .= " addedColumns:\n"; foreach ($addedColumns as $colname => $column) { $ret .= sprintf(" - %s\n", $colname); } } if ($removedColumns = $this->getRemovedColumns()) { $ret .= " removedColumns:\n"; foreach ($removedColumns as $colname => $column) { $ret .= sprintf(" - %s\n", $colname); } } if ($modifiedColumns = $this->getModifiedColumns()) { $ret .= " modifiedColumns:\n"; foreach ($modifiedColumns as $colDiff) { $ret .= $colDiff->__toString(); } } if ($renamedColumns = $this->getRenamedColumns()) { $ret .= " renamedColumns:\n"; foreach ($renamedColumns as $columnRenaming) { list($fromColumn, $toColumn) = $columnRenaming; $ret .= sprintf(" %s: %s\n", $fromColumn->getName(), $toColumn->getName()); } } if ($addedIndices = $this->getAddedIndices()) { $ret .= " addedIndices:\n"; foreach ($addedIndices as $indexName => $index) { $ret .= sprintf(" - %s\n", $indexName); } } if ($removedIndices = $this->getRemovedIndices()) { $ret .= " removedIndices:\n"; foreach ($removedIndices as $indexName => $index) { $ret .= sprintf(" - %s\n", $indexName); } } if ($modifiedIndices = $this->getModifiedIndices()) { $ret .= " modifiedIndices:\n"; foreach ($modifiedIndices as $indexName => $indexDiff) { $ret .= sprintf(" - %s\n", $indexName); } } if ($addedFks = $this->getAddedFks()) { $ret .= " addedFks:\n"; foreach ($addedFks as $fkName => $fk) { $ret .= sprintf(" - %s\n", $fkName); } } if ($removedFks = $this->getRemovedFks()) { $ret .= " removedFks:\n"; foreach ($removedFks as $fkName => $fk) { $ret .= sprintf(" - %s\n", $fkName); } } if ($modifiedFks = $this->getModifiedFks()) { $ret .= " modifiedFks:\n"; foreach ($modifiedFks as $fkName => $fkFromTo) { $ret .= sprintf(" %s:\n", $fkName); list($fromFk, $toFk) = $fkFromTo; $fromLocalColumns = json_encode($fromFk->getLocalColumns()); $toLocalColumns = json_encode($toFk->getLocalColumns()); if ($fromLocalColumns != $toLocalColumns) { $ret .= sprintf(" localColumns: from %s to %s\n", $fromLocalColumns, $toLocalColumns); } $fromForeignColumns = json_encode($fromFk->getForeignColumns()); $toForeignColumns = json_encode($toFk->getForeignColumns()); if ($fromForeignColumns != $toForeignColumns) { $ret .= sprintf(" foreignColumns: from %s to %s\n", $fromForeignColumns, $toForeignColumns); } if ($fromFk->normalizeFKey($fromFk->getOnUpdate()) != $toFk->normalizeFKey($toFk->getOnUpdate())) { $ret .= sprintf(" onUpdate: from %s to %s\n", $fromFk->getOnUpdate(), $toFk->getOnUpdate()); } if ($fromFk->normalizeFKey($fromFk->getOnDelete()) != $toFk->normalizeFKey($toFk->getOnDelete())) { $ret .= sprintf(" onDelete: from %s to %s\n", $fromFk->getOnDelete(), $toFk->getOnDelete()); } } } return $ret; }
public function testCompareSeveralColumnDifferences() { $t1 = new Table(); $c1 = new Column('col1'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $c1->setNotNull(false); $t1->addColumn($c1); $c2 = new Column('col2'); $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c2->setNotNull(true); $t1->addColumn($c2); $c3 = new Column('col3'); $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c3->getDomain()->replaceSize(255); $t1->addColumn($c3); $t2 = new Table(); $c4 = new Column('col1'); $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c4->getDomain()->replaceScale(2); $c4->getDomain()->replaceSize(3); $c4->setNotNull(true); $c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c4); $c5 = new Column('col22'); $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER')); $c5->setNotNull(true); $t2->addColumn($c5); $c6 = new Column('col4'); $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR')); $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c6); // col1 was modified, col2 was renamed, col3 was removed, col4 was added $tc = new PropelTableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->compareColumns(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(4, $nbDiffs); $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns()); $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns()); $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns()); $columnDiff = PropelColumnComparator::computeDiff($c1, $c4); $this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns()); }
/** * Returns the SQL for the primary key of a Table object * @return string */ public function getPrimaryKeyDDL(Table $table) { if ($table->hasPrimaryKey() && !$table->hasAutoIncrementPrimaryKey()) { return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')'; } return ''; }
/** * Generate oracle block storage * * @param Table|Index $object object with vendor parameters * @param boolean $isPrimaryKey is a primary key vendor part * * @return string oracle vendor sql part */ public function generateBlockStorage($object, $isPrimaryKey = false) { $vendorSpecific = $object->getVendorInfoForType('oracle'); if ($vendorSpecific->isEmpty()) { return ''; } if ($isPrimaryKey) { $physicalParameters = "\nUSING INDEX\n"; $prefix = "PK"; } else { $physicalParameters = "\n"; $prefix = ""; } if ($vendorSpecific->hasParameter($prefix . 'PCTFree')) { $physicalParameters .= "PCTFREE " . $vendorSpecific->getParameter($prefix . 'PCTFree') . "\n"; } if ($vendorSpecific->hasParameter($prefix . 'InitTrans')) { $physicalParameters .= "INITRANS " . $vendorSpecific->getParameter($prefix . 'InitTrans') . "\n"; } if ($vendorSpecific->hasParameter($prefix . 'MinExtents') || $vendorSpecific->hasParameter($prefix . 'MaxExtents') || $vendorSpecific->hasParameter($prefix . 'PCTIncrease')) { $physicalParameters .= "STORAGE\n(\n"; if ($vendorSpecific->hasParameter($prefix . 'MinExtents')) { $physicalParameters .= " MINEXTENTS " . $vendorSpecific->getParameter($prefix . 'MinExtents') . "\n"; } if ($vendorSpecific->hasParameter($prefix . 'MaxExtents')) { $physicalParameters .= " MAXEXTENTS " . $vendorSpecific->getParameter($prefix . 'MaxExtents') . "\n"; } if ($vendorSpecific->hasParameter($prefix . 'PCTIncrease')) { $physicalParameters .= " PCTINCREASE " . $vendorSpecific->getParameter($prefix . 'PCTIncrease') . "\n"; } $physicalParameters .= ")\n"; } if ($vendorSpecific->hasParameter($prefix . 'Tablespace')) { $physicalParameters .= "TABLESPACE " . $vendorSpecific->getParameter($prefix . 'Tablespace'); } return $physicalParameters; }
/** * Adds a useRelatedQuery method for this object. * @param string &$script The script will be modified in this method. */ protected function addUseRelatedQuery(&$script, Table $fkTable, $queryClass, $relationName, $joinType) { $script .= "\n /**\n * Use the {$relationName} relation " . $fkTable->getPhpName() . " object\n *\n * @see useQuery()\n *\n * @param string \$relationAlias optional alias for the relation,\n * to be used as main alias in the secondary query\n * @param string \$joinType Accepted values are null, 'left join', 'right join', 'inner join'\n *\n * @return {$queryClass} A secondary query class using the current class as primary query\n */\n public function use" . $relationName . "Query(\$relationAlias = null, \$joinType = " . $joinType . ")\n {\n return \$this\n ->join" . $relationName . "(\$relationAlias, \$joinType)\n ->useQuery(\$relationAlias ? \$relationAlias : '{$relationName}', '{$queryClass}');\n }\n"; }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query("PRAGMA index_list('" . $table->getName() . "')"); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $name = $row['name']; $index = new Index($name); $stmt2 = $this->dbh->query("PRAGMA index_info('" . $name . "')"); while ($row2 = $stmt2->fetch(\PDO::FETCH_ASSOC)) { $colname = $row2['name']; $index->addColumn($table->getColumn($colname)); } $table->addIndex($index); } }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query('PRAGMA index_list("' . $table->getName() . '")'); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $name = $row['name']; $internalName = $name; if (0 === strpos($name, 'sqlite_autoindex')) { $internalName = ''; } $index = $row['unique'] ? new Unique($internalName) : new Index($internalName); $stmt2 = $this->dbh->query("PRAGMA index_info('" . $name . "')"); while ($row2 = $stmt2->fetch(\PDO::FETCH_ASSOC)) { $colname = $row2['name']; $index->addColumn($table->getColumn($colname)); } if (1 === count($table->getPrimaryKey()) && 1 === count($index->getColumns())) { // exclude the primary unique index, since it's autogenerated by sqlite if ($table->getPrimaryKey()[0]->getName() === $index->getColumns()[0]) { continue; } } if ($index instanceof Unique) { $table->addUnique($index); } else { $table->addIndex($index); } } }
/** * Loads the primary key for this table. * * @param Table $table The Table model class to add PK to. */ protected function addPrimaryKey(Table $table) { $stmt = $this->dbh->query("SELECT COLS.COLUMN_NAME FROM USER_CONSTRAINTS CONS, USER_CONS_COLUMNS COLS WHERE CONS.CONSTRAINT_NAME = COLS.CONSTRAINT_NAME AND CONS.TABLE_NAME = '" . $table->getName() . "' AND CONS.CONSTRAINT_TYPE = 'P'"); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { // This fixes a strange behavior by PDO. Sometimes the // row values are inside an index 0 of an array if (isset($row[0])) { $row = $row[0]; } $table->getColumn($row['COLUMN_NAME'])->setPrimaryKey(true); } }
/** * Loads the primary key for this table. */ protected function addPrimaryKey(Table $table) { $dataFetcher = $this->dbh->query("SELECT COLUMN_NAME\n FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS\n INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ON\n INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.constraint_name\n WHERE (INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'PRIMARY KEY') AND\n (INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME = '" . $table->getName() . "')"); // Loop through the returned results, grouping the same key_name together // adding each column for that key. foreach ($dataFetcher as $row) { $name = $this->cleanDelimitedIdentifiers($row[0]); $table->getColumn($name)->setPrimaryKey(true); } }
public function providerForTestGetModifyColumnRemoveDefaultValueDDL() { $t1 = new Table('test'); $t1->setIdentifierQuoting(true); $c1 = new Column(); $c1->setName('test'); $c1->getDomain()->setType('INTEGER'); $c1->setDefaultValue(0); $t1->addColumn($c1); $t2 = new Table('test'); $t2->setIdentifierQuoting(true); $c2 = new Column(); $c2->setName('test'); $c2->getDomain()->setType('INTEGER'); $t2->addColumn($c2); return [[ColumnComparator::computeDiff($c1, $c2)]]; }
public function testSetForReferenceOnly() { $table = new Table('books'); $table->setForReferenceOnly(true); $this->assertTrue($table->isForReferenceOnly()); }