示例#1
0
 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);
 }
示例#2
0
    public function testUnsupportedMySQLDbField()
    {
        $sql = <<<ENDL
CREATE TABLE `testexternal_musiclists` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `external_id` varchar(256) NOT NULL,
  `url` varchar(256) default NULL,
  `title` varchar(256) NOT NULL,
  `description` text,
  `type` enum('iMix','iTunes') NOT NULL default 'iMix',
  `last_updated` datetime NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `external_id` (`external_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='';
ENDL;
        $this->db->query($sql);
        try {
            $schema = ezcDbSchema::createFromDb($this->db);
            self::fail("Expected exception not thrown.");
        } catch (ezcDbSchemaUnsupportedTypeException $e) {
            self::assertEquals("The field type 'enum' is not supported with the 'MySQL' handler.", $e->getMessage());
        }
    }
示例#3
0
<?php

/**
 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 * @version 1.3.1
 * @filesource
 * @package WorkflowDatabaseTiein
 * @ignore
 */
require_once '../../../trunk/Base/src/base.php';
function __autoload($className)
{
    ezcBase::autoload($className);
}
$db = ezcDbFactory::create('mysql://test@localhost/test');
$schema = ezcDbSchema::createFromDb($db);
$schema->writeToFile('array', '../tests/workflow.dba');
file_put_contents('../tests/workflow.dba', str_replace('<?php return array (', '<?php
return array (', file_get_contents('../tests/workflow.dba')));
示例#4
0
 /**
  * Saves the schema from database to file.
  *
  * Use this method if you have changed the definition of the persistent object
  * and need to update the file on disk.
  */
 public function saveSchema()
 {
     $db = ezcDbInstance::get();
     $schema = ezcDbSchema::createFromDb($db);
     $schema->writeToFile('array', dirname(__FILE__) . '/persistent_test_object.dba');
 }
示例#5
0
 /**
  * Saves the schema from database to file.
  *
  * Use this method if you have changed the definition of the persistent object
  * and need to update the file on disk.
  */
 public static function saveSchema()
 {
     $db = ezcDbInstance::get();
     $schema = ezcDbSchema::createFromDb($db);
     $schema->writeToFile('array', dirname(__FILE__) . '/table.dba');
 }
示例#6
0
 /**
  * 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');
     }
 }
示例#7
0
 /**
  * Saves the schema from database to file.
  *
  * Use this method if you have changed the definition of the persistent object
  * and need to update the file on disk.
  */
 public function saveSchema()
 {
     $db = ezcDbInstance::get();
     $schema = ezcDbSchema::createFromDb($db);
     $schema->writeToFile("array", dirname(__FILE__) . "/relation.dba");
 }
示例#8
0
 public function testApply2()
 {
     $schema1 = self::getSchema3();
     $schema1->writeToDb($this->db);
     $schemaDiff = self::getSchemaDiff2();
     $schemaDiff->applyToDb($this->db);
     $schemaInDb = ezcDbSchema::createFromDb($this->db);
     $this->resetDb();
     $schema4 = self::getSchema4()->getSchema();
     $schemaInDb = $schemaInDb->getSchema();
     self::assertEquals($schema4['table'], $schemaInDb['table']);
     self::assertEquals($schema4['order'], $schemaInDb['order']);
     self::assertEquals($schema4['bugdb_change'], $schemaInDb['bugdb_change']);
 }
示例#9
0
 /**
  * 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;
 }
示例#10
0
 /**
  * Returns an {@link ezcDbSchema} created from $source which is of $format.
  * 
  * @param string $format 
  * @param string $source 
  * @return ezcDbSchema
  */
 private function getSchema($format, $source)
 {
     $readerClass = ezcDbSchemaHandlerManager::getReaderByFormat($format);
     $reader = new $readerClass();
     $schema = null;
     switch (true) {
         case $reader instanceof ezcDbSchemaDbReader:
             $db = ezcDbFactory::create($source);
             $schema = ezcDbSchema::createFromDb($db);
             break;
         case $reader instanceof ezcDbSchemaFileReader:
         default:
             $schema = ezcDbSchema::createFromFile($format, $source);
             break;
     }
     return $schema;
 }
示例#11
0
 public function testWriteWithoutPrefixReadWithPrefix()
 {
     $optionsWithoutPrefix = new ezcDbSchemaOptions();
     $optionsWithoutPrefix->tableNamePrefix = '';
     $optionsWithPrefix = new ezcDbSchemaOptions();
     $optionsWithPrefix->tableNamePrefix = 'prefix_';
     $schema = new ezcDbSchema(self::getSchema());
     $schemaWithPrefix = new ezcDbSchema(self::getSchemaWithPrefixedTableNames());
     ezcDbSchema::setOptions($optionsWithoutPrefix);
     $schemaWithPrefix->writeToDb($this->db);
     ezcDbSchema::setOptions($optionsWithPrefix);
     $newSchema = ezcDbSchema::createFromDb($this->db);
     self::assertEquals($schema, $newSchema);
 }
        'rgt' integer NOT NULL
    );
    CREATE UNIQUE INDEX 'nested_set_pri' on 'nested_set' ( 'id' );
    CREATE INDEX 'nested_set_left' on 'nested_set' ( 'lft' );
    CREATE INDEX 'nested_set_right' on 'nested_set' ( 'rgt' );

    CREATE TABLE data (
        'node_id' varchar(255) NOT NULL,
        'melting_temp_k' float,
        'boiling_temp_k' float
    );
    CREATE UNIQUE INDEX 'data_pri' on 'data' ( 'node_id' );
ENDSQL
);
// Create the example Persistent Object definition files and stub classes
$dbSchema = ezcDbSchema::createFromDb($dbh);
$writer1 = new ezcDbSchemaPersistentWriter(true);
$writer2 = new ezcDbSchemaPersistentClassWriter(true);
$writer1->saveToFile('files/po_defs', $dbSchema);
$writer2->saveToFile('files/classes', $dbSchema);
require 'files/classes/data.php';
// Setup the store and tree
$session = new ezcPersistentSession($dbh, new ezcPersistentCodeManager("files/po_defs"));
$store = new ezcTreePersistentObjectDataStore($session, 'data', 'node_id');
$tree = new ezcTreeDbNestedSet($dbh, 'nested_set', $store);
// Insert data
$metal = new data();
$tree->setRootNode($root = $tree->createNode('Metals', $metal));
$iron = new data();
$iron->setState(array('melting_temp_k' => 1811, 'boiling_temp_k' => 3134));
$root->addChild($tree->createNode('Fe', $iron));
示例#13
0
 public function __get($name)
 {
     switch ($name) {
         case 'poDef':
             if (is_null($this->_poDef)) {
                 $pos = ezcPersistentSessionInstance::get();
                 $this->_poDef = $pos->definitionManager->fetchDefinition($this->poClass);
             }
             return $this->_poDef;
         case 'schema':
             if (is_null($this->_schema)) {
                 $this->_schema = ezcDbSchema::createFromDb(ezcDbInstance::get());
             }
             return $this->_schema;
     }
     return parent::__get($name);
 }