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


PHP Table::getPrimaryKey方法代码示例

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


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

示例1: getPrimaryKeyDDL

 /**
  * Returns the SQL for the primary key of a Table object.
  *
  * @return string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey() && 1 < count($table->getPrimaryKey())) {
         if ($table->hasAutoIncrementPrimaryKey()) {
             return 'UNIQUE (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
         }
         return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
     }
 }
开发者ID:robin850,项目名称:Propel2,代码行数:14,代码来源:SqlitePlatform.php

示例2: isLocalPrimaryKey

 /**
  * Returns whether or not this foreign key is also the primary key of
  * the local table.
  *
  * @return boolean True if all local columns are at the same time a primary key
  */
 public function isLocalPrimaryKey()
 {
     $localPKCols = [];
     foreach ($this->parentTable->getPrimaryKey() as $lPKCol) {
         $localPKCols[] = $lPKCol->getName();
     }
     return count($localPKCols) === count($this->localColumns) && !array_diff($localPKCols, $this->localColumns);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:14,代码来源:ForeignKey.php

示例3: getAddTableDDL

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

示例4: addUpdateLoadedNodes

 protected function addUpdateLoadedNodes(&$script)
 {
     $queryClassName = $this->queryClassName;
     $objectClassName = $this->objectClassName;
     $tableMapClassName = $this->tableMapClassName;
     $script .= "\n/**\n * Reload all already loaded nodes to sync them with updated db\n *\n * @param      {$objectClassName} \$prune        Object to prune from the update\n * @param      ConnectionInterface \$con        Connection to use.\n */\nstatic public function updateLoadedNodes(\$prune = null, ConnectionInterface \$con = null)\n{\n    if (Propel::isInstancePoolingEnabled()) {\n        \$keys = array();\n        /** @var \$obj {$objectClassName} */\n        foreach ({$tableMapClassName}::\$instances as \$obj) {\n            if (!\$prune || !\$prune->equals(\$obj)) {\n                \$keys[] = \$obj->getPrimaryKey();\n            }\n        }\n\n        if (!empty(\$keys)) {\n            // We don't need to alter the object instance pool; we're just modifying these ones\n            // already in the pool.\n            \$criteria = new Criteria({$tableMapClassName}::DATABASE_NAME);";
     if (1 === count($this->table->getPrimaryKey())) {
         $pkey = $this->table->getPrimaryKey();
         $col = array_shift($pkey);
         $script .= "\n            \$criteria->add(" . $this->builder->getColumnConstant($col) . ", \$keys, Criteria::IN);";
     } else {
         $fields = array();
         foreach ($this->table->getPrimaryKey() as $k => $col) {
             $fields[] = $this->builder->getColumnConstant($col);
         }
         $script .= "\n\n            // Loop on each instances in pool\n            foreach (\$keys as \$values) {\n              // Create initial Criterion\n                \$cton = \$criteria->getNewCriterion(" . $fields[0] . ", \$values[0]);";
         unset($fields[0]);
         foreach ($fields as $k => $col) {
             $script .= "\n\n                // Create next criterion\n                \$nextcton = \$criteria->getNewCriterion(" . $col . ", \$values[{$k}]);\n                // And merge it with the first\n                \$cton->addAnd(\$nextcton);";
         }
         $script .= "\n\n                // Add final Criterion to Criteria\n                \$criteria->addOr(\$cton);\n            }";
     }
     $script .= "\n            \$dataFetcher = {$queryClassName}::create(null, \$criteria)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find(\$con);\n            while (\$row = \$dataFetcher->fetch()) {\n                \$key = {$tableMapClassName}::getPrimaryKeyHashFromRow(\$row, 0);\n                /** @var \$object {$objectClassName} */\n                if (null !== (\$object = {$tableMapClassName}::getInstanceFromPool(\$key))) {";
     $n = 0;
     foreach ($this->table->getColumns() as $col) {
         if ($col->isLazyLoad()) {
             continue;
         }
         if ($col->getPhpName() == $this->getColumnPhpName('left_column')) {
             $script .= "\n                    \$object->setLeftValue(\$row[{$n}]);";
         } elseif ($col->getPhpName() == $this->getColumnPhpName('right_column')) {
             $script .= "\n                    \$object->setRightValue(\$row[{$n}]);";
         } elseif ($this->getParameter('use_scope') == 'true' && $col->getPhpName() == $this->getColumnPhpName('scope_column')) {
             $script .= "\n                    \$object->setScopeValue(\$row[{$n}]);";
         } elseif ($col->getPhpName() == $this->getColumnPhpName('level_column')) {
             $script .= "\n                    \$object->setLevel(\$row[{$n}]);\n                    \$object->clearNestedSetChildren();";
         }
         $n++;
     }
     $script .= "\n                }\n            }\n            \$dataFetcher->close();\n        }\n    }\n}\n";
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:41,代码来源:NestedSetBehaviorQueryBuilderModifier.php

示例5: getPrimaryKeyDDL

 /**
  * Returns the SQL for the primary key of a Table object
  *
  * @param Table $table
  *
  * @return string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey()) {
         $keys = $table->getPrimaryKey();
         //MySQL throws an 'Incorrect table definition; there can be only one auto column and it must be defined as a key'
         //if the primary key consists of multiple columns and if the first is not the autoIncrement one. So
         //this push the autoIncrement column to the first position if its not already.
         $autoIncrement = $table->getAutoIncrementPrimaryKey();
         if ($autoIncrement && $keys[0] != $autoIncrement) {
             $idx = array_search($autoIncrement, $keys);
             if ($idx !== false) {
                 unset($keys[$idx]);
                 array_unshift($keys, $autoIncrement);
             }
         }
         return 'PRIMARY KEY (' . $this->getColumnListDDL($keys) . ')';
     }
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:25,代码来源:MysqlPlatform.php

示例6: getAddPrimaryKeyDDL

 public function getAddPrimaryKeyDDL(Table $table)
 {
     if (is_array($table->getPrimaryKey()) && count($table->getPrimaryKey())) {
         return parent::getAddPrimaryKeyDDL($table);
     }
 }
开发者ID:smoqs,项目名称:Propel2,代码行数:6,代码来源:OraclePlatform.php

示例7: 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

示例8: testGetAutoIncrementPrimaryKey

 public function testGetAutoIncrementPrimaryKey()
 {
     $column1 = $this->getColumnMock('id', array('primary' => true, 'auto_increment' => true));
     $column2 = $this->getColumnMock('title');
     $column3 = $this->getColumnMock('isbn');
     $table = new Table();
     $table->setIdMethod('native');
     $table->addColumn($column1);
     $table->addColumn($column2);
     $table->addColumn($column3);
     $this->assertCount(1, $table->getPrimaryKey());
     $this->assertTrue($table->hasPrimaryKey());
     $this->assertTrue($table->hasAutoIncrementPrimaryKey());
     $this->assertSame($column1, $table->getAutoIncrementPrimaryKey());
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:15,代码来源:TableTest.php

示例9: getPrimaryKeyDDL

 /**
  * Returns the SQL for the primary key of a Table object.
  *
  * @return string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey()) {
         return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:11,代码来源:DefaultPlatform.php


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