This class is used to load and parse the XML file, to create an array of SQL statements that can be used to build a database, and to build the database using the SQL array.
示例#1
0
function create_table($schemaFile, $prefix, $db, $drop = true)
{
    $result = array();
    $schema = new adoSchema($db);
    $schema->setPrefix($prefix);
    $sql = $schema->ParseSchema($schemaFile);
    $dbTable = $schema->obj;
    $adoDB = $schema->db;
    $stmt = sprintf($adoDB->_dropSeqSQL, $dbTable->name);
    $dropresult = true;
    if ($drop) {
        $ok = $db->Execute($stmt);
        if (!$ok) {
            $dropresult = false;
        }
        $schema = new adoSchema($db);
        $schema->setPrefix($prefix);
        $sql = $schema->ParseSchema($schemaFile);
    }
    $result = $schema->ExecuteSchema($sql);
    ob_start();
    print_r($sql);
    $sql_r = ob_get_contents();
    ob_end_clean();
    return array('result' => $result, 'sql' => $sql_r);
}
 /**
  * Parse an XML database file and output the corresponding SQL statements.
  * See lib/pkp/dtd/xmlSchema.dtd for the format of the XML files.
  */
 function execute()
 {
     require_once './lib/pkp/lib/adodb/adodb-xmlschema.inc.php';
     if (in_array($this->command, array('print', 'save'))) {
         // Don't connect to actual database (so parser won't build upgrade XML)
         $conn = new DBConnection(Config::getVar('database', 'driver'), null, null, null, null, true, Config::getVar('i18n', 'connection_charset'));
         $dbconn = $conn->getDBConn();
     } else {
         // Create or upgrade existing database
         $dbconn =& DBConnection::getConn();
     }
     $schema = new adoSchema($dbconn);
     $dict =& $schema->dict;
     $dict->SetCharSet(Config::getVar('i18n', 'database_charset'));
     if ($this->type == 'schema') {
         // Parse XML schema files
         $sql = $schema->parseSchema($this->inputFile);
         switch ($this->command) {
             case 'execute':
                 $schema->ExecuteSchema();
                 break;
             case 'save':
             case 'save_upgrade':
                 $schema->SaveSQL($this->outputFile);
                 break;
             case 'print':
             case 'print_upgrade':
             default:
                 echo @$schema->PrintSQL('TEXT') . "\n";
                 break;
         }
     } else {
         if ($this->type == 'data') {
             // Parse XML data files
             $dataXMLParser = new DBDataXMLParser();
             $dataXMLParser->setDBConn($dbconn);
             $sql = $dataXMLParser->parseData($this->inputFile);
             switch ($this->command) {
                 case 'execute':
                     $schema->addSQL($sql);
                     $schema->ExecuteSchema();
                     break;
                 case 'save':
                 case 'save_upgrade':
                     $schema->addSQL($sql);
                     $schema->SaveSQL($this->outputFile);
                     break;
                 case 'print':
                 case 'print_upgrade':
                 default:
                     $schema->addSQL($sql);
                     echo @$schema->PrintSQL('TEXT') . "\n";
                     break;
             }
             $schema->destroy();
             $dataXMLParser->destroy();
         }
     }
 }
示例#3
0
/**
 * Generates the SQL commands necessary to create all tables
 * @param string $db_type Database type for which to generate SQL 
 * @return array Array of SQL commands or false if error
 */
function GetTableCreationSQL($db_type, $tbl_prefix)
{
    $db = NewAdoConnection($db_type);
    $schema = new adoSchema($db);
    $schema->setPrefix($tbl_prefix);
    if ($sql = $schema->ParseSchema('create.xml')) {
        return $sql;
    } else {
        return false;
    }
}
示例#4
0
 function perform()
 {
     if (empty($this->loop)) {
         $this->loop = 1;
     }
     if ($this->prepareParameters() === FALSE) {
         $this->result = INSTALLER_ACTION_FAIL;
         return $this->result;
     }
     if (!is_readable($this->schema_file)) {
         $this->result = INSTALLER_ACTION_FAIL;
         $this->result_message = "Could not read file sql {$this->schema_file}.";
         $this->loop = 2;
         return $this->result;
     }
     # Connect to the DB
     $db = $this->connect();
     if ($db === FALSE) {
         return $this->result;
     }
     # Create empty ADOdb connection
     $conn = ADONewConnection($this->type);
     # Create new ADO Schema object
     $schema = new adoSchema($conn);
     # Build the SQL query from the Schema file
     $sql = $schema->ParseSchema($this->schema_file);
     # Execute the SQL query
     # "2" is status returned by ExecuteSQLArray()
     $dict = NewDataDictionary($db);
     @($ok = 2 == $dict->ExecuteSQLArray($sql, FALSE));
     if ($ok) {
         $this->result = INSTALLER_ACTION_SUCCESS;
         $this->result_message = "DB schema loaded successfully";
         $this->loop = 3;
     } else {
         $this->result = INSTALLER_ACTION_FAIL;
         $this->result_message = "Errors on execution of the schema SQL: " . $db->ErrorMsg();
         $this->loop = 2;
     }
     return $this->result;
 }
示例#5
0
文件: index.php 项目: roycocup/Tests
<?php

require '../adodb/adodb5/adodb.inc.php';
require '../adodb/adodb5/adodb-xmlschema.inc.php';
$_server = "IMAGESERVER,1433";
$_dbServer = "3170-090204";
$_dbServer = "disney-live";
$_dbUsername = "******";
$_dbPassword = "******";
$dsn = "Driver={SQL Server};Server=" . $_server . ";Database=" . $_dbServer . ";";
$db =& NewADOConnection('odbc_mssql');
$db->Connect($dsn, $_dbUsername, $_dbPassword);
$dict = NewDataDictionary($db);
$schema = new adoSchema($db);
$ext = $schema->ExtractSchema(true);
//print_r($ext); die;
示例#6
0
function adodb_session_create_table($schemaFile = null, $conn = null)
{
    // set default values
    if ($schemaFile === null) {
        $schemaFile = ADODB_SESSION . '/session_schema.xml';
    }
    if ($conn === null) {
        $conn =& ADODB_Session::_conn();
    }
    if (!$conn) {
        return 0;
    }
    $schema = new adoSchema($conn);
    $schema->ParseSchema($schemaFile);
    return $schema->ExecuteSchema();
}
示例#7
0
 /**
  * Execute a single installer action.
  * @param $action array
  * @return boolean
  */
 function executeAction($action)
 {
     switch ($action['type']) {
         case 'schema':
             $fileName = $action['file'];
             $this->log(sprintf('schema: %s', $action['file']));
             require_once './lib/pkp/lib/adodb/adodb-xmlschema.inc.php';
             $schemaXMLParser = new adoSchema($this->dbconn);
             $dict =& $schemaXMLParser->dict;
             $dict->SetCharSet($this->dbconn->charSet);
             $sql = $schemaXMLParser->parseSchema($fileName);
             $schemaXMLParser->destroy();
             if ($sql) {
                 return $this->executeSQL($sql);
             } else {
                 $this->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $fileName, __('installer.installParseDBFileError')));
                 return false;
             }
             break;
         case 'data':
             $fileName = $action['file'];
             $condition = isset($action['attr']['condition']) ? $action['attr']['condition'] : null;
             $includeAction = true;
             if ($condition) {
                 $funcName = create_function('$installer,$action', $condition);
                 $includeAction = $funcName($this, $action);
             }
             $this->log('data: ' . $action['file'] . ($includeAction ? '' : ' (skipped)'));
             if (!$includeAction) {
                 break;
             }
             $sql = $this->dataXMLParser->parseData($fileName);
             // We might get an empty SQL if the upgrade script has
             // been executed before.
             if ($sql) {
                 return $this->executeSQL($sql);
             }
             break;
         case 'code':
             $condition = isset($action['attr']['condition']) ? $action['attr']['condition'] : null;
             $includeAction = true;
             if ($condition) {
                 $funcName = create_function('$installer,$action', $condition);
                 $includeAction = $funcName($this, $action);
             }
             $this->log(sprintf('code: %s %s::%s' . ($includeAction ? '' : ' (skipped)'), isset($action['file']) ? $action['file'] : 'Installer', isset($action['attr']['class']) ? $action['attr']['class'] : 'Installer', $action['attr']['function']));
             if (!$includeAction) {
                 return true;
             }
             // Condition not met; skip the action.
             if (isset($action['file'])) {
                 require_once $action['file'];
             }
             if (isset($action['attr']['class'])) {
                 return call_user_func(array($action['attr']['class'], $action['attr']['function']), $this, $action['attr']);
             } else {
                 return call_user_func(array(&$this, $action['attr']['function']), $this, $action['attr']);
             }
             break;
         case 'note':
             $condition = isset($action['attr']['condition']) ? $action['attr']['condition'] : null;
             $includeAction = true;
             if ($condition) {
                 $funcName = create_function('$installer,$action', $condition);
                 $includeAction = $funcName($this, $action);
             }
             if (!$includeAction) {
                 break;
             }
             $this->log(sprintf('note: %s', $action['file']));
             $this->notes[] = join('', file($action['file']));
             break;
     }
     return true;
 }
示例#8
0
 /**
  * Called during the install process to install the plugin schema,
  * if applicable.
  * @param $hookName string
  * @param $args array
  * @return boolean
  */
 function updateSchema($hookName, $args)
 {
     $installer =& $args[0];
     $result =& $args[1];
     $schemaXMLParser = new adoSchema($installer->dbconn);
     $dict =& $schemaXMLParser->dict;
     $dict->SetCharSet($installer->dbconn->charSet);
     $sql = $schemaXMLParser->parseSchema($this->getInstallSchemaFile());
     if ($sql) {
         $result = $installer->executeSQL($sql);
     } else {
         $installer->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $this->getInstallSchemaFile(), __('installer.installParseDBFileError')));
         $result = false;
     }
     return false;
 }
示例#9
0
文件: install.php 项目: edt82/ona
                    $status++;
                    $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to create system user '{$sys_login}'.<br><span style='font-size: xx-small;'>" . $db->ErrorMsg() . "</span><br>";
                    printmsg("ERROR => There was an error creating DB user: "******"1.0"?>
<schema version="0.3">
<sql>
    <query>INSERT INTO domains (id,name,admin_email,default_ttl,refresh,retry,expiry,minimum) VALUES (1,'{$default_domain}','hostmaster', 86400, 86400, 3600, 3600, 3600)</query>
    <query>UPDATE sys_config SET value='{$default_domain}' WHERE name like 'dns_defaultdomain'</query>
</sql>
</schema>
EOL;
                $schema = new adoSchema($db);
                // Build the SQL array from the schema XML file
                $domainsql = $schema->ParseSchemaString($xmldefdomain);
                // Execute the SQL on the database
                if ($schema->ExecuteSchema($domainsql) == 2) {
                    $text .= "<img src=\"{$images}/silk/accept.png\" border=\"0\" /> Created default DNS domain '{$default_domain}'.<br>";
                } else {
                    $status++;
                    $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to create default DNS domain '{$default_domain}'.<br><span style='font-size: xx-small;'>" . $db->ErrorMsg() . "</span><br>";
                }
                // Open the database config and write the contents to it.
                if (!($fh = @fopen($dbconffile, 'w'))) {
                    $status++;
                    $text .= "<img src=\"{$images}/silk/exclamation.png\" border=\"0\" /> Failed to open config file for writing: '{$dbconffile}'.<br>";
                } else {
                    fwrite($fh, "<?php\n\n\$ona_contexts=" . var_export($ona_contexts, TRUE) . ";\n\n?>");
示例#10
0
function execute_upgrade_file($folder, $installed_version)
{
    global $db, $page, $conf;
    // At first the config file
    $upgrade_path = BASEDIR . '/upgrade/' . $folder;
    new ConfUpdater(CONFIG_PATH, $upgrade_path);
    $upgrade_info = parse_ini_file($upgrade_path . '/upgrade.info', true);
    // dev version upgrade?
    if ($folder == Flyspray::base_version($installed_version)) {
        $type = 'develupgrade';
    } else {
        $type = 'defaultupgrade';
    }
    // Next a mix of XML schema files and PHP upgrade scripts
    if (!isset($upgrade_info[$type])) {
        die('#1 Bad upgrade.info file.');
    }
    ksort($upgrade_info[$type]);
    foreach ($upgrade_info[$type] as $file) {
        if (substr($file, -4) == '.php') {
            require_once $upgrade_path . '/' . $file;
        }
        if (substr($file, -4) == '.xml') {
            $schema = new adoSchema($db->dblink);
            $xml = file_get_contents($upgrade_path . '/' . $file);
            // $xml = str_replace('<table name="', '<table name="' . $conf['database']['dbprefix'], $xml);
            // Set the prefix for database objects ( before parsing)
            $schema->setPrefix($conf['database']['dbprefix'], false);
            $schema->ParseSchemaString($xml);
            $schema->ExecuteSchema(null, true);
        }
    }
    // Last but not least global prefs update
    if (isset($upgrade_info['fsprefs'])) {
        $sql = $db->Query('SELECT pref_name FROM {prefs}');
        $existing = $db->FetchCol($sql);
        // Add what is missing
        foreach ($upgrade_info['fsprefs'] as $name => $value) {
            if (!in_array($name, $existing)) {
                $db->Query('INSERT INTO {prefs} (pref_name, pref_value) VALUES (?, ?)', array($name, $value));
            }
        }
        // Delete what is too much
        foreach ($existing as $name) {
            if (!isset($upgrade_info['fsprefs'][$name])) {
                $db->Query('DELETE FROM {prefs} WHERE pref_name = ?', array($name));
            }
        }
    }
    $db->Query('UPDATE {prefs} SET pref_value = ? WHERE pref_name = ?', array(basename($upgrade_path), 'fs_ver'));
    #$page->assign('done', true);
    return "Write " . basename($upgrade_path) . " into table {prefs} fs_ver in database";
}
示例#11
0
 function createTables($schemaFile, $dbHostName = false, $userName = false, $userPassword = false, $dbName = false, $dbType = false)
 {
     $this->println("ADODB createTables " . $schemaFile);
     if ($dbHostName != false) {
         $this->dbHostName = $dbHostName;
     }
     if ($userName != false) {
         $this->userName = $userPassword;
     }
     if ($userPassword != false) {
         $this->userPassword = $userPassword;
     }
     if ($dbName != false) {
         $this->dbName = $dbName;
     }
     if ($dbType != false) {
         $this->dbType = $dbType;
     }
     //$db = ADONewConnection($this->dbType);
     $this->checkConnection();
     $db = $this->database;
     //$db->debug = true;
     //$this->println("ADODB createTables connect status=".$db->Connect($this->dbHostName, $this->userName, $this->userPassword, $this->dbName));
     $schema = new adoSchema($db);
     //Debug Adodb XML Schema
     $sehema->XMLS_DEBUG = TRUE;
     //Debug Adodb
     $sehema->debug = true;
     $sql = $schema->ParseSchema($schemaFile);
     $this->println("--------------Starting the table creation------------------");
     //$this->println($sql);
     //integer ExecuteSchema ([array $sqlArray = NULL], [boolean $continueOnErr = NULL])
     $result = $schema->ExecuteSchema($sql, $this->continueInstallOnError);
     //if($result) print $db->errorMsg();
     $this->println("ADODB createTables error: " . $db->errorMsg());
     // needs to return in a decent way
     $this->println("ADODB createTables " . $schemaFile . " status=" . $result);
     return $result;
 }
示例#12
0
<?php

error_reporting(E_ALL);
die('Enable me by commenting this out by editing ' . basename(__FILE__) . ' at line ' . __LINE__);
require_once '../vendor/adodb/adodb-php/adodb.inc.php';
require_once '../vendor/adodb/adodb-php/adodb-xmlschema03.inc.php';
$conf = @parse_ini_file('../flyspray.conf.php', true) or die('Cannot open config file.');
/* Start by creating a normal ADODB connection. */
$db = ADONewConnection($conf['database']['dbtype']);
$db->Connect($conf['database']['dbhost'], $conf['database']['dbuser'], $conf['database']['dbpass'], $conf['database']['dbname']) or die('Cannot connect to DB.');
$db->debug = true;
/* Use the database connection to create a new adoSchema object. */
$schema = new adoSchema($db);
$withdata = false;
$stripprefix = true;
$data = $schema->ExtractSchema($withdata, '  ', $conf['database']['dbprefix'], $stripprefix);
file_put_contents('flyspray-schema.xml', $data);
示例#13
0
文件: DB.php 项目: uzerpllp/uzerp
 function extractSchema()
 {
     $schema = new adoSchema($this->db);
     return $schema->extractSchema();
 }
示例#14
0
<?php

require "path_to_adodb/adodb-xmlschema.inc.php";
// To build the schema, start by creating a normal ADOdb connection:
$db = ADONewConnection('mysql');
$db->Connect('localhost', 'someuser', '', 'schematest');
// Create the schema object and build the query array.
$schema = new adoSchema($db);
// Build the SQL array
$sql = $schema->ParseSchema("example.xml");
print "Here's the SQL to do the build:\n";
print_r($sql);
print "\n";
// Execute the SQL on the database
$result = $schema->ExecuteSchema($sql);
// Finally, clean up after the XML parser
// (PHP won't do this for you!)
$schema->Destroy();
示例#15
0
    <td colspan="2" valign="top">
<?php 
    include_once "../adodb-xmlschema.inc.php";
    echo "<h1>Test XML Schema</h1>";
    $ff = file('xmlschema.xml');
    echo "<pre>";
    foreach ($ff as $xml) {
        echo htmlspecialchars($xml);
    }
    echo "</pre>";
    $db = NewADOConnection('mysql', "pear");
    if ($_POST['create_test']) {
        $db->Connect($_POST['dbhost'], $_POST['dbusername'], $_POST['dbpassword'], $_POST['databasename']);
    }
    // To create a schema object and build the query array.
    $schema = new adoSchema($db);
    // To upgrade an existing schema object, use the following
    // To upgrade an existing database to the provided schema,
    // uncomment the following line:
    #$schema->upgradeSchema();
    print "<b>SQL to build xmlschema.xml</b>:\n<pre>";
    // Build the SQL array
    $sql = $schema->ParseSchema("xmlschema.xml");
    print_r($sql);
    print "</pre>\n";
    // Execute the SQL on the database
    $db->debug = true;
    if ($_POST['create_test']) {
        print "<pre><hr>\n";
        $result = $schema->ExecuteSchema($sql);
        print "</pre>\n";
示例#16
0
                echo_failed("Database \"<b>{$db_name}</b>\" could not be created, please do so manually.");
            } else {
                echo_success("Good, database \"<b>{$db_name}</b>\" has been created!!");
                //Reconnect. Hrmm, this is kinda weird.
                $db->Connect($db_host, $db_user, $db_password, $db_name);
            }
        }
        break;
    default:
        echo_normal("Sorry, <b>setup.php</b> currently does not fully support \"<b>{$db_type}</b>\" databases.\n\t\t\t\t\t<br>I'm assuming you've already created the database \"{$db_name}\", attempting to create tables.\n\t\t\t\t\t<br> Please email <b>{$author_email}</b> code to detect if a database is created or not so full support for \"<b>{$db_type}</b>\" can be added.");
}
/*
 * Attempt to create tables
 */
// Create the schema object and build the query array.
$schema = new adoSchema($db);
$schema->SetPrefix($db_table_prefix);
// Build the SQL array
$schema->ParseSchema('schema.xml');
// maybe display this if $gacl->debug is true?
if ($gacl->_debug) {
    print "Here's the SQL to do the build:<br />\n<code>";
    print $schema->getSQL('html');
    print "</code>\n";
    // exit;
}
// Execute the SQL on the database
#ADODB's xmlschema is being lame, continue on error.
$schema->ContinueOnError(TRUE);
$result = $schema->ExecuteSchema();
if ($result != 2) {
示例#17
0
<?php

error_reporting(E_ALL);
require_once '../adodb/adodb.inc.php';
require_once '../adodb/adodb-xmlschema03.inc.php';
$conf = @parse_ini_file('../flyspray.conf.php', true) or die('Cannot open config file.');
/* Start by creating a normal ADODB connection.
 */
$db = ADONewConnection($conf['database']['dbtype']);
$db->Connect($conf['database']['dbhost'], $conf['database']['dbuser'], $conf['database']['dbpass'], $conf['database']['dbname']) or die('Cannot connect to DB.');
$db->debug = true;
/* Use the database connection to create a new adoSchema object.
 */
$schema = new adoSchema($db);
$data = $schema->ExtractSchema();
$data = str_replace('flyspray_', '', $data);
file_put_contents('flyspray-schema.xml', $data);
示例#18
0
 /**
  * Execute a single installer action.
  * @param $action array
  * @return boolean
  */
 function executeAction($action)
 {
     switch ($action['type']) {
         case 'schema':
             $fileName = $action['file'];
             $this->log(sprintf('schema: %s', $action['file']));
             require_once 'adodb-xmlschema.inc.php';
             $schemaXMLParser = new adoSchema($this->dbconn);
             $dict =& $schemaXMLParser->dict;
             $dict->SetCharSet($this->dbconn->charSet);
             $sql = $schemaXMLParser->parseSchema($fileName);
             $schemaXMLParser->destroy();
             if ($sql) {
                 return $this->executeSQL($sql);
             } else {
                 $this->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $fileName, __('installer.installParseDBFileError')));
                 return false;
             }
             break;
         case 'data':
             $fileName = $action['file'];
             $this->log(sprintf('data: %s', $action['file']));
             $sql = $this->dataXMLParser->parseData($fileName);
             if ($sql) {
                 return $this->executeSQL($sql);
             } else {
                 $this->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $fileName, __('installer.installParseDBFileError')));
                 return false;
             }
             break;
         case 'code':
             $this->log(sprintf('code: %s %s::%s', isset($action['file']) ? $action['file'] : 'Installer', isset($action['attr']['class']) ? $action['attr']['class'] : 'Installer', $action['attr']['function']));
             if (isset($action['file'])) {
                 require_once $action['file'];
             }
             if (isset($action['attr']['class'])) {
                 return call_user_func(array($action['attr']['class'], $action['attr']['function']), $this);
             } else {
                 return call_user_func(array(&$this, $action['attr']['function']));
             }
             break;
         case 'note':
             $this->log(sprintf('note: %s', $action['file']));
             $this->notes[] = join('', file($action['file']));
             break;
     }
     return true;
 }
示例#19
0
                echo_failed("Database \"<b>{$db_name}</b>\" could not be created, please do so manually.");
            } else {
                echo_success("Good, database \"<b>{$db_name}</b>\" has been created!!");
                //Reconnect. Hrmm, this is kinda weird.
                $db->Connect($db_host, $db_user, $db_password, $db_name);
            }
        }
        break;
    default:
        echo_normal("Sorry, <b>setup.php</b> currently does not fully support \"<b>{$db_type}</b>\" databases.\n\t\t\t\t\t<br>I'm assuming you've already created the database \"{$db_name}\", attempting to create tables.\n\t\t\t\t\t<br> Please email <b>{$author_email}</b> code to detect if a database is created or not so full support for \"<b>{$db_type}</b>\" can be added.");
}
/*
 * Attempt to create tables
 */
// Create the schema object and build the query array.
$schema = new adoSchema($db);
$schema->SetPrefix($db_table_prefix, FALSE);
//set $underscore == FALSE
// Build the SQL array
$schema->ParseSchema(AMP_BASE_INCLUDE_PATH . 'phpgacl/schema.xml');
// maybe display this if $gacl->debug is true?
//if ($gacl->_debug) {
print "Here's the SQL to do the build:<br />\n<code>";
print $schema->getSQL('html');
print "</code>\n";
// exit;
//}
// Execute the SQL on the database
#ADODB's xmlschema is being lame, continue on error.
$schema->ContinueOnError(TRUE);
$result = $schema->ExecuteSchema();
示例#20
0
<?php

include 'adodb.inc.php';
include 'adodb-xmlschema03.inc.php';
$db = ADONewConnection('mysqli');
$db->connect('localhost', 'root', 'C0yote71', 'apecove');
$xml = new adoSchema($db);
print $xml->extractSchema();
示例#21
0
                echo_failed("Database \"<b>{$db_name}</b>\" could not be created, please do so manually.");
            } else {
                echo_success("Good, database \"<b>{$db_name}</b>\" has been created!!");
                //Reconnect. Hrmm, this is kinda weird.
                $db->Connect($db_host, $db_user, $db_password, $db_name);
            }
        }
        break;
    default:
        echo_normal("Sorry, <b>setup.php</b> currently does not fully support \"<b>{$db_type}</b>\" databases.\n\t\t\t\t\t<br>I'm assuming you've already created the database \"{$db_name}\", attempting to create tables.\n\t\t\t\t\t<br> Please email <b>{$author_email}</b> code to detect if a database is created or not so full support for \"<b>{$db_type}</b>\" can be added.");
}
/*
 * Attempt to create tables
 */
// Create the schema object and build the query array.
$schema = new adoSchema($db);
$schema->SetPrefix($db_table_prefix, FALSE);
//set $underscore == FALSE
// Build the SQL array
$schema->ParseSchema(dirname(__FILE__) . '/schema.xml');
// maybe display this if $gacl->debug is true?
if ($gacl->_debug) {
    print "Here's the SQL to do the build:<br />\n<code>";
    print $schema->getSQL('html');
    print "</code>\n";
    // exit;
}
// Execute the SQL on the database
#ADODB's xmlschema is being lame, continue on error.
$schema->ContinueOnError(TRUE);
$result = $schema->ExecuteSchema();
// To build the schema, start by creating a normal ADOdb connection:
$db = ADONewConnection('mysql');
$db->Connect('localhost', 'root', '', 'test') || die('fail connect1');
// To create a schema object and build the query array.
$schema = new adoSchema($db);
// To upgrade an existing schema object, use the following
// To upgrade an existing database to the provided schema,
// uncomment the following line:
#$schema->upgradeSchema();
print "<b>SQL to build xmlschema.xml</b>:\n<pre>";
// Build the SQL array
$sql = $schema->ParseSchema("xmlschema.xml");
var_dump($sql);
print "</pre>\n";
// Execute the SQL on the database
//$result = $schema->ExecuteSchema( $sql );
// Finally, clean up after the XML parser
// (PHP won't do this for you!)
//$schema->Destroy();
print "<b>SQL to build xmlschema-mssql.xml</b>:\n<pre>";
$db2 = ADONewConnection('mssql');
$db2->Connect('', 'adodb', 'natsoft', 'northwind') || die("Fail 2");
$db2->Execute("drop table simple_table");
$schema = new adoSchema($db2);
$sql = $schema->ParseSchema("xmlschema-mssql.xml");
print_r($sql);
print "</pre>\n";
$db2->debug = 1;
foreach ($sql as $s) {
    $db2->Execute($s);
}
 function setupDDBB()
 {
     require_once $this->adodb_path . '/adodb.inc.php';
     require_once $this->adodb_path . '/adodb-xmlschema.inc.php';
     $bol_error = true;
     $int = 1;
     do {
         $SGBDs = $this->getAllSGBD();
         $select = $this->cli->prompt(agt('ddbbSGBD'), $SGBDs);
         $platform = $SGBDs[$select];
         $dbHost = $this->cli->prompt(agt('ddbbHost') . ': ');
         $dbUser = $this->cli->prompt(agt('ddbbUser') . ': ');
         $dbPassword = $this->cli->prompt(agt('ddbbPasswd') . ': ');
         $dbName = $this->cli->prompt(agt('ddbbName') . ': ');
         $db = ADONewConnection($platform);
         $db->Connect($dbHost, $dbUser, $dbPassword, $dbName);
         if (is_resource($db->_connectionID)) {
             $this->log(agt('ddbbConnOk'), 'success');
             $bol_error = false;
             break;
         } else {
             $this->log(agt('ddbbConnErr'), 'error');
         }
         $int++;
     } while ($int < 4);
     if ($bol_error) {
         return false;
     }
     $allDDBB = $db->MetaDatabases();
     if (!empty($allDDBB)) {
         if (in_array($dbName, $allDDBB)) {
             $this->log(agt('ddbbNameOk'), 'success');
         } else {
             $this->log(agt('ddbbNameErr'), 'warning');
             $this->log(agt('ddbbCreate'), 'warning');
             if (!$db->Execute("create database {$dbName}")) {
                 $this->cli->fatal(agt('ddbbCreateErr'));
             } else {
                 $this->log(agt('ddbbCreateOk'), 'success');
                 //Reconectamos
                 $db->Connect($dbHost, $dbUser, $dbPassword, $dbName);
             }
         }
     }
     $schemaFile = $this->miguel_path . '/' . $this->miguel_name . '/modules/common/include/miguel_schema.xml';
     if (file_exists($schemaFile)) {
         //Preparamos el proceso de creación de la BBDD
         $schema = new adoSchema($db);
         $sql = $schema->ParseSchema($schemaFile);
         $result = $schema->ExecuteSchema($sql, true);
         if ($result != 2) {
             $this->cli->fatal(agt('ddbbTableErr'));
         }
         $this->log(agt('ddbbTableOk'), 'success');
     } else {
         $this->cli->fatal(agt('fsErr'));
     }
     return true;
 }
示例#24
0
 function createTables($schemaFile, $dbHostName = false, $userName = false, $userPassword = false, $dbName = false, $dbType = false)
 {
     $this->println("ADODB createTables " . $schemaFile);
     if ($dbHostName != false) {
         $this->dbHostName = $dbHostName;
     }
     if ($userName != false) {
         $this->userName = $userPassword;
     }
     if ($userPassword != false) {
         $this->userPassword = $userPassword;
     }
     if ($dbName != false) {
         $this->dbName = $dbName;
     }
     if ($dbType != false) {
         $this->dbType = $dbType;
     }
     $this->checkConnection();
     $db = $this->database;
     $schema = new adoSchema($db);
     //Debug Adodb XML Schema
     $schema->XMLS_DEBUG = TRUE;
     //Debug Adodb
     $schema->debug = true;
     $sql = $schema->ParseSchema($schemaFile);
     $this->println("--------------Starting the table creation------------------");
     $result = $schema->ExecuteSchema($sql, $this->continueInstallOnError);
     if ($result) {
         print $db->errorMsg();
     }
     // needs to return in a decent way
     $this->println("ADODB createTables " . $schemaFile . " status=" . $result);
     return $result;
 }
示例#25
0
<?php

// V4.21 20 Mar 2004
error_reporting(E_ALL);
require "../adodb-xmlschema.inc.php";
// To build the schema, start by creating a normal ADOdb connection:
$db = ADONewConnection('mysql');
$db->Connect('localhost', 'root', '', 'schematest');
// To create a schema object and build the query array.
$schema = new adoSchema($db);
// To upgrade an existing schema object, use the following
// To upgrade an existing database to the provided schema,
// uncomment the following line:
#$schema->upgradeSchema();
// Build the SQL array
$sql = $schema->ParseSchema("xmlschema.xml");
print "Here's the SQL to do the build:\n<pre>";
print_r($sql);
print "</pre>\n";
// Execute the SQL on the database
//$result = $schema->ExecuteSchema( $sql );
// Finally, clean up after the XML parser
// (PHP won't do this for you!)
//$schema->Destroy();
示例#26
0
 /**
  * Using an XML string, build or update a table.
  */
 function execXML($xml, $mode = 'REPLACE')
 {
     global $db, $AppUI;
     include_once DP_BASE_DIR . '/lib/adodb/adodb-xmlschema.inc.php';
     $schema = new adoSchema($db);
     $schema->setUpgradeMode($mode);
     if (isset($this->_table_prefix) && $this->_table_prefix) {
         $schema->setPrefix($this->_table_prefix, false);
     }
     $schema->ContinueOnError(true);
     if (($sql = $scheme->ParseSchemaString($xml)) == false) {
         $AppUI->setMsg(array('Error in XML Schema', 'Error', $db->ErrorMsg()), UI_MSG_ERR);
         return false;
     }
     if ($schema->ExecuteSchema($sql, true)) {
         return true;
     } else {
         return false;
     }
 }
示例#27
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Retrospect-GDS - Installation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="install.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <h1>Retrospect-GDS Installer</h1>
  
  <h2>Step 4 - Upgrading Tables</h2>
  
  <?php 
# update tables and indexes
$schema = new adoSchema($db);
$schema->setPrefix($g_db_prefix);
$sql = $schema->ParseSchema('upgrade.xml');
$result = $schema->ExecuteSchema($sql);
$error = $db->ErrorMsg();
if ($result != true) {
    die('The following error was encountered while creating the database tables:<br/> ' . $error);
} else {
    echo 'No error were encountered.';
}
?>
 
    
    <h2>Step 5 - Updating Records</h2>

    <?php 
    $dbc = $db->Connect($dbhost, $dbuser, $dbpass);
    if ($dbc) {
        $existing_db = $db->SelectDB($dbname);
    }
} else {
    $dbc = false;
}
// Quick hack to ensure MySQL behaves itself (#2323)
$db->Execute("SET sql_mode := ''");
$current_version = $dp_version_major . '.' . $dp_version_minor;
$current_version .= isset($dp_version_patch) ? '.' . $dp_version_patch : '';
$current_version .= isset($dp_version_prepatch) ? '-' . $dp_version_prepatch : '';
if ($dobackup) {
    if ($dbc) {
        require_once DP_BASE_DIR . '/lib/adodb/adodb-xmlschema.inc.php';
        $schema = new adoSchema($db);
        $sql = $schema->ExtractSchema(true);
        header('Content-Disposition: attachment; filename="dPdbBackup' . date('Ymd') . date('His') . '.xml"');
        header('Content-Type: text/xml');
        echo $sql;
        exit;
    } else {
        $backupMsg = 'ERROR: No Database Connection available! - Backup not performed!';
    }
}
?>
<html>
<head>
 <title>dotProject Installer</title>
 <meta name="Description" content="dotProject Installer">
  <link rel="stylesheet" type="text/css" href="../style/default/main.css">
示例#29
0
 function _upgrade_database($table_prefix)
 {
     $dbcon = AMP_Registry::getDbcon();
     $table_names = $dbcon->MetaTables();
     $target_table = strtolower($table_prefix . 'phpgacl');
     if (array_search($target_table, $table_names) !== FALSE) {
         return true;
     }
     require_once 'adodb/adodb-xmlschema.inc.php';
     $schema = new adoSchema($dbcon);
     $schema->SetPrefix($table_prefix, FALSE);
     $schema->ParseSchema(AMP_BASE_INCLUDE_PATH . 'phpgacl/schema.xml');
     $schema->ContinueOnError(TRUE);
     $result = $schema->ExecuteSchema();
     if ($result == 2) {
         $this->message('Database upgraded successfully');
     } else {
         $this->error('Database upgrade failed');
     }
 }