当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::addUnique方法代码示例

本文整理汇总了PHP中Propel\Generator\Model\Table::addUnique方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addUnique方法的具体用法?PHP Table::addUnique怎么用?PHP Table::addUnique使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propel\Generator\Model\Table的用法示例。


在下文中一共展示了Table::addUnique方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addUniqueConstraint

 /**
  * 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);
 }
开发者ID:SwissalpS,项目名称:Propel2,代码行数:15,代码来源:SluggableBehavior.php

示例2: endElement

 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();
 }
开发者ID:malukenho,项目名称:Propel2,代码行数:14,代码来源:SchemaReader.php

示例3: normalizeTable

 /**
  * Unfortunately, SQLite does not support composite pks where one is AUTOINCREMENT,
  * so we have to flag both as NOT NULL and create a UNIQUE constraint.
  *
  * @param Table $table
  */
 public function normalizeTable(Table $table)
 {
     if (count($pks = $table->getPrimaryKey()) > 1 && $table->hasAutoIncrementPrimaryKey()) {
         foreach ($pks as $pk) {
             //no pk can be NULL, as usual
             $pk->setNotNull(true);
             //in SQLite the column with the AUTOINCREMENT MUST be a primary key, too.
             if (!$pk->isAutoIncrement()) {
                 //for all other sub keys we remove it, since we create a UNIQUE constraint over all primary keys.
                 $pk->setPrimaryKey(false);
             }
         }
         //search if there is already a UNIQUE constraint over the primary keys
         $pkUniqueExist = false;
         foreach ($table->getUnices() as $unique) {
             $allPk = false;
             foreach ($unique->getColumns() as $columnName) {
                 $allPk &= $table->getColumn($columnName)->isPrimaryKey();
             }
             if ($allPk) {
                 //there's already a unique constraint with the composite pk
                 $pkUniqueExist = true;
                 break;
             }
         }
         //there is none, let's create it
         if (!$pkUniqueExist) {
             $unique = new Unique();
             foreach ($pks as $pk) {
                 $unique->addColumn($pk);
             }
             $table->addUnique($unique);
         }
     }
     parent::normalizeTable($table);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:42,代码来源:SqlitePlatform.php

示例4: addIndexes

 /**
  * 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);
         }
     }
 }
开发者ID:KyleGoslan,项目名称:Huge-Propel,代码行数:31,代码来源:SqliteSchemaParser.php

示例5: testAddArrayUnique

 public function testAddArrayUnique()
 {
     $table = new Table();
     $table->addUnique(array('name' => 'author_unq'));
     $this->assertCount(1, $table->getUnices());
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:6,代码来源:TableTest.php

示例6: Table

$sluggableBehavior->setName('sluggable');
/* Tables */
$table1 = new Table('blog_post');
$table1->setDescription('The list of posts');
$table1->setNamespace('Blog');
$table1->setPackage('Acme.Blog');
$table1->addColumns([$column11, $column12, $column13, $column14, $column15, $column16, $column17]);
$table1->addForeignKeys([$fkAuthorPost, $fkCategoryPost]);
$table1->addBehavior($timestampableBehavior);
$table1->addBehavior($sluggableBehavior);
$table2 = new Table('blog_author');
$table2->setDescription('The list of authors');
$table2->setNamespace('Blog');
$table2->setPackage('Acme.Blog');
$table2->addColumns([$column21, $column22, $column23]);
$table2->addUnique($authorUsernameUnique);
$table3 = new Table('blog_category');
$table3->setDescription('The list of categories');
$table3->setNamespace('Blog');
$table3->setPackage('Acme.Blog');
$table3->addColumns([$column31, $column32]);
$table4 = new Table('blog_tag');
$table4->setDescription('The list of tags');
$table4->setNamespace('Blog');
$table4->setPackage('Acme.Blog');
$table4->addColumns([$column41, $column42]);
$table5 = new Table('blog_post_tag');
$table5->setNamespace('Blog');
$table5->setPackage('Acme.Blog');
$table5->setCrossRef();
$table5->addColumns([$column51, $column52]);
开发者ID:disider,项目名称:Propel2,代码行数:31,代码来源:blog-database.php

示例7: providerForTestGetUniqueDDL

 public function providerForTestGetUniqueDDL()
 {
     $table = new Table('foo');
     $table->setIdentifierQuoting(true);
     $column1 = new Column('bar1');
     $column1->getDomain()->copy(new Domain('FOOTYPE'));
     $table->addColumn($column1);
     $column2 = new Column('bar2');
     $column2->getDomain()->copy(new Domain('BARTYPE'));
     $table->addColumn($column2);
     $index = new Unique('babar');
     $index->addColumn($column1);
     $index->addColumn($column2);
     $table->addUnique($index);
     return array(array($index));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:16,代码来源:PlatformTestProvider.php

示例8: addIndexes

 /**
  * Load indexes for this table
  */
 protected function addIndexes(Table $table, $oid)
 {
     $stmt = $this->dbh->prepare("SELECT\n            DISTINCT ON(cls.relname)\n            cls.relname as idxname,\n            indkey,\n            indisunique\n            FROM pg_index idx\n            JOIN pg_class cls ON cls.oid=indexrelid\n            WHERE indrelid = ? AND NOT indisprimary\n            ORDER BY cls.relname");
     $stmt->bindValue(1, $oid);
     $stmt->execute();
     $stmt2 = $this->dbh->prepare("SELECT a.attname\n            FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid\n            WHERE c.oid = ? AND a.attnum = ? AND NOT a.attisdropped\n            ORDER BY a.attnum");
     $indexes = array();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $name = $row['idxname'];
         $unique = in_array($row['indisunique'], ['t', true, 1, '1']) ? true : false;
         if (!isset($indexes[$name])) {
             if ($unique) {
                 $indexes[$name] = new Unique($name);
             } else {
                 $indexes[$name] = new Index($name);
             }
         }
         $arrColumns = explode(' ', $row['indkey']);
         foreach ($arrColumns as $intColNum) {
             $stmt2->bindValue(1, $oid);
             $stmt2->bindValue(2, $intColNum);
             $stmt2->execute();
             $row2 = $stmt2->fetch(\PDO::FETCH_ASSOC);
             $indexes[$name]->addColumn($table->getColumn($row2['attname']));
         }
     }
     foreach ($indexes as $index) {
         if ($index instanceof Unique) {
             $table->addUnique($index);
         } else {
             $table->addIndex($index);
         }
     }
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:37,代码来源:PgsqlSchemaParser.php

示例9: addIndexes

 /**
  * Load indexes for this table
  */
 protected function addIndexes(Table $table)
 {
     $stmt = $this->dbh->query(sprintf('SHOW INDEX FROM %s', $this->getPlatform()->quoteIdentifier($table->getName())));
     // Loop through the returned results, grouping the same key_name together
     // adding each column for that key.
     /** @var $indexes Index[] */
     $indexes = array();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $colName = $row['Column_name'];
         $colSize = $row['Sub_part'];
         $name = $row['Key_name'];
         if ('PRIMARY' === $name) {
             continue;
         }
         if (!isset($indexes[$name])) {
             $isUnique = 0 == $row['Non_unique'];
             if ($isUnique) {
                 $indexes[$name] = new Unique($name);
             } else {
                 $indexes[$name] = new Index($name);
             }
             if ($this->addVendorInfo) {
                 $vi = $this->getNewVendorInfoObject($row);
                 $indexes[$name]->addVendorInfo($vi);
             }
         }
         $indexes[$name]->addColumn(['name' => $colName, 'size' => $colSize]);
     }
     foreach ($indexes as $index) {
         if ($index instanceof Unique) {
             $table->addUnique($index);
         } else {
             $table->addIndex($index);
         }
     }
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:39,代码来源:MysqlSchemaParser.php


注:本文中的Propel\Generator\Model\Table::addUnique方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。