Exemplo n.º 1
0
 /**
  * Returns a MDB2 connection with the requested DSN.
  * A new MDB2 connection object is only created if no object with the
  * requested DSN exists yet.
  *
  * @param   mixed   'data source name', see the MDB2::parseDSN
  *                            method for a description of the dsn format.
  *                            Can also be specified as an array of the
  *                            format returned by MDB2::parseDSN.
  * @param   array   An associative array of option names and
  *                            their values.
  *
  * @return  mixed   a newly created MDB2 connection object, or a MDB2
  *                  error object on error
  *
  * @access  public
  * @see     MDB2::parseDSN
  */
 static function singleton($dsn = null, $options = false)
 {
     if ($dsn) {
         $dsninfo = MDB2::parseDSN($dsn);
         $dsninfo = array_merge($GLOBALS['_MDB2_dsninfo_default'], $dsninfo);
         $keys = array_keys($GLOBALS['_MDB2_databases']);
         for ($i = 0, $j = count($keys); $i < $j; ++$i) {
             if (isset($GLOBALS['_MDB2_databases'][$keys[$i]])) {
                 $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array');
                 if (count(array_diff_assoc($tmp_dsn, $dsninfo)) == 0) {
                     MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options);
                     return $GLOBALS['_MDB2_databases'][$keys[$i]];
                 }
             }
         }
     } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {
         return $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
     }
     $db = MDB2::factory($dsn, $options);
     return $db;
 }
Exemplo n.º 2
0
 /**
  * Returns a MDB2 connection with the requested DSN.
  * A newnew MDB2 connection object is only created if no object with the
  * reuested DSN exists yet.
  *
  * IMPORTANT: In order for MDB2 to work properly it is necessary that
  * you make sure that you work with a reference of the original
  * object instead of a copy (this is a PHP4 quirk).
  *
  * For example:
  *     $mdb =& MDB2::singleton($dsn);
  *          ^^
  * And not:
  *     $mdb = MDB2::singleton($dsn);
  *          ^^
  *
  * @param   mixed   $dsn      'data source name', see the MDB2::parseDSN
  *                            method for a description of the dsn format.
  *                            Can also be specified as an array of the
  *                            format returned by MDB2::parseDSN.
  * @param   array   $options  An associative array of option names and
  *                            their values.
  * @return  mixed   a newly created MDB2 connection object, or a MDB2
  *                  error object on error
  * @access  public
  * @see     MDB2::parseDSN
  */
 function &singleton($dsn = null, $options = false)
 {
     if ($dsn) {
         $dsninfo = MDB2::parseDSN($dsn);
         $dsninfo_default = array('phptype' => false, 'dbsyntax' => false, 'username' => false, 'password' => false, 'protocol' => false, 'hostspec' => false, 'port' => false, 'socket' => false, 'database' => false, 'mode' => false);
         $dsninfo = array_merge($dsninfo_default, $dsninfo);
         $keys = array_keys($GLOBALS['_MDB2_databases']);
         for ($i = 0, $j = count($keys); $i < $j; ++$i) {
             $tmp_dsn = $GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array');
             if (count(array_diff($tmp_dsn, $dsninfo)) == 0) {
                 MDB2::setOptions($GLOBALS['_MDB2_databases'][$keys[$i]], $options);
                 return $GLOBALS['_MDB2_databases'][$keys[$i]];
             }
         }
     } else {
         if (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {
             $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
             return $db;
         }
     }
     $db =& MDB2::connect($dsn, $options);
     return $db;
 }
Exemplo n.º 3
0
@set_time_limit(600);
OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('cache'));
error_reporting(E_ALL & ~(E_NOTICE | E_WARNING | E_DEPRECATED | E_STRICT));
if (!is_writable(RV_PATH . '/etc/xmlcache')) {
    die("=> The directory " . RV_PATH . '/etc/xmlcache' . " is not writable\n");
}
require RV_PATH . '/lib/OA/DB/Table.php';
// Create a database mock so we will not have to connect to database itself
require_once RV_PATH . '/lib/simpletest/mock_objects.php';
require_once 'MDB2/Driver/mysql.php';
Mock::generatePartial('MDB2_Driver_mysql', 'MDB2_Mock', array());
$oDbh = new MDB2_Mock();
$oDbh->__construct();
// add datatype mapping
$aDatatypeOptions = OA_DB::getDatatypeMapOptions();
MDB2::setOptions($oDbh, $aDatatypeOptions);
$oCache = new OA_DB_XmlCache();
$aOptions = array('force_defaults' => false);
$aSkipFiles = array();
clean_up();
// Generate XML caches
generateXmlCache(glob(RV_PATH . '/etc/tables_*.xml'));
generateXmlCache(glob(RV_PATH . '/etc/changes/schema_tables_*.xml'));
generateXmlCache(glob(RV_PATH . '/etc/changes/changes_tables_*.xml'), 'parseChangesetDefinitionFile');
echo "=> FINISHED REFRESHING THE MDB2 SCHEMA XML FILE CACHE\n\n";
function generateXmlCache($xmlFiles, $callback = 'parseDatabaseDefinitionFile')
{
    global $aSkipFiles, $aOptions, $oDbh, $oCache;
    foreach ($xmlFiles as $fileName) {
        if (!in_array(baseName($fileName), $aSkipFiles)) {
            echo "  => " . basename($fileName) . ": ";