本文整理汇总了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;
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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.');
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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);
}