本文整理汇总了PHP中MDB2_Schema类的典型用法代码示例。如果您正苦于以下问题:PHP MDB2_Schema类的具体用法?PHP MDB2_Schema怎么用?PHP MDB2_Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MDB2_Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: alterDatabaseActionTable
function alterDatabaseActionTable()
{
$this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()));
$prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
OA_DB::setCaseSensitive();
$aPrev = $this->oSchema->getDefinitionFromDatabase(array($prefix . 'database_action'));
OA_DB::disableCaseSensitive();
$aCurr = $this->_getLatestDatabaseActionSchema($prefix);
$aChanges = $this->oSchema->compareDefinitions($aCurr, $aPrev);
if (is_array($aChanges) && count($aChanges) > 0) {
if (isset($aChanges['tables']['change'][$prefix . 'database_action'])) {
if (isset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['add']['database_action_pkey'])) {
unset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['add']['database_action_pkey']);
unset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['change']);
}
if (isset($aChanges['tables']['change'][$prefix . 'database_action']['add']['database_action_id'])) {
$result = $this->oSchema->alterDatabase($aCurr, $aPrev, $aChanges);
if (PEAR::isError($result)) {
$this->oUpgrade->oLogger->logError($result->getUserInfo());
return false;
}
$this->oUpgrade->oLogger->log('database_action table schema successfully upgraded');
return true;
}
}
}
$this->oUpgrade->oLogger->log('database_action table schema upgrade unnecessary');
return true;
}
示例2: __construct
/**
* The constructor method.
*/
function __construct()
{
parent::__construct();
$this->oDbh = OA_DB::singleton();
$this->oCache = new OA_DB_XmlCache();
$this->oSchema =& MDB2_Schema::factory($this->oDbh, array('force_defaults' => false));
}
示例3: init
/**
* verify the input file
* instantiate the schema and table objects
*
* @param string $datafile
* @param string $directory
* @return boolean
*/
function init($datafile = 'fjsdj', $directory = '/tests/datasets/mdb2schema/')
{
if (!parent::init()) {
return false;
}
if (!$directory) {
$directory = '/tests/datasets/mdb2schema/';
}
$this->directory = $directory;
if (substr_count($this->directory, MAX_PATH) < 1) {
$this->directory = MAX_PATH . $this->directory;
}
$this->datafile = $datafile;
if (!file_exists($this->directory . $this->datafile)) {
return false;
}
$this->oSchema =& MDB2_Schema::factory($this->oDbh);
if (PEAR::isError($this->oSchema)) {
return false;
}
$this->oTable = new OA_DB_Table();
if (PEAR::isError($this->oTable)) {
return false;
}
return true;
}
示例4: Test_OA_DB_XmlCache
/**
* The constructor method.
*/
function Test_OA_DB_XmlCache()
{
$this->UnitTestCase();
$this->oDbh = OA_DB::singleton();
$this->oCache = new OA_DB_XmlCache();
$this->oSchema =& MDB2_Schema::factory($this->oDbh, array('force_defaults' => false));
}
示例5: removeDashboardColumns
function removeDashboardColumns()
{
$this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()));
$prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
$table = 'preference';
$aColumns = array('ad_clicks_sum', 'ad_views_sum', 'ad_clicks_per_second', 'ad_views_per_second', 'ad_cs_data_last_sent', 'ad_cs_data_last_sent', 'ad_cs_data_last_received');
OA_DB::setCaseSensitive();
$aDef = $this->oSchema->getDefinitionFromDatabase(array($prefix . $table));
OA_DB::disableCaseSensitive();
if (is_array($aDef) && count($aDef) > 0) {
$aTask['remove'] = array();
if (isset($aDef['tables'][$prefix . $table])) {
foreach ($aColumns as $column) {
if (isset($aDef['tables'][$prefix . $table]['fields'][$column])) {
$aTask['remove'][$column] = array();
$this->oUpgrade->oLogger->logOnly("preference.{$column} found");
}
}
}
if (count($aTask['remove'] > 0)) {
$result = $this->oSchema->db->manager->alterTable($prefix . $table, $aTask, false);
}
}
$this->oUpgrade->oLogger->logOnly('preference table schema upgrade for dashboard unnecessary');
return true;
}
示例6: setUp
function setUp()
{
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchErrorHandlerPEAR');
$this->dsn = $GLOBALS['dsn'];
$this->options = $GLOBALS['options'];
$this->database = $GLOBALS['database'];
$this->dsn['database'] = $this->database;
$this->schema =& MDB2_Schema::factory($this->dsn, $this->options);
if (PEAR::isError($this->schema)) {
$this->assertTrue(false, 'Could not connect to manager in setUp');
exit;
}
}
示例7: setUpDatabase
function setUpDatabase()
{
// Create a new test table, overwriting old ones.
require_once 'MDB2/Schema.php';
$config = $this->getDriverConfig();
$manager = MDB2_Schema::factory($config['params']);
$defs = $manager->parseDatabaseDefinition(dirname(dirname(__DIR__)) . '/scripts/sql/test.xml', false, array('name' => $config['params']['database']), false);
$result = $manager->createTable('hordetest_turba_objects', $defs['tables']['hordetest_turba_objects'], true);
$this->assertOk($result);
foreach ($this->_fixtures as $fixture) {
$this->assertOk($this->_insert($fixture));
}
}
示例8: setUp
function setUp()
{
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchErrorHandlerPEAR');
$this->dsn = $GLOBALS['dsn'];
$this->options = $GLOBALS['options'];
$this->database = $GLOBALS['database'];
$this->dsn['database'] = $this->database;
$this->schema =& MDB2_Schema::factory($this->dsn, $this->options);
if (PEAR::isError($this->schema)) {
$this->assertTrue(false, 'Could not connect to manager in setUp');
exit;
}
$this->aSchemas = array(1 => SCHEMA_PATH . 'schema_1_original.xml', 2 => SCHEMA_PATH . 'schema_2_newfield.xml', 3 => SCHEMA_PATH . 'schema_3_primarykey.xml', 4 => SCHEMA_PATH . 'schema_4_idxfieldorder.xml', 5 => SCHEMA_PATH . 'schema_5_fieldtype.xml', 6 => SCHEMA_PATH . 'schema_6_removefield.xml', 7 => SCHEMA_PATH . 'schema_7_removeindex.xml', 8 => SCHEMA_PATH . 'schema_8_addtable.xml', 9 => SCHEMA_PATH . 'schema_9_removetable.xml', 10 => SCHEMA_PATH . 'schema_10_keyfield.xml');
}
示例9: setUp
function setUp()
{
$this->dsn = $GLOBALS['dsn'];
$this->options = $GLOBALS['options'];
$this->database = $GLOBALS['database'];
$backup_file = $this->driver_input_file . $this->backup_extension;
if (file_exists($backup_file)) {
unlink($backup_file);
}
$backup_file = $this->lob_input_file . $this->backup_extension;
if (file_exists($backup_file)) {
unlink($backup_file);
}
$this->schema =& MDB2_Schema::factory($this->dsn, $this->options);
if (PEAR::isError($this->schema)) {
$this->assertTrue(false, 'Could not connect to manager in setUp');
exit;
}
}
示例10: generateXmlCache
function generateXmlCache($xmlFiles, $callback = 'parseDatabaseDefinitionFile')
{
global $aSkipFiles, $aOptions, $oDbh, $oCache;
foreach ($xmlFiles as $fileName) {
if (!in_array(baseName($fileName), $aSkipFiles)) {
echo " => " . basename($fileName) . ": ";
flush();
$oSchema =& MDB2_Schema::factory($oDbh, $aOptions);
$result = $oSchema->{$callback}($fileName, true);
if (PEAR::isError($result)) {
clean_up();
die("Failed\n");
} else {
$oCache->save($result, $fileName);
echo "Processed";
eol_flush();
}
unset($result);
}
}
}
示例11: setUp
function setUp()
{
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchErrorHandlerPEAR');
$this->dsn = $GLOBALS['dsn'];
$this->options = $GLOBALS['options'];
$this->database = $GLOBALS['database'];
$this->dsn['database'] = $this->database;
$backup_file = SCHEMA_PATH . $this->driver_input_file . $this->backup_extension;
if (file_exists($backup_file)) {
unlink($backup_file);
}
$backup_file = SCHEMA_PATH . $this->lob_input_file . $this->backup_extension;
if (file_exists($backup_file)) {
unlink($backup_file);
}
$this->schema =& MDB2_Schema::factory($this->dsn, $this->options);
if (PEAR::isError($this->schema)) {
$this->assertTrue(false, 'Could not connect to manager in setUp');
exit;
}
}
示例12: connectScheme
/**
* @brief connects to a MDB2 database scheme
* @returns true/false
*
* Connects to a MDB2 database scheme
*/
private static function connectScheme()
{
// We need a mdb2 database connection
self::connectMDB2();
self::$MDB2->loadModule('Manager');
self::$MDB2->loadModule('Reverse');
// Connect if this did not happen before
if (!self::$schema) {
require_once 'MDB2/Schema.php';
self::$schema = MDB2_Schema::factory(self::$MDB2);
}
return true;
}
示例13: __construct
/**
* php5 class constructor
*
* @param string The XML schema file we are working on
*/
function __construct($file_schema = 'tables_core.xml', $file_changes = '', $path_schema)
{
$this->oLogger = new OA_UpgradeLogger();
$this->oLogger->setLogFile('schema.log');
if (empty($path_schema)) {
$path_schema = '/etc/';
}
if (!empty($path_schema) && substr($path_schema, 0, 1) != '/') {
$path_schema = '/' . $path_schema;
}
if (!empty($path_schema) && substr($path_schema, strlen($path_schema) - 4, 4) != 'etc/') {
$path_schema = $path_schema . 'etc/';
}
$this->path_schema_final = MAX_PATH . $path_schema;
$this->path_schema_trans = MAX_PATH . '/var/';
$this->path_changes_final = MAX_PATH . $path_schema . 'changes/';
$this->path_changes_trans = MAX_PATH . '/var/';
if ($path_schema == '/etc/') {
$this->path_dbo = MAX_PATH . '/lib/max/Dal/DataObjects/';
} else {
$this->path_dbo = $this->path_schema_final . 'DataObjects/';
}
//$this->path_links_final = MAX_PATH.'/lib/max/Dal/DataObjects/';
$this->path_links_final = $this->path_dbo;
$this->path_links_trans = MAX_PATH . '/var/';
$file_changes = $file_changes ? $file_changes : 'changes_' . $file_schema;
$file_links = 'db_schema.links.ini';
$this->schema_final = $this->path_schema_final . $file_schema;
$this->schema_trans = $this->path_schema_trans . $file_schema;
$this->oLogger->log($this->schema_final);
$this->use_links = $file_schema == 'tables_core.xml';
if ($this->use_links) {
$this->links_final = $this->path_links_final . $file_links;
$this->links_trans = $this->path_links_trans . $file_links;
}
$this->changes_final = $this->path_changes_final . $file_changes;
$this->changes_trans = $this->path_changes_trans . $file_changes;
$this->oLogger->log($this->changes_final);
if ($this->use_links) {
$this->aFile_perms = array($this->path_schema_trans, $this->path_changes_final, $this->path_changes_trans, $this->path_links_trans, $this->links_final, $this->schema_final, MAX_SCHEMA_LOG, MAX_PATH . '/www/devel/');
} else {
$this->aFile_perms = array($this->path_schema_trans, $this->path_changes_final, $this->path_changes_trans, $this->schema_final, MAX_SCHEMA_LOG, MAX_PATH . '/www/devel/');
}
$this->aDump_options = array('output_mode' => 'file', 'output' => $this->schema_trans, 'end_of_line' => "\n", 'xsl_file' => "xsl/mdb2_schema.xsl", 'custom_tags' => array('version' => '', 'status' => 'transitional'));
$this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn()), $this->aDump_options);
$this->dd_file = 'etc/dd.generic.xml';
$this->aDD_definition = $this->oSchema->parseDictionaryDefinitionFile($this->dd_file);
ksort($this->aDD_definition);
//$this->aXMLRPCServer = array('path'=>'/upms/xmlrpc.php', 'host'=>'localhost','port'=>'80');
}
示例14: initializeDatabase
/**
* Create or upgrade the database needed for pearweb
*
* This helper function scans for previous database versions,
* and upgrades the database based on differences between the
* previous version's schema and the one distributed with this
* version.
*
* If the database has never been created, then it is created.
*
* @param array $answers
* @return boolean
*/
function initializeDatabase($answers)
{
$this->dsn = array('phptype' => $answers['driver'], 'username' => $answers['user'], 'password' => $answers['password'], 'hostspec' => $answers['host'], 'database' => $answers['database']);
$a = MDB2_Schema::factory($this->dsn, array('idxname_format' => '%s', 'seqname_format' => 'id', 'quote_identifier' => true));
// for upgrade purposes
if (!file_exists('@www-dir@' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . '.pearweb-upgrade')) {
if (!mkdir('@www-dir@' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . '.pearweb-upgrade')) {
$this->_ui->outputData('error - make sure we can create directories');
return false;
}
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$c = $a->parseDatabaseDefinitionFile(realpath('@www-dir@/sql/pearweb_mdb2schema.xml'));
PEAR::staticPopErrorHandling();
if (PEAR::isError($c)) {
$extra = '';
if (MDB2_Schema::isError($c) || MDB2::isError($c)) {
$extra = "\n" . $c->getUserInfo();
}
$this->_ui->outputData('ERROR: ' . $c->getMessage() . $extra);
return false;
}
$c['name'] = $answers['database'];
$c['create'] = 1;
$c['overwrite'] = 0;
$dir = opendir('@www-dir@/sql/.pearweb-upgrade');
$oldversion = false;
while (false !== ($entry = readdir($dir))) {
if ($entry[0] === '.') {
continue;
}
if (strpos($entry, $answers['database']) === 0) {
// this is one of ours
// strip databasename-
$entry = substr($entry, strlen($answers['database']) + 1);
// strip ".ser"
$entry = substr($entry, 0, strlen($entry) - 4);
// ... and we're left with just the version
if (!$oldversion) {
$oldversion = $entry;
continue;
}
if (version_compare($entry, $oldversion, '>')) {
$oldversion = $entry;
}
}
}
if (!file_exists('@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-@version@.ser')) {
$fp = fopen('@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-@version@.ser', 'w');
fwrite($fp, serialize($c));
fclose($fp);
}
if ($oldversion == '@version@') {
// this is where to change if we need to add a "force upgrade of
// structure" option
// we would uncomment the following line:
//$c['overwrite'] = true;
$oldversion = false;
}
if ($oldversion) {
$curdef = unserialize(file_get_contents('@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-' . $oldversion . '.ser'));
if (!is_array($curdef)) {
$this->_ui->outputData('invalid data returned from previous version');
}
// get a database diff (MDB2_Schema is very useful here)
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$c = $a->compareDefinitions($c, $curdef);
if (PEAR::isError($c)) {
$this->_ui->outputData($err->getMessage());
$this->_ui->outputData($err->getUserInfo());
$this->_ui->outputData('Unable to automatically update database');
return false;
}
$err = $a->updateDatabase($curdef, $c);
PEAR::staticPopErrorHandling();
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $a->createDatabase($c);
PEAR::staticPopErrorHandling();
}
if (PEAR::isError($err)) {
$this->_ui->outputData($err->getUserInfo());
$this->_ui->outputData($err->getMessage());
return false;
}
return true;
}
示例15: doInit
/**
* Initializes a database with data
*
* @param array $args Command line arguments
*
* @return void
*/
protected function doInit($args)
{
list($typeSource, $dsnSource) = $this->getFileOrDsn($args);
list($typeDest, $dsnDest) = $this->getFileOrDsn($args);
if ($typeSource != 'file') {
throw new MDB2_Schema_Tool_ParameterException('Data must come from a source file');
}
if ($typeDest != 'dsn') {
throw new MDB2_Schema_Tool_ParameterException('A schema can only be loaded into a database, not a file');
}
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
$this->throwExceptionOnError($schemaDest, 'connecting to destination database');
$definition = $schemaDest->getDefinitionFromDatabase();
$this->throwExceptionOnError($definition, 'loading definition from database');
$op = $schemaDest->writeInitialization($dsnSource, $definition);
$this->throwExceptionOnError($op, 'initializing database');
}