Commit b7ab7229 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 4faa6e54
......@@ -126,6 +126,7 @@ abstract class Doctrine_Configurable
case Doctrine::ATTR_DEFAULT_TABLE_TYPE:
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
case Doctrine::ATTR_EMULATE_DATABASE:
break;
case Doctrine::ATTR_SEQCOL_NAME:
......
......@@ -497,7 +497,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params
* @return array
*/
public function fetchAll($statement, array $params = array()) {
public function fetchAll($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
}
/**
......@@ -508,7 +509,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param int $colnum 0-indexed column number to retrieve
* @return mixed
*/
public function fetchOne($statement, array $params = array(), $colnum = 0) {
public function fetchOne($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchColumn($colnum);
}
/**
......@@ -518,7 +520,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params
* @return array
*/
public function fetchRow($statement, array $params = array()) {
public function fetchRow($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(PDO::FETCH_ASSOC);
}
/**
......@@ -528,7 +531,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params
* @return array
*/
public function fetchArray($statement, array $params = array()) {
public function fetchArray($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(PDO::FETCH_NUM);
}
/**
......@@ -539,7 +543,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param int $colnum 0-indexed column number to retrieve
* @return array
*/
public function fetchColumn($statement, array $params = array(), $colnum = 0) {
public function fetchColumn($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_COLUMN, $colnum);
}
/**
......@@ -549,7 +554,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params
* @return array
*/
public function fetchAssoc($statement, array $params = array()) {
public function fetchAssoc($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
}
/**
......@@ -559,7 +565,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params
* @return array
*/
public function fetchBoth($statement, array $params = array()) {
public function fetchBoth($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_BOTH);
}
/**
......@@ -578,7 +585,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @see Doctrine_Query
* @return Doctrine_Collection Collection of Doctrine_Record objects
*/
public function query($query, array $params = array()) {
public function query($query, array $params = array())
{
$parser = new Doctrine_Query($this);
return $parser->query($query, $params);
......@@ -602,7 +610,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return Doctrine_Record|false Doctrine_Record object on success,
* boolean false on failure
*/
public function queryOne($query, array $params = array()) {
public function queryOne($query, array $params = array())
{
$parser = new Doctrine_Query($this);
$coll = $parser->query($query, $params);
......@@ -627,6 +636,18 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
return $this->dbh->query($query);
}
/**
* standaloneQuery
*
* @param string $query sql query
* @param array $params query parameters
*
* @return PDOStatement|Doctrine_Adapter_Statement
*/
public function standaloneQuery($query, $params = array())
{
return $this->execute($query, $params);
}
/**
* execute
* @param string $query sql query
......@@ -634,7 +655,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* @return PDOStatement|Doctrine_Adapter_Statement
*/
public function execute($query, array $params = array()) {
public function execute($query, array $params = array())
{
try {
if ( ! empty($params)) {
$stmt = $this->dbh->prepare($query);
......
......@@ -37,23 +37,22 @@ class Doctrine_Import_Oracle extends Doctrine_Import
*/
public function listDatabases()
{
if ( ! $this->conn->options['emulate_database']) {
return $this->conn->raiseError(Doctrine::ERROR_UNSUPPORTED, null, null,
'database listing is only supported if the "emulate_database" option is enabled', __FUNCTION__);
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) {
throw new Doctrine_Import_Exception('database listing is only supported if the "emulate_database" option is enabled');
}
/**
if ($this->conn->options['database_name_prefix']) {
$query = 'SELECT SUBSTR(username, ';
$query.= (strlen($this->conn->options['database_name_prefix'])+1);
$query.= (strlen($this->conn->getAttribute(['database_name_prefix'])+1);
$query.= ") FROM sys.dba_users WHERE username LIKE '";
$query.= $this->conn->options['database_name_prefix']."%'";
} else {
$query = 'SELECT username FROM sys.dba_users';
}
$result2 = $this->conn->standaloneQuery($query, array('text'), false);
$result = $result2->fetchCol();
*/
$query = 'SELECT username FROM sys.dba_users';
$result2 = $this->conn->standaloneQuery($query);
$result = $result2->fetchColumn();
$result2->free();
return $result;
}
/**
......@@ -86,6 +85,7 @@ class Doctrine_Import_Oracle extends Doctrine_Import
public function listSequences($database = null)
{
$query = "SELECT sequence_name FROM sys.user_sequences";
$tableNames = $this->conn->fetchColumn($query);
return array_map(array($this->conn, 'fixSequenceName'), $tableNames);
......@@ -98,10 +98,11 @@ class Doctrine_Import_Oracle extends Doctrine_Import
*/
public function listTableConstraints($table)
{
$table = $this->conn->quote($table, 'text');
$query = 'SELECT index_name name FROM user_constraints';
$query.= ' WHERE table_name='.$table.' OR table_name='.strtoupper($table);
$query = 'SELECT index_name name FROM user_constraints'
. ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table);
$constraints = $this->conn->fetchColumn($query);
return array_map(array($this->conn, 'fixIndexName'), $constraints);
......@@ -115,7 +116,9 @@ class Doctrine_Import_Oracle extends Doctrine_Import
public function listTableColumns($table)
{
$table = strtoupper($table);
$sql = "SELECT column_name, data_type, data_length, nullable, data_default from all_tab_columns WHERE table_name='$table' ORDER BY column_name";
$sql = "SELECT column_name, data_type, data_length, nullable, data_default from all_tab_columns"
. " WHERE table_name = '" . $table . "' ORDER BY column_name";
$result = $this->conn->fetchAssoc($sql);
foreach($result as $val) {
......@@ -138,9 +141,10 @@ class Doctrine_Import_Oracle extends Doctrine_Import
public function listTableIndexes($table)
{
$table = $this->conn->quote($table, 'text');
$query = 'SELECT index_name name FROM user_indexes';
$query.= ' WHERE table_name='.$table.' OR table_name='.strtoupper($table);
$query.= ' AND generated=' .$this->conn->quote('N', 'text');
$query = 'SELECT index_name name FROM user_indexes'
. ' WHERE table_name = ' . $table . ' OR table_name = ' . strtoupper($table)
. ' AND generated = ' . $this->conn->quote('N', 'text');
$indexes = $this->conn->fetchColumn($query);
return array_map(array($this->conn, 'fixIndexName'), $indexes);
......@@ -183,14 +187,18 @@ class Doctrine_Import_Oracle extends Doctrine_Import
*/
public function listUsers()
{
/**
if ($this->conn->options['emulate_database'] && $this->conn->options['database_name_prefix']) {
$query = 'SELECT SUBSTR(username, ';
$query.= (strlen($this->conn->options['database_name_prefix'])+1);
$query.= ") FROM sys.dba_users WHERE username NOT LIKE '";
$query.= $this->conn->options['database_name_prefix']."%'";
} else {
$query = 'SELECT username FROM sys.dba_users';
}
*/
$query = 'SELECT username FROM sys.dba_users';
//}
return $this->conn->fetchColumn($query);
}
/**
......
......@@ -73,7 +73,7 @@ class AdapterMock implements Doctrine_Adapter_Interface {
if ($fail) {
$this->lastInsertIdFail = true;
} else {
$this->lastInsertIdFail = false;
$this->lastInsertIdFail = false;
}
}
public function lastInsertId()
......@@ -125,7 +125,7 @@ class AdapterStatementMock {
$this->mock->addQuery($this->query);
return true;
}
public function fetchColumn($colnum) {
public function fetchColumn($colnum = 0) {
return 0;
}
}
......
......@@ -30,5 +30,77 @@
* @since 1.0
* @version $Revision$
*/
class Doctrine_Import_Oracle_TestCase extends Doctrine_UnitTestCase {
class Doctrine_Import_Oracle_TestCase extends Doctrine_UnitTestCase
{
public function testListSequencesExecutesSql()
{
$this->conn->setAttribute(Doctrine::ATTR_EMULATE_DATABASE, true);
$this->import->listSequences('table');
$this->assertEqual($this->adapter->pop(), "SELECT sequence_name FROM sys.user_sequences");
}
public function testListTableColumnsExecutesSql()
{
$this->import->listTableColumns('table');
$q = "SELECT column_name, data_type, data_length, nullable, data_default from all_tab_columns"
. " WHERE table_name = 'TABLE' ORDER BY column_name";
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListTableIndexesExecutesSql()
{
$this->import->listTableIndexes('table');
$q = 'SELECT index_name name FROM user_indexes'
. " WHERE table_name = 'table' OR table_name = 'TABLE'"
. " AND generated = 'N'";
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListTablesExecutesSql()
{
$this->import->listTables();
$q = 'SELECT table_name FROM sys.user_tables';
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListDatabasesExecutesSql()
{
$this->import->listDatabases();
$q = 'SELECT username FROM sys.dba_users';
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListUsersExecutesSql()
{
$this->import->listUsers();
$q = 'SELECT username FROM sys.dba_users';
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListViewsExecutesSql()
{
$this->import->listViews();
$q = 'SELECT view_name FROM sys.user_views';
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListFunctionsExecutesSql()
{
$this->import->listFunctions();
$q = "SELECT name FROM sys.user_source WHERE line = 1 AND type = 'FUNCTION'";
$this->assertEqual($this->adapter->pop(), $q);
}
public function testListTableConstraintsExecutesSql()
{
$this->import->listTableConstraints('table');
$q = "SELECT index_name name FROM user_constraints"
. " WHERE table_name = 'table' OR table_name = 'TABLE'";
$this->assertEqual($this->adapter->pop(), $q);
}
}
......@@ -151,7 +151,8 @@ class Doctrine_Import_Pgsql_TestCase extends Doctrine_UnitTestCase
public function testListTableConstraintsExecutesSql()
{
$this->import->listTableConstraints('table');
$q = "SELECT
relname
FROM
......
......@@ -88,5 +88,15 @@ class Doctrine_TreeStructure_TestCase extends Doctrine_UnitTestCase
$this->assertTrue(count($o4->Children) == 0);
$this->assertFalse(isset($o4->Parent));
}
}
public function testTreeStructureFetchingWorksWithDql()
{
$q = new Doctrine_Query();
$q->select('l.*, c.*')
->from('TreeLeaf l, l.Children c')
->where('l.parent_id IS NULL')
->groupby('l.id, c.id');
$coll = $q->execute();
}
}
......@@ -60,10 +60,16 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
$test->addTestCase(new Doctrine_Import_Firebird_TestCase());
$test->addTestCase(new Doctrine_Import_Informix_TestCase());
$test->addTestCase(new Doctrine_Import_Mysql_TestCase());
$test->addTestCase(new Doctrine_Import_Mssql_TestCase());
$test->addTestCase(new Doctrine_Import_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Import_Oracle_TestCase());
$test->addTestCase(new Doctrine_Import_Sqlite_TestCase());
// DATABASE ABSTRACTION tests
/**
// Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
......@@ -117,13 +123,7 @@ $test->addTestCase(new Doctrine_Export_Sqlite_TestCase());
// Import module (not yet fully tested)
//$test->addTestCase(new Doctrine_Import_TestCase());
$test->addTestCase(new Doctrine_Import_Firebird_TestCase());
$test->addTestCase(new Doctrine_Import_Informix_TestCase());
$test->addTestCase(new Doctrine_Import_Mysql_TestCase());
$test->addTestCase(new Doctrine_Import_Mssql_TestCase());
$test->addTestCase(new Doctrine_Import_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Import_Oracle_TestCase());
$test->addTestCase(new Doctrine_Import_Sqlite_TestCase());
// Expression module (not yet fully tested)
$test->addTestCase(new Doctrine_Expression_TestCase());
......@@ -155,7 +155,6 @@ $test->addTestCase(new Doctrine_Relation_Access_TestCase());
$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
$test->addTestCase(new Doctrine_Relation_OneToOne_TestCase());
$test->addTestCase(new Doctrine_TreeStructure_TestCase());
// Datatypes
......@@ -215,6 +214,9 @@ $test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
$test->addTestCase(new Doctrine_Query_Join_TestCase());
$test->addTestCase(new Doctrine_ColumnAlias_TestCase());
*/
$test->addTestCase(new Doctrine_TreeStructure_TestCase());
// Cache tests
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment