/** * 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); }
/** * 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); }
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); }
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; }
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(); }
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()); } }
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); }
/** * 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'); } }
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()); } }
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()); } }
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(); }
/** * 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; }
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(); }
/** * 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'); } }
protected function setUpTables() { $schema = ezcDbSchema::createFromFile('xml', dirname(__FILE__) . '/data/schema.xml'); $schema->writeToDb($this->db); }
<?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']);
/** * Loads the schema from file into the database. * * If autoIncrement is set to false a schema with the id field not set to autoincrement is used. */ public static function setupTables($autoIncrement = true) { $db = ezcDbInstance::get(); $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/database_type.dba'); $schema->writeToDb($db); }
public function step2Action() { $this->reloadConfig(); configureTheme(APPLICATION_THEME, 'install'); $session = new Zend_Session_Namespace('Install'); // Create tables $xmlSchema = ezcDbSchema::createFromFile('xml', APPLICATION_DIRECTORY . '/data/schema.xml'); $schema =& $xmlSchema->getSchema(); if ($this->config->db->prefix != "") { $keys = array_keys($schema); foreach ($keys as $tableName) { $schema[$this->config->db->prefix . $tableName] = clone $schema[$tableName]; unset($schema[$tableName]); } } $dbconfig = new Zend_Config_Xml(DB_CONFIG_LOCATION, 'zend_db'); $db = ezcDbFactory::create($dbconfig->connection_string); $xmlSchema->writeToDb($db); $db = Zend_Registry::get("db"); $db->delete($this->config->db->prefix . $this->config->dbtables->categories, array("name='General'")); $db->insert($this->config->db->prefix . $this->config->dbtables->categories, array('id' => 0, 'name' => 'General', 'link' => 'general', 'orderindex' => 100, 'parent' => 0)); // Make the form $this->adminForm = new Zend_Form(); $this->adminForm->setAction($this->view->baseUrl . "/install/step2")->setMethod('post')->setLegend('Administrator credentials'); $notEmpty = new Zend_Validate_NotEmpty(); $realname = $this->adminForm->createElement('text', 'realname')->setLabel('Your name:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Real name is mandatory")))->setRequired(true); $notEmpty = clone $notEmpty; $username = $this->adminForm->createElement('text', 'username')->setLabel('Username:'******'StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Username is mandatory")))->setRequired(true); $notEmpty = clone $notEmpty; $password = $this->adminForm->createElement('text', 'password')->setLabel('Password:'******'StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Password is mandatory")))->setRequired(true); $notEmpty = clone $notEmpty; $emailValidator = new Zend_Validate_EmailAddress(); $email = $this->adminForm->createElement('text', 'email')->setLabel('Email:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[email,required]')->addValidator($notEmpty->setMessage($this->view->translate("Email is mandatory")))->addValidator($emailValidator->setMessage($this->view->translate("Email is invalid")))->setRequired(true); $submit = $this->adminForm->createElement('submit', 'save')->setLabel('Save'); $this->adminForm->addElement($realname)->addElement($username)->addElement($password)->addElement($email)->addElement($submit); $dg = $this->adminForm->addDisplayGroup(array('realname', 'username', 'password', 'email', 'save'), 'user'); if ($this->getRequest()->isPost()) { $this->validateAdminUser(); return; } $this->view->form = $this->adminForm->render(); }
public function testGenerateCorrectTypeStringPrimary() { $schema = ezcDbSchema::createFromFile('xml', $this->testFilesDir . '/bug-12937-persitent-string-id.xml'); $schema->writeToFile('persistent', $this->tempDir); $this->assertEquals(require $this->tempDir . '/liveuser_translations_string_id.php', require $this->testFilesDir . '/persistent_bug_12937/liveuser_translations_string_id.php'); }
/** * 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; }
public function testTwoTablesPrimaryKey() { $fileNameWithout = realpath($this->testFilesDir . 'bug8900-without-index.xml'); $schemaWithout = ezcDbSchema::createFromFile('xml', $fileNameWithout); $fileNameWith = realpath($this->testFilesDir . 'bug8900.xml'); $schemaWith = ezcDbSchema::createFromFile('xml', $fileNameWith); $diff = ezcDbSchemaComparator::compareSchemas($schemaWithout, $schemaWith); $text = ''; foreach ($diff->convertToDDL($this->db) as $statement) { $text .= $statement . ";\n"; } $name = strtolower($this->db->getName()); $sql = file_get_contents($this->testFilesDir . "bug8900-diff_{$name}.sql"); self::assertEquals($sql, $text); }
<?php /** * @package JetFuelCore */ require_once 'core/common.php'; $output = new ezcConsoleOutput(); $output->formats->info->color = 'blue'; // create a database schema from a database connection: $db = ezcDbFactory::create(DB_DSN); $dbSchema = ezcDbSchema::createFromDb($db); // save a database schema to an XML file: $dbSchema->writeToFile('xml', 'saved-schema.xml'); $messages = ezcDbSchemaValidator::validate($dbSchema); foreach ($messages as $message) { $output->outputLine($message, 'info'); } $readerClass = ezcDbSchemaHandlerManager::getReaderByFormat('xml'); $reader = new $readerClass(); $schema = ezcDbSchema::createFromFile('xml', 'saved-schema.xml'); $writer = new ezcDbSchemaPersistentWriter(true, null); $writer->saveToFile('app/model/definitions', $schema); $output->outputLine("Class files successfully written to app/model/definitions.", 'info');
<?php $db = ezcDbInstance::get(); // replace if you get your database instance differently $schema = ezcDbSchema::createFromFile('array', 'workflow.dba'); $schema->writeToDb($db);
public function testAdditionalTables() { $command = array(); $schema = ezcDbSchema::createFromFile('xml', dirname(__FILE__) . '/testfiles/audits_db_schema.xml'); foreach ($schema->convertToDDL($this->db) as $statement) { $command[] = $statement; } try { $this->db->exec($command[0]); } catch (Exception $e) { } $this->db->exec($command[1]); // Only the FAILED and SUCCESS audits from every type. $filter = new ezcLogFilter(); $filter->severity = ezcLog::FAILED_AUDIT | ezcLog::SUCCESS_AUDIT; $this->writer->setTable($filter, "audits"); $this->writer->writeLogMessage("Hoagie logged in.", ezcLog::SUCCESS_AUDIT, "administration interface", "security", array("name" => "Hoagie")); $q = $this->db->createSelectQuery(); $q->select('*')->from('audits'); $stmt = $this->db->query($q->getQuery()); $a = $stmt->fetch(); $this->assertEquals("Hoagie logged in.", $a["message"], "Message doesn't match"); $this->assertEquals("administration interface", $a["source"], "Source doesn't match"); $this->assertEquals("security", $a["category"], "Category doesn't match"); $this->assertEquals("Success audit", $a["severity"], "Severity doesn't match"); $this->assertEquals("Hoagie", $a["name"], "Extra info doesn't match"); try { $this->db->exec($command[0]); } catch (Exception $e) { } }
public function getSchema() { $schema = ezcDbSchema::createFromFile('xml', dirname(__FILE__) . '/data/webbuilder.schema.xml'); return $schema; }
/** * Loads the schema from file into the database. */ public static function setupTables() { $db = ezcDbInstance::get(); $schema = ezcDbSchema::createFromFile("array", dirname(__FILE__) . "/relation.dba"); $schema->writeToDb($db); }
function testUpdateWithFalseTest() { // create the database $db = ezcDbInstance::get(); // open schema $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/files/bug10777.dba'); $schema->writeToDb($db); // insert data $q = $db->createInsertQuery(); $s = $q->insertInto('bug10777')->set('bar', $q->bindValue(false, null, PDO::PARAM_BOOL))->prepare(); $s->execute(); $q = $db->createInsertQuery(); $s = $q->insertInto('bug10777')->set('bar', $q->bindValue(true))->prepare(); $s->execute(); // first test: select with where being false. $q = $db->createSelectQuery(); $s = $q->select('bar')->from('bug10777')->where($q->expr->eq('bar', $q->bindValue(false, null, PDO::PARAM_BOOL)))->prepare(); $s->execute(); $s->bindColumn(1, $returnValue, PDO::PARAM_BOOL); $s->fetch(PDO::FETCH_BOUND); self::assertEquals(false, $returnValue); // second test: update with set to true $q = $db->createUpdateQuery(); $s = $q->update('bug10777')->set('bar', $q->bindValue(true, null, PDO::PARAM_BOOL))->prepare(); $s->execute(); $q = $db->createSelectQuery(); $s = $q->select('bar')->from('bug10777')->prepare(); $s->execute(); $s->bindColumn(1, $returnValue, PDO::PARAM_BOOL); $s->fetch(PDO::FETCH_BOUND); self::assertEquals(true, $returnValue); $s->fetch(PDO::FETCH_BOUND); self::assertEquals(true, $returnValue); // third test: update with set to false $q = $db->createUpdateQuery(); $s = $q->update('bug10777')->set('bar', $q->bindValue(false, null, PDO::PARAM_BOOL))->prepare(); $s->execute(); $q = $db->createSelectQuery(); $s = $q->select('bar')->from('bug10777')->prepare(); $s->execute(); $s->bindColumn(1, $returnValue, PDO::PARAM_BOOL); $s->fetch(PDO::FETCH_BOUND); self::assertEquals(false, $returnValue); $s->fetch(PDO::FETCH_BOUND); self::assertEquals(false, $returnValue); }
private function loadSchema() { // create the parent_child table $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . '/files/' . $this->schemaName); $schema->writeToDb($this->dbh); }
public function getSchema() { $schema = ezcDbSchema::createFromFile('xml', $this->testFilesDir . '/webbuilder.schema.xml'); return $schema; }
private function loadSchemas() { $schema = ezcDbSchema::createFromFile('array', dirname(__FILE__) . "/files/all-types.dba"); $schema->writeToDb($this->dbh); }