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


PHP Model\Database类代码示例

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


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

示例1: parse

 public function parse(Database $database, Task $task = null)
 {
     $dataFetcher = $this->dbh->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'");
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     foreach ($dataFetcher as $row) {
         $name = $this->cleanDelimitedIdentifiers($row[0]);
         if ($name === $this->getMigrationTable()) {
             continue;
         }
         $table = new Table($name);
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     foreach ($tables as $table) {
         $this->addColumns($table);
     }
     // Now add indexes and constraints.
     foreach ($tables as $table) {
         $this->addForeignKeys($table);
         $this->addIndexes($table);
         $this->addPrimaryKey($table);
     }
     return count($tables);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:27,代码来源:MssqlSchemaParser.php

示例2: parseTables

 protected function parseTables(Database $database, $filterTable = null)
 {
     $sql = 'SHOW FULL TABLES';
     if ($filterTable) {
         if ($schema = $filterTable->getSchema()) {
             $sql .= ' FROM ' . $database->getPlatform()->doQuoting($schema);
         }
         $sql .= sprintf(" LIKE '%s'", $filterTable->getCommonName());
     } else {
         if ($schema = $database->getSchema()) {
             $sql .= ' FROM ' . $database->getPlatform()->doQuoting($schema);
         }
     }
     $dataFetcher = $this->dbh->query($sql);
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     foreach ($dataFetcher as $row) {
         $name = $row[0];
         $type = $row[1];
         if ($name == $this->getMigrationTable() || $type !== 'BASE TABLE') {
             continue;
         }
         $table = new Table($name);
         $table->setIdMethod($database->getDefaultIdMethod());
         if ($filterTable && $filterTable->getSchema()) {
             $table->setSchema($filterTable->getSchema());
         }
         $database->addTable($table);
         $tables[] = $table;
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:31,代码来源:MysqlSchemaParser.php

示例3: parse

 /**
  *
  */
 public function parse(Database $database)
 {
     $this->addVendorInfo = $this->getGeneratorConfig()->getBuildProperty('addVendorInfo');
     $sql = 'SHOW FULL TABLES';
     if ($schema = $database->getSchema()) {
         $sql .= ' FROM ' . $database->getPlatform()->quoteIdentifier($schema);
     }
     $dataFetcher = $this->dbh->query($sql);
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     foreach ($dataFetcher as $row) {
         $name = $row[0];
         $type = $row[1];
         if ($name == $this->getMigrationTable() || $type !== 'BASE TABLE') {
             continue;
         }
         $table = new Table($name);
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     foreach ($tables as $table) {
         $this->addColumns($table);
     }
     // Now add indices and constraints.
     foreach ($tables as $table) {
         $this->addForeignKeys($table);
         $this->addIndexes($table);
         $this->addPrimaryKey($table);
         $this->addTableVendorInfo($table);
     }
     return count($tables);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:37,代码来源:MysqlSchemaParser.php

示例4: parse

 /**
  *
  */
 public function parse(Database $database)
 {
     $dataFetcher = $this->dbh->query("SELECT name FROM sqlite_master WHERE type='table' UNION ALL SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name;");
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     foreach ($dataFetcher as $row) {
         $name = $row[0];
         if ($name === $this->getMigrationTable()) {
             continue;
         }
         $table = new Table($name);
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     foreach ($tables as $table) {
         $this->addColumns($table);
     }
     // Now add indexes and constraints.
     foreach ($tables as $table) {
         $this->addIndexes($table);
     }
     return count($tables);
 }
开发者ID:robin850,项目名称:Propel2,代码行数:28,代码来源:SqliteSchemaParser.php

示例5: testTableNamespaceAndDbNamespace

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

示例6: validateDatabaseTables

 protected function validateDatabaseTables(Database $database)
 {
     $phpNames = array();
     foreach ($database->getTables() as $table) {
         if (in_array($table->getPhpName(), $phpNames)) {
             $this->errors[] = sprintf('Table "%s" declares a phpName already used in another table', $table->getName());
         }
         $phpNames[] = $table->getPhpName();
         $this->validateTableAttributes($table);
         $this->validateTableColumns($table);
     }
 }
开发者ID:norfil,项目名称:Propel2,代码行数:12,代码来源:SchemaValidator.php

示例7: testParse

 public function testParse()
 {
     $parser = new MysqlSchemaParser(Propel::getConnection('reverse-bookstore'));
     $parser->setGeneratorConfig(new QuickGeneratorConfig());
     $database = new Database();
     $database->setPlatform(new DefaultPlatform());
     $this->assertEquals(1, $parser->parse($database), 'One table and one view defined should return one as we exclude views');
     $tables = $database->getTables();
     $this->assertEquals(1, count($tables));
     $table = $tables[0];
     $this->assertEquals('Book', $table->getPhpName());
     $this->assertEquals(4, count($table->getColumns()));
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:13,代码来源:MysqlSchemaParserTest.php

示例8: parse

 /**
  *
  */
 public function parse(Database $database, Task $task = null)
 {
     $this->addVendorInfo = $this->getGeneratorConfig()->getBuildProperty('addVendorInfo');
     $stmt = $this->dbh->query("SHOW FULL TABLES");
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     if ($task) {
         $task->log("Reverse Engineering Tables", Project::MSG_VERBOSE);
     }
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $name = $row[0];
         $type = $row[1];
         if ($name == $this->getMigrationTable() || $type != "BASE TABLE") {
             continue;
         }
         if ($task) {
             $task->log("  Adding table '" . $name . "'", Project::MSG_VERBOSE);
         }
         $table = new Table($name);
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     if ($task) {
         $task->log("Reverse Engineering Columns", Project::MSG_VERBOSE);
     }
     foreach ($tables as $table) {
         if ($task) {
             $task->log("  Adding columns for table '" . $table->getName() . "'", Project::MSG_VERBOSE);
         }
         $this->addColumns($table);
     }
     // Now add indices and constraints.
     if ($task) {
         $task->log("Reverse Engineering Indices And Constraints", Project::MSG_VERBOSE);
     }
     foreach ($tables as $table) {
         if ($task) {
             $task->log("  Adding indices and constraints for table '" . $table->getName() . "'", Project::MSG_VERBOSE);
         }
         $this->addForeignKeys($table);
         $this->addIndexes($table);
         $this->addPrimaryKey($table);
         if ($this->addVendorInfo) {
             $this->addTableVendorInfo($table);
         }
     }
     return count($tables);
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:53,代码来源:MysqlSchemaParser.php

示例9: updateSchema

 /**
  * Detects the differences between current connected database and $pDatabase
  * and updates the schema. This does not DROP tables.
  *
  * @param Database $pDatabase
  */
 public function updateSchema($pDatabase)
 {
     $diff = DatabaseComparator::computeDiff($this->database, $pDatabase);
     $sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
     $statements = SqlParser::parseString($sql);
     foreach ($statements as $statement) {
         if (strpos($statement, 'DROP') === 0) {
             // drop statements cause errors since the table doesn't exist
             continue;
         }
         $stmt = $this->con->prepare($statement);
         $stmt->execute();
     }
 }
开发者ID:robin850,项目名称:Propel2,代码行数:20,代码来源:PlatformDatabaseBuildTimeBase.php

示例10: testValidateReturnsFalseWhenTwoTablesHaveSamePhpName

 public function testValidateReturnsFalseWhenTwoTablesHaveSamePhpName()
 {
     $table1 = new Table('foo');
     $table2 = new Table('bar');
     $table2->setPhpName('Foo');
     $database = new Database();
     $database->addTable($table1);
     $database->addTable($table2);
     $appData = new AppData();
     $appData->addDatabase($database);
     $validator = new SchemaValidator($appData);
     $this->assertFalse($validator->validate());
     $this->assertContains('Table "bar" declares a phpName already used in another table', $validator->getErrors());
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:14,代码来源:SchemaValidatorTest.php

示例11: createFormTypeFromDatabase

 /**
  * Create FormTypes from a given database, bundle and models.
  *
  * @param BundleInterface $bundle   The bundle for which the FormTypes will be generated.
  * @param Database        $database The database to inspect.
  * @param array           $models   The models to build.
  * @param OutputInterface $output   An OutputInterface instance
  * @param boolean         $force    Override files if present.
  */
 protected function createFormTypeFromDatabase(BundleInterface $bundle, Database $database, $models, OutputInterface $output, $force = false)
 {
     $dir = $this->createDirectory($bundle, $output);
     foreach ($database->getTables() as $table) {
         if (0 < count($models) && !in_array($table->getPhpName(), $models)) {
             continue;
         }
         $file = new \SplFileInfo(sprintf('%s/%sType.php', $dir, $table->getPhpName()));
         if (!file_exists($file) || true === $force) {
             $this->writeFormType($bundle, $table, $file, $force, $output);
         } else {
             $output->writeln(sprintf('File <comment>%-60s</comment> exists, skipped. Try the <info>--force</info> option.', $this->getRelativeFileName($file)));
         }
     }
 }
开发者ID:naldz,项目名称:cyberden,代码行数:24,代码来源:FormGenerateCommand.php

示例12: appendDatabaseNode

 /**
  * Appends the generated <database> XML node to its parent node.
  *
  * @param Database $database   The Database model instance
  * @param \DOMNode $parentNode The parent DOMNode object
  */
 private function appendDatabaseNode(Database $database, \DOMNode $parentNode)
 {
     $databaseNode = $parentNode->appendChild($this->document->createElement('database'));
     $databaseNode->setAttribute('name', $database->getName());
     $databaseNode->setAttribute('defaultIdMethod', $database->getDefaultIdMethod());
     if ($package = $database->getPackage()) {
         $databaseNode->setAttribute('package', $package);
     }
     if ($schema = $database->getSchema()) {
         $databaseNode->setAttribute('schema', $schema);
     }
     if ($namespace = $database->getNamespace()) {
         $databaseNode->setAttribute('namespace', $namespace);
     }
     if ($baseClass = $database->getBaseClass()) {
         $databaseNode->setAttribute('baseClass', $baseClass);
     }
     if ($baseQueryClass = $database->getBaseQueryClass()) {
         $databaseNode->setAttribute('baseQueryClass', $baseQueryClass);
     }
     if ($defaultNamingMethod = $database->getDefaultPhpNamingMethod()) {
         $databaseNode->setAttribute('defaultPhpNamingMethod', $defaultNamingMethod);
     }
     $defaultAccessorVisibility = $database->getDefaultAccessorVisibility();
     if ($defaultAccessorVisibility !== Database::VISIBILITY_PUBLIC) {
         $databaseNode->setAttribute('defaultAccessorVisibility', $defaultAccessorVisibility);
     }
     $defaultMutatorVisibility = $database->getDefaultMutatorVisibility();
     if ($defaultMutatorVisibility !== Database::VISIBILITY_PUBLIC) {
         $databaseNode->setAttribute('defaultMutatorVisibility', $defaultMutatorVisibility);
     }
     $defaultStringFormat = $database->getDefaultStringFormat();
     if (Database::DEFAULT_STRING_FORMAT !== $defaultStringFormat) {
         $databaseNode->setAttribute('defaultStringFormat', $defaultStringFormat);
     }
     if ($database->isHeavyIndexing()) {
         $databaseNode->setAttribute('heavyIndexing', 'true');
     }
     if ($tablePrefix = $database->getTablePrefix()) {
         $databaseNode->setAttribute('tablePrefix', $tablePrefix);
     }
     if ($database->isIdentifierQuotingEnabled()) {
         $databaseNode->setAttribute('identifierQuoting', 'true');
     }
     /*
        FIXME - Before we can add support for domains in the schema, we need
        to have a method of the Column that indicates whether the column was mapped
        to a SPECIFIC domain (since Column->getDomain() will always return a Domain object)
     
        foreach ($this->domainMap as $domain) {
            $this->appendDomainNode($databaseNode);
        }
     */
     foreach ($database->getVendorInformation() as $vendorInformation) {
         $this->appendVendorInformationNode($vendorInformation, $databaseNode);
     }
     foreach ($database->getTables() as $table) {
         $this->appendTableNode($table, $databaseNode);
     }
 }
开发者ID:SwissalpS,项目名称:Propel2,代码行数:66,代码来源:XmlDumper.php

示例13: parse

 /**
  *
  */
 public function parse(Database $database)
 {
     $stmt = $this->dbh->query('SELECT version() as ver');
     $nativeVersion = $stmt->fetchColumn();
     if (!$nativeVersion) {
         throw new EngineException('Failed to get database version');
     }
     $arrVersion = sscanf($nativeVersion, '%*s %d.%d');
     $version = sprintf('%d.%d', $arrVersion[0], $arrVersion[1]);
     // Clean up
     $stmt = null;
     $stmt = $this->dbh->query("SELECT c.oid,\n            c.relname, n.nspname\n            FROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)\n            WHERE c.relkind = 'r'\n            AND n.nspname NOT IN ('information_schema','pg_catalog')\n            AND n.nspname NOT LIKE 'pg_temp%'\n            AND n.nspname NOT LIKE 'pg_toast%'\n            ORDER BY relname");
     $tableWraps = array();
     // First load the tables (important that this happen before filling out details of tables)
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $name = $row['relname'];
         $namespacename = $row['nspname'];
         if ($name == $this->getMigrationTable()) {
             continue;
         }
         $oid = $row['oid'];
         $table = new Table($name);
         if ($namespacename != 'public') {
             $table->setSchema($namespacename);
         }
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         // Create a wrapper to hold these tables and their associated OID
         $wrap = new \stdClass();
         $wrap->table = $table;
         $wrap->oid = $oid;
         $tableWraps[] = $wrap;
     }
     // Now populate only columns.
     foreach ($tableWraps as $wrap) {
         $this->addColumns($wrap->table, $wrap->oid, $version);
     }
     // Now add indexes and constraints.
     foreach ($tableWraps as $wrap) {
         $this->addForeignKeys($wrap->table, $wrap->oid, $version);
         $this->addIndexes($wrap->table, $wrap->oid, $version);
         $this->addPrimaryKey($wrap->table, $wrap->oid, $version);
     }
     // @TODO - Handle Sequences ...
     return count($tableWraps);
 }
开发者ID:robin850,项目名称:Propel2,代码行数:49,代码来源:PgsqlSchemaParser.php

示例14: getAddTablesDDL

 /**
  * Returns the DDL SQL to add the tables of a database
  * together with index and foreign keys. 
  * Since MSSQL always checks it the tables in foreign key definitions exist, 
  * the foreign key DDLs are moved after all tables are created
  *
  * @return string
  */
 public function getAddTablesDDL(Database $database)
 {
     $ret = $this->getBeginDDL();
     foreach ($database->getTablesForSql() as $table) {
         $this->normalizeTable($table);
     }
     foreach ($database->getTablesForSql() as $table) {
         $ret .= $this->getCommentBlockDDL($table->getName());
         $ret .= $this->getDropTableDDL($table);
         $ret .= $this->getAddTableDDL($table);
         $ret .= $this->getAddIndicesDDL($table);
     }
     foreach ($database->getTablesForSql() as $table) {
         $ret .= $this->getAddForeignKeysDDL($table);
     }
     $ret .= $this->getEndDDL();
     return $ret;
 }
开发者ID:naldz,项目名称:cyberden,代码行数:26,代码来源:MssqlPlatform.php

示例15: parseTables

 protected function parseTables(Database $database, Table $filterTable = null)
 {
     $sql = "\n        SELECT name\n        FROM sqlite_master\n        WHERE type='table'\n        %filter%\n        UNION ALL\n        SELECT name\n        FROM sqlite_temp_master\n        WHERE type='table'\n        %filter%\n        ORDER BY name;";
     $filter = '';
     if ($filterTable) {
         if ($schema = $filterTable->getSchema()) {
             $filter = sprintf(" AND name LIKE '%s§%%'", $schema);
         }
         $filter .= sprintf(" AND (name = '%s' OR name LIKE '%%§%1\$s')", $filterTable->getCommonName());
     } else {
         if ($schema = $database->getSchema()) {
             $filter = sprintf(" AND name LIKE '%s§%%'", $schema);
         }
     }
     $sql = str_replace('%filter%', $filter, $sql);
     $dataFetcher = $this->dbh->query($sql);
     // First load the tables (important that this happen before filling out details of tables)
     foreach ($dataFetcher as $row) {
         $tableName = $row[0];
         $tableSchema = '';
         if ('sqlite_' == substr($tableName, 0, 7)) {
             continue;
         }
         if (false !== ($pos = strpos($tableName, '§'))) {
             $tableSchema = substr($tableName, 0, $pos);
             $tableName = substr($tableName, $pos + 2);
         }
         $table = new Table($tableName);
         if ($filterTable && $filterTable->getSchema()) {
             $table->setSchema($filterTable->getSchema());
         } else {
             if (!$database->getSchema() && $tableSchema) {
                 //we have no schema to filter, but this belongs to one, so next
                 continue;
             }
         }
         if ($tableName === $this->getMigrationTable()) {
             continue;
         }
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
     }
 }
开发者ID:KyleGoslan,项目名称:Huge-Propel,代码行数:43,代码来源:SqliteSchemaParser.php


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