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


PHP Table::getDatabase方法代码示例

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


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

示例1: createName

 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);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:9,代码来源:Index.php

示例2: hasCompositeNumberRangeBehavior

 /**
  * @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;
 }
开发者ID:apinnecke,项目名称:composite-number-range-behavior,代码行数:22,代码来源:MysqlPlatform.php

示例3: addForeignKeys

 /**
  * 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);
     }
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:28,代码来源:MssqlSchemaParser.php

示例4: getDatabase

 /**
  * Returns the database object the current column is in.
  *
  * @return Database
  */
 private function getDatabase()
 {
     return $this->parentTable->getDatabase();
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:9,代码来源:Column.php

示例5: addForeignKeys

 /**
  * 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]));
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:78,代码来源:PgsqlSchemaParser.php

示例6: getForeignTable

 /**
  * Returns the resolved foreign Table model object.
  *
  * @return Table
  */
 public function getForeignTable()
 {
     if ($database = $this->parentTable->getDatabase()) {
         return $database->getTable($this->getForeignTableName());
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:11,代码来源:ForeignKey.php

示例7: computeDiff

 /**
  * 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;
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:27,代码来源:TableComparator.php

示例8: setupObject

 /**
  * 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());
//.........这里部分代码省略.........
开发者ID:rouffj,项目名称:Propel2,代码行数:101,代码来源:Column.php

示例9: addParentColumn

 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;
 }
开发者ID:scif,项目名称:propel-closuretable-behavior,代码行数:15,代码来源:ClosureTableBehavior.php

示例10: getConfiguredBuilder

 /**
  * 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;
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:18,代码来源:GeneratorConfig.php

示例11: addForeignKeys

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

示例12: addForeignKeys

 /**
  * 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]);
             }
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:79,代码来源:MysqlSchemaParser.php

示例13: addForeignKeys

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

示例14: addForeignKeys

 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']);
     }
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:25,代码来源:SqliteSchemaParser.php

示例15: addForeignKeys

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


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