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


PHP ezcDbSchema类代码示例

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


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


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