Exemple #1
0
 /**
  * @param PASL_DB_Driver_Common|MDB2_Driver_common $dbObject
  */
 private function testBasicQueryMethods($dbObject)
 {
     $sql = "SELECT * FROM pasl_query_tests";
     $expectedRecord = array();
     $expectedRecord['id'] = "1";
     $expectedRecord['name'] = 'db_test';
     $expectedRecord['sequence'] = 'primary';
     $expectedRecord['timestamp'] = '0000-00-00 00:00:00';
     $result = $dbObject->queryCol($sql, 'name');
     $this->assertEqual($result[0], $expectedRecord['name']);
     $result = $dbObject->queryCol($sql, 1);
     $this->assertEqual($result[0], $expectedRecord['name']);
     $result = $dbObject->queryOne($sql, 'name');
     $this->assertEqual($result, $expectedRecord['name']);
     $result = $dbObject->queryOne($sql, 1);
     $this->assertEqual($result, $expectedRecord['name']);
     $result = $dbObject->queryRow($sql);
     $this->assertIsA($result, 'Array');
     $this->assertIdentical($result, $expectedRecord);
     $result = $dbObject->queryAll($sql);
     $this->assertIsA($result, 'Array');
     $this->assertIdentical($result[0], $expectedRecord);
 }
Exemple #2
0
 /**
  * A method to set the default schema. The schema will be created if missing.
  *
  * @param MDB2_Driver_common $oDbh
  * @return mixed True on succes, PEAR_Error otherwise
  */
 static function setSchema($oDbh)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Connect to PgSQL schema if needed
     if ($oDbh->dbsyntax == 'pgsql' && !empty($oDbh->connected_database_name)) {
         if (empty($aConf['databasePgsql']['schema'])) {
             // No need to deal with schemas
             return true;
         }
         OA::disableErrorHandling();
         $result = $oDbh->exec("SET search_path = '{$aConf['databasePgsql']['schema']}'");
         OA::enableErrorHandling();
         if (PEAR::isError($result)) {
             // Schema not found, try to create it
             OA::disableErrorHandling();
             $schema = $oDbh->quoteIdentifier($aConf['databasePgsql']['schema'], true);
             $result = $oDbh->exec("CREATE SCHEMA {$schema}");
             OA::enableErrorHandling();
             if (PEAR::isError($result)) {
                 // Schema was not created, return error
                 return $result;
             }
             OA::disableErrorHandling();
             $result = $oDbh->exec("SET search_path = '{$aConf['databasePgsql']['schema']}'");
             OA::enableErrorHandling();
             if (PEAR::isError($result)) {
                 // Schema was created, but SET search_path failed...
                 return $result;
             }
             OA::disableErrorHandling();
             $result = OA_DB::createFunctions();
             OA::enableErrorHandling();
             if (PEAR::isError($result)) {
                 // Could not create functions
                 return $result;
             }
         }
     }
     return true;
 }