• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ezcDbSchema类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: convertToDDL

 /**
  * Returns an array with SQL DDL statements that creates the database definition in $dbSchema
  *
  * Converts the schema definition contained in $dbSchema to DDL SQL. This
  * SQL can be used to create tables in an existing database according to
  * the definition.  The SQL queries are returned as an array.
  * 
  * @param ezcDbSchema $dbSchema
  * @return array(string)
  */
 public function convertToDDL(ezcDbSchema $dbSchema)
 {
     $this->schema = $dbSchema->getSchema();
     // reset queries
     $this->queries = array();
     $this->context = array();
     $this->generateSchemaAsSql();
     return $this->queries;
 }
开发者ID:mdb-webdev,项目名称:livehelperchat,代码行数:19,代码来源:common_sql_writer.php


示例2: saveToFile

 /**
  * Saves the schema definition in $schema to the file $file.
  * @todo throw exception when file can not be opened
  *
  * @param string      $file
  * @param ezcDbSchema $dbSchema
  */
 public function saveToFile($file, ezcDbSchema $dbSchema)
 {
     $schema = $dbSchema->getSchema();
     $data = $dbSchema->getData();
     $fileData = '<?php return ' . var_export(array($schema, $data), true) . '; ?>';
     if (!@file_put_contents($file, (string) $fileData)) {
         throw new ezcBaseFilePermissionException($file, ezcBaseFileException::WRITE);
     }
 }
开发者ID:valentinbora,项目名称:joobsbox-php,代码行数:16,代码来源:writer.php


示例3: testPhpArrayUnwritableDir

 public function testPhpArrayUnwritableDir()
 {
     $fileName = $this->tempDir . '/bogus/php_array_write_result.php';
     $schema = new ezcDbSchema(self::getSchema());
     try {
         $schema->writeToFile('array', $fileName);
         $this->fail('Expected exception not thrown');
     } catch (ezcBaseFilePermissionException $e) {
         $this->assertEquals("The file '{$fileName}' can not be opened for writing.", $e->getMessage());
     }
 }
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:11,代码来源:php_array_test.php


示例4: saveToFile

 /**
  * Writes the schema definition in $dbSchema to files located in $dir.
  * This method dumps the given schema to PersistentObject definitions, which
  * will be located in the given directory.
  *
  * @param string $dir           The directory to store definitions in.
  * @param ezcDbSchema $dbSchema The schema object to create defs for.
  *
  * @throws ezcBaseFileNotFoundException If the given directory could not be
  *                                      found.
  * @throws ezcBaseFilePermissionException If the given directory is not 
  *                                        writable.
  */
 public function saveToFile($dir, ezcDbSchema $dbSchema)
 {
     if (!is_dir($dir)) {
         throw new ezcBaseFileNotFoundException($dir, 'directory');
     }
     if (!is_writable($dir)) {
         throw new ezcBaseFilePermissionException($dir, ezcBaseFileException::WRITE);
     }
     $schema = $dbSchema->getSchema();
     foreach ($schema as $tableName => $table) {
         $this->writeTable($dir, $tableName, $table);
     }
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:26,代码来源:writer.php


示例5: validate

 /**
  * Validates if all the types used in the $schema are supported.
  *
  * This method loops over all the fields in a table and checks whether the
  * type that is used for each field is supported. It will return an array
  * containing error strings for each non-supported type that it finds.
  *
  * @param ezcDbSchema $schema
  * @return array(string)
  */
 public static function validate(ezcDbSchema $schema)
 {
     $errors = array();
     /* For each table we check all field's types. */
     foreach ($schema->getSchema() as $tableName => $table) {
         foreach ($table->fields as $fieldName => $field) {
             if (!in_array($field->type, ezcDbSchema::$supportedTypes)) {
                 $errors[] = "Field '{$tableName}:{$fieldName}' uses the unsupported type '{$field->type}'.";
             }
         }
     }
     return $errors;
 }
开发者ID:valentinbora,项目名称:joobsbox-php,代码行数:23,代码来源:types.php


示例6: testCompareSchemas

 /**
  * Compare two schemas loaded from different sources.
  *
  * Load schema #1 from a .php file, save it to mysql db.
  * Then load schema #2 from the same db and save it to another .php file.
  * (the .php files can be then compared manually)
  * Then compare the schemas.
  * There should be no differences.
  *
  * i.e.:
  * php -> schema1 -> mydb -> schema2 -> php
  *
  */
 public function testCompareSchemas()
 {
     $db = ezcDbInstance::get();
     $schema = new ezcDbSchema();
     $schema->load($this->referenceFile, 'php-file', 'schema');
     $schema->save($db, $db->getName() . '-db');
     $schema2 = new ezcDbSchema();
     $schema2->load($db, $db->getName() . '-db');
     $schema2->save($this->generatedFile, 'php-file', 'schema');
     $diff = $schema->compare($schema2);
     $schema->saveDelta($diff, $this->deltaFile, $db->getName() . '-file');
     $this->assertEquals(array(), $diff, 'Found differences in the schemas.');
 }
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:26,代码来源:conversion_test.php


示例7: setupTable

 /**
  * Loads the schema from file into the database.
  */
 public static function setupTable()
 {
     $db = ezcDbInstance::get();
     // Load schema
     $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/persistent_test_object_no_auto_increment.dba');
     $schema->writeToDb($db);
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:10,代码来源:manual_generator_test.php


示例8: getEmptyDb

 protected function getEmptyDb()
 {
     $schema = ezcDbSchema::createFromFile('xml', TESTPATH . '../src/schema.xml');
     //        $db = ezcDbFactory::create("sqlite://:memory:");
     $db = ezcDbFactory::create("sqlite:///home/ymc-toko/sqlite");
     $schema->writeToDb($db);
     return $db;
 }
开发者ID:jou,项目名称:ymc-components,代码行数:8,代码来源:definition_storage_database.php


示例9: validate

 /**
  * Validates if all the fields used in all indexes exist.
  *
  * This method loops over all the fields in the indexes of each table and
  * checks whether the fields that is used in an index is also defined in
  * the table definition. It will return an array containing error strings
  * for each non-supported type that it finds.
  *
  * @param ezcDbSchema $schema
  * @return array(string)
  */
 public static function validate(ezcDbSchema $schema)
 {
     $errors = array();
     /* For each table we first retrieve all the field names, and then check
      * per index whether the fields it references exist */
     foreach ($schema->getSchema() as $tableName => $table) {
         $fields = array_keys($table->fields);
         foreach ($table->indexes as $indexName => $index) {
             foreach ($index->indexFields as $indexFieldName => $dummy) {
                 if (!in_array($indexFieldName, $fields)) {
                     $errors[] = "Index '{$tableName}:{$indexName}' references unknown field name '{$tableName}:{$indexFieldName}'.";
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:Adeelgill,项目名称:livehelperchat,代码行数:28,代码来源:index_fields.php


示例10: validate

 /**
  * Validates if all the index names used are unique accross the schema.
  *
  * This method loops over all the indexes in all tables and checks whether
  * they have been used before.
  *
  * @param ezcDbSchema $schema
  * @return array(string)
  */
 public static function validate(ezcDbSchema $schema)
 {
     $indexes = array();
     $errors = array();
     /* For each table we check all auto increment fields. */
     foreach ($schema->getSchema() as $tableName => $table) {
         foreach ($table->indexes as $indexName => $dummy) {
             $indexes[$indexName][] = $tableName;
         }
     }
     foreach ($indexes as $indexName => $tableList) {
         if (count($tableList) > 1) {
             $errors[] = "The index name '{$indexName}' is not unique. It exists for the tables: '" . join("', '", $tableList) . "'.";
         }
     }
     return $errors;
 }
开发者ID:Adeelgill,项目名称:livehelperchat,代码行数:26,代码来源:unique_index_name.php


示例11: setUp

 protected function setUp()
 {
     $this->xmlSchema = ezcDbSchema::createFromFile('xml', dirname(__FILE__) . '/testfiles/bug8900.xml');
     // get the tables schema from the database schema
     // BY REFERENCE! - otherwise new/deleted tables are NOT updated
     // in the schema
     $this->schema =& $this->xmlSchema->getSchema();
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:8,代码来源:schema_test.php


示例12: testCreateFromFileNonExisting

 public function testCreateFromFileNonExisting()
 {
     try {
         ezcDbSchema::createFromFile('xml', 'testfiles/isnt-here.php');
         self::fail("Expected exception not thrown");
     } catch (Exception $e) {
         self::assertEquals("The schema file 'testfiles/isnt-here.php' could not be found.", $e->getMessage());
     }
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:9,代码来源:xml_diff_test.php


示例13: write

 /**
  * Writes the given $schema to $dir using $template.
  *
  * Iterates through all tables in $schema, sends each of them to a {@link
  * ezcTemplate} with $template and writes the result to $dir with the file
  * name returned by the template.
  * 
  * @param ezcDbSchema $schema 
  * @param string $template
  * @param mixed $dir 
  */
 public function write(ezcDbSchema $schema, $template, $dir)
 {
     $tplConf = ezcTemplateConfiguration::getInstance();
     $tplConf->templatePath = $this->properties['options']->templatePath;
     $tplConf->compilePath = $this->properties['options']->templateCompilePath;
     $tpl = new ezcTemplate();
     $tpl->send->classPrefix = $this->properties['options']->classPrefix;
     foreach ($schema->getSchema() as $tableName => $tableSchema) {
         $tpl->send->schema = $tableSchema;
         $tpl->send->tableName = $tableName;
         $content = $tpl->process($template);
         $fileName = $dir . '/' . $tpl->receive->fileName;
         if (!$this->properties['options']->overwrite && file_exists($fileName)) {
             throw new ezcPersistentObjectSchemaOverwriteException($fileName);
         }
         file_put_contents($fileName, $content);
     }
 }
开发者ID:Adeelgill,项目名称:livehelperchat,代码行数:29,代码来源:template_writer.php


示例14: testUppercaseDataTypes

 public function testUppercaseDataTypes()
 {
     $path = dirname(__FILE__) . '/testfiles/bug13072.sqlite';
     $db = ezcDbFactory::create("sqlite://{$path}");
     $newSchema = ezcDbSchema::createFromDb($db);
     $schema = $newSchema->getSchema();
     self::assertEquals('integer', $schema['authors']->fields['id']->type);
     self::assertEquals('text', $schema['authors']->fields['firstname']->type);
     self::assertEquals('text', $schema['ownership']->fields['critique']->type);
 }
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:10,代码来源:sqlite_test.php


示例15: testParsingTrueFalse

 public function testParsingTrueFalse()
 {
     $fileName = realpath($this->testFilesDir . 'bug10365.xml');
     $schema = ezcDbSchema::createFromFile('xml', $fileName)->getSchema();
     self::assertEquals($schema['bug10365']->fields['field_notnull']->notNull, true);
     self::assertEquals($schema['bug10365']->fields['field_notnull']->autoIncrement, true);
     self::assertEquals($schema['bug10365']->fields['field_notnull']->unsigned, true);
     self::assertEquals($schema['bug10365']->fields['field_null']->notNull, false);
     self::assertEquals($schema['bug10365']->fields['field_null']->autoIncrement, false);
     self::assertEquals($schema['bug10365']->fields['field_null']->unsigned, false);
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:11,代码来源:xml_test.php


示例16: setupTable

 /**
  * Loads the schema from file into the database.
  */
 public static function setupTable()
 {
     $db = ezcDbInstance::get();
     // Load schema
     $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/persistent_test_object.dba');
     $schema->writeToDb($db);
     // create sequence if it is a postgres database
     if ($db->getName() == 'pgsql') {
         $db->exec('CREATE SEQUENCE PO_test_seq START 5');
     }
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:14,代码来源:native_generator_test.php


示例17: setUp

 public function setUp()
 {
     $_GET = null;
     $_SERVER = self::$server;
     try {
         $this->db = ezcDbInstance::get();
         $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/../../../docs/tutorial/openid_db_store_schema.dba');
         $schema->writeToDb($this->db);
     } catch (Exception $e) {
         $this->markTestSkipped("You must provide a database to runtests.php: " . $e->getMessage());
     }
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:12,代码来源:openid_db_store_test.php


示例18: setUp

 protected function setUp()
 {
     parent::setUp();
     try {
         $this->db = ezcDbInstance::get();
         $this->cleanupTables($this->db);
         $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'workflow.dba');
         $schema->writeToDb($this->db);
         $this->dbStorage = new ezcWorkflowDatabaseDefinitionStorage($this->db);
     } catch (Exception $e) {
         $this->markTestSkipped('No test database has been configured: ' . $e->getMessage());
     }
 }
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:13,代码来源:case.php


示例19: setUp

 public function setUp()
 {
     try {
         $this->db = ezcDbInstance::get();
         if ($this->db === false) {
             $this->markTestSkipped("You must provide a database to runtests.php.");
         }
         $tables = array(self::$table => new ezcDbSchemaTable(array(self::$fieldId => new ezcDbSchemaField('integer', false, true, null, true), self::$fieldUser => new ezcDbSchemaField('text', 32, true), self::$fieldPassword => new ezcDbSchemaField('text', 64, true), self::$fieldName => new ezcDbSchemaField('text', 64, true), self::$fieldCountry => new ezcDbSchemaField('text', 32, true)), array(self::$fieldUser => new ezcDbSchemaIndex(array(self::$fieldUser => new ezcDbSchemaIndexField()), false, false))));
         $schema = new ezcDbSchema($tables);
         $schema->writeToDb($this->db);
     } catch (Exception $e) {
         // Oracle seems to skip every other test if the next line is enabled
         // $this->markTestSkipped( "Cannot create test table '" . self::$table . "'. " . $e->getMessage() );
     }
     if (!isset($this->db)) {
         $this->markTestSkipped("You must provide a database to runtests.php. Run runtests.php --help to see how to specify a database.");
     }
     try {
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('1'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('jan.modaal'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(sha1('qwerty')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Jan Modaal'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('NL'));
         $stmt = $query->prepare();
         $stmt->execute();
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('2'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('john.doe'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(crypt('foobar', 'jo')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('John Doe'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('US'));
         $stmt = $query->prepare();
         $stmt->execute();
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('3'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('zhang.san'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(md5('asdfgh')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Zhang San'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('CN'));
         $stmt = $query->prepare();
         $stmt->execute();
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('4'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('hans.mustermann'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue('abcdef'))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Hans Mustermann'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('DE'));
         $stmt = $query->prepare();
         $stmt->execute();
     } catch (Exception $e) {
         $this->markTestSkipped("Cannot insert test values into table '" . self::$table . "'. " . $e->getMessage());
     }
 }
开发者ID:bmdevel,项目名称:ezc,代码行数:38,代码来源:database_test.php


示例20: validate

 /**
  * Validates if all the types used in the $schema are supported.
  *
  * This method loops over all the fields in a table and checks whether the
  * type that is used for each field is supported. It will return an array
  * containing error strings for each non-supported type that it finds.
  *
  * @param ezcDbSchema $schema
  * @return array(string)
  */
 public static function validate(ezcDbSchema $schema)
 {
     $errors = array();
     /* For each table we check all auto increment fields. */
     foreach ($schema->getSchema() as $tableName => $table) {
         foreach ($table->fields as $fieldName => $field) {
             if ($field->autoIncrement === true) {
                 $found = false;
                 // Loop over de indexes to see if there is a primary
                 foreach ($table->indexes as $indexName => $index) {
                     if ($index->primary === true) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $errors[] = "Field '{$tableName}:{$fieldName}' is auto increment but there is no primary index defined.";
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:mdb-webdev,项目名称:livehelperchat,代码行数:33,代码来源:auto_increment_index.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP ezcDebug类代码示例发布时间:2022-05-23
下一篇:
PHP ezcDbInstance类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap