本文整理汇总了PHP中ezcDbSchema::createFromFile方法的典型用法代码示例。如果您正苦于以下问题:PHP ezcDbSchema::createFromFile方法的具体用法?PHP ezcDbSchema::createFromFile怎么用?PHP ezcDbSchema::createFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ezcDbSchema
的用法示例。
在下文中一共展示了ezcDbSchema::createFromFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupTable
/**
* Loads the schema from file into the database.
*/
public static function setupTable()
{
$db = ezcDbInstance::get();
// Load schema
$schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/table.dba');
$schema->writeToDb($db);
}
示例2: testPhpArray
public function testPhpArray()
{
$fileName = $this->tempDir . '/php_array_write_result.php';
$schema = new ezcDbSchema(self::getSchema());
$schema->writeToFile('array', $fileName);
$newSchema = ezcDbSchema::createFromFile('array', $fileName);
self::assertEquals($schema, $newSchema);
}
示例3: 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;
}
示例4: 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();
}
示例5: 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());
}
}
示例6: 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);
}
示例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.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');
}
}
示例8: 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());
}
}
示例9: 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());
}
}
示例10: setUp
protected function setUp()
{
$tables = array('user', 'cache_templates', 'cache_values');
// Get the DB instance
try {
$db = ezcDbInstance::get();
} catch (Exception $e) {
$this->markTestSkipped('No database handler defined');
}
$this->basePath = realpath(dirname(__FILE__)) . '/';
// Setup the template engine
$config = ezcTemplateConfiguration::getInstance();
$this->tempDir = $config->compilePath = $this->createTempDir("ezcTemplate_");
$config->templatePath = $this->basePath . 'templates/';
$config->disableCache = false;
$config->cacheManager = new DbCacheManager();
// Create tables.
foreach ($tables as $table) {
try {
$db->exec("DROP TABLE {$table}");
} catch (Exception $e) {
}
// eat
}
$schema = ezcDbSchema::createFromFile('xml', dirname(__FILE__) . '/cache-manager-schema.xml');
$schema->writeToDb($db);
// insert some data
$iq = $db->createInsertQuery();
$s = $iq->insertInto($db->quoteIdentifier('user'))->set($db->quoteIdentifier('id'), 1)->set($db->quoteIdentifier('name'), $iq->bindValue('Raymond'))->set($db->quoteIdentifier('nickname'), $iq->bindValue('sunRay'))->prepare();
$s->execute();
$iq = $db->createInsertQuery();
$s = $iq->insertInto($db->quoteIdentifier('user'))->set($db->quoteIdentifier('id'), 2)->set($db->quoteIdentifier('name'), $iq->bindValue('Derick'))->set($db->quoteIdentifier('nickname'), $iq->bindValue('Tiger'))->prepare();
$s->execute();
$iq = $db->createInsertQuery();
$s = $iq->insertInto($db->quoteIdentifier('user'))->set($db->quoteIdentifier('id'), 3)->set($db->quoteIdentifier('name'), $iq->bindValue('Jan'))->set($db->quoteIdentifier('nickname'), $iq->bindValue('Amos'))->prepare();
$s->execute();
}
示例11: getSchema
/**
* Returns the schema reader instance for the given schema path and format.
*
* @return object The schema reader.
*/
protected function getSchema()
{
$schema = null;
$readerClass = ezcDbSchemaHandlerManager::getReaderByFormat($this->schemaFormat);
$reader = new $readerClass();
switch (true) {
case $reader instanceof ezcDbSchemaDbReader:
$db = ezcDbFactory::create($this->pathSchema);
$schema = ezcDbSchema::createFromDb($db);
break;
case $reader instanceof ezcDbSchemaFileReader:
$schema = ezcDbSchema::createFromFile($this->schemaFormat, $this->pathSchema);
break;
default:
$this->raiseError("Reader class not supported: '{$readerClass}'.");
break;
}
return $schema;
}
示例12: testValidFromDb
public function testValidFromDb()
{
$type = ezcTestSettings::getInstance()->db->phptype;
$dsn = ezcTestSettings::getInstance()->db->dsn;
if ($dsn === null || $type === null || $dsn === "sqlite://:memory:") {
$this->markTestSkipped("DSN or database type not set or DSN not supported.");
}
// setup this test
$destination = $this->createTempDir("PersObjDatSchem");
$db = ezcDbFactory::create($dsn);
$fileSource = dirname(__FILE__) . "/data/webbuilder.schema.xml";
$schema = ezcDbSchema::createFromFile("xml", $fileSource);
$schema->writeToDb($db);
// real test
$res = `php PersistentObjectDatabaseSchemaTiein/src/rungenerator.php -f "{$type}" -s "{$dsn}" "{$destination}"`;
$this->assertEquals(1, preg_match('(PersistentObject\\sdefinition\\ssuccessfully\\swritten\\sto)s', $res), 'No success message found in generated output.');
foreach (glob(dirname(__FILE__) . "/data/definition_only/definitions/*.php") as $file) {
$this->assertEquals(file_get_contents($file), file_get_contents($destination . "/" . basename($file)), "Geneator generated an invalid persistent object definition file.");
}
$this->removeTempDir();
}
示例13: run
/**
* Run the generator.
* Process the given options and generate a PersistentObject definition from it.
*
* @return void
*/
public function run()
{
try {
$this->input->process();
} catch (ezcConsoleException $e) {
$this->raiseError("Error while processing your options: {$e->getMessage()}", true);
}
if ($this->input->getOption('h')->value === true) {
$this->output->outputText($this->input->getHelpText(ezcPersistentObjectSchemaGenerator::PROGRAM_DESCRIPTION, 80, true), "help");
exit(0);
}
$defDir = $this->input->argumentDefinition["def dir"]->value;
$classDir = $this->input->argumentDefinition["class dir"]->value;
$schema = null;
try {
$readerClass = ezcDbSchemaHandlerManager::getReaderByFormat($this->input->getOption("format")->value);
$reader = new $readerClass();
switch (true) {
case $reader instanceof ezcDbSchemaDbReader:
$db = ezcDbFactory::create($this->input->getOption("source")->value);
$schema = ezcDbSchema::createFromDb($db);
break;
case $reader instanceof ezcDbSchemaFileReader:
$schema = ezcDbSchema::createFromFile($this->input->getOption("format")->value, $this->input->getOption("source")->value);
break;
default:
$this->raiseError("Reader class not supported: '{$readerClass}'.");
break;
}
} catch (Exception $e) {
$this->raiseError("Error reading schema: {$e->getMessage()}");
}
try {
$writer = new ezcDbSchemaPersistentWriter($this->input->getOption("overwrite")->value, $this->input->getOption("prefix")->value);
$writer->saveToFile($defDir, $schema);
if ($classDir !== null) {
$writer = new ezcDbSchemaPersistentClassWriter($this->input->getOption("overwrite")->value, $this->input->getOption("prefix")->value);
$writer->saveToFile($classDir, $schema);
}
} catch (ezcBaseException $e) {
$this->raiseError("Error writing schema: {$e->getMessage()}");
}
$this->output->outputLine("PersistentObject definition successfully written to {$defDir}.", 'info');
if ($classDir !== null) {
$this->output->outputLine("Class files successfully written to {$classDir}.", 'info');
}
}
示例14: setUpTables
protected function setUpTables()
{
$schema = ezcDbSchema::createFromFile('xml', dirname(__FILE__) . '/data/schema.xml');
$schema->writeToDb($this->db);
}
示例15: ezcDbSchemaTable
<?php
require 'tutorial_autoload.php';
// create a database schema from an XML file
$xmlSchema = ezcDbSchema::createFromFile('xml', 'enterprise.xml');
// get the tables schema from the database schema
// BY REFERENCE! - otherwise new/deleted tables are NOT updated in the schema
$schema =& $xmlSchema->getSchema();
// add a new table (employees) to the database
$schema['employees'] = new ezcDbSchemaTable(array('id' => new ezcDbSchemaField('integer', false, true, null, true)), array('primary' => new ezcDbSchemaIndex(array('id' => new ezcDbSchemaIndexField()), true)));
// copy the schema of table employees to table persons
$schema['persons'] = clone $schema['employees'];
// delete the table table2
unset($schema['table2']);
// add the fields birthday and salary to the table employees
$schema['employees']->fields['birthday'] = new ezcDbSchemaField('date');
$schema['employees']->fields['salary'] = new ezcDbSchemaField('integer');
// modify the type of salary field to be float
$schema['employees']->fields['salary']->type = 'float';
// delete the field salary
unset($schema['employees']->fields['salary']);