fixes #4892 different users on oracle, fixes #4894 escaping field

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7258 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-24 20:30:51 +00:00
parent 3ce765358d
commit f2fd386217
2 changed files with 108 additions and 59 deletions

View file

@ -439,7 +439,7 @@ class DboOracle extends DboSource {
if ($cache != null) {
return $cache;
}
$sql = 'SELECT view_name AS name FROM user_views UNION SELECT table_name AS name FROM user_tables';
$sql = 'SELECT view_name AS name FROM all_views UNION SELECT table_name AS name FROM all_tables';
if (!$this->execute($sql)) {
return false;
@ -474,7 +474,7 @@ class DboOracle extends DboSource {
if ($cache != null) {
return $cache;
}
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM user_tab_columns WHERE table_name = \'';
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM all_tab_columns WHERE table_name = \'';
$sql .= strtoupper($this->fullTableName($model)) . '\'';
if (!$this->execute($sql)) {
@ -506,7 +506,7 @@ class DboOracle extends DboSource {
function truncate($table, $reset = 0) {
if (empty($this->_sequences)) {
$sql = "SELECT sequence_name FROM user_sequences";
$sql = "SELECT sequence_name FROM all_sequences";
$this->execute($sql);
while ($row = $this->fetchRow()) {
$this->_sequences[] = strtolower($row[0]['sequence_name']);
@ -522,7 +522,7 @@ class DboOracle extends DboSource {
$row = $this->fetchRow();
$currval = $row[$this->_sequenceMap[$table]]['nextval'];
$this->execute("SELECT min_value FROM user_sequences WHERE sequence_name = '{$this->_sequenceMap[$table]}'");
$this->execute("SELECT min_value FROM all_sequences WHERE sequence_name = '{$this->_sequenceMap[$table]}'");
$row = $this->fetchRow();
$min_value = $row[0]['min_value'];
@ -560,9 +560,9 @@ class DboOracle extends DboSource {
$sql = "SELECT
table_name,
c.constraint_name
FROM user_cons_columns cc
LEFT JOIN user_indexes i ON (cc.constraint_name = i.index_name)
LEFT JOIN user_constraints c ON(c.constraint_name = cc.constraint_name)";
FROM all_cons_columns cc
LEFT JOIN all_indexes i ON (cc.constraint_name = i.index_name)
LEFT JOIN all_constraints c ON(c.constraint_name = cc.constraint_name)";
$this->execute($sql);
while ($row = $this->fetchRow()) {
$this->_keyConstraints[] = array($row[0]['table_name'], $row['c']['constraint_name']);
@ -582,7 +582,7 @@ class DboOracle extends DboSource {
constraint_name,
r_constraint_name
FROM
user_constraints";
all_constraints";
$this->execute($sql);
while ($row = $this->fetchRow()) {
$this->_constraints[] = $row[0];
@ -632,9 +632,9 @@ class DboOracle extends DboSource {
c.constraint_type,
i.index_name,
i.uniqueness
FROM user_cons_columns cc
LEFT JOIN user_indexes i ON(cc.constraint_name = i.index_name)
LEFT JOIN user_constraints c ON(c.constraint_name = cc.constraint_name)
FROM all_cons_columns cc
LEFT JOIN all_indexes i ON(cc.constraint_name = i.index_name)
LEFT JOIN all_constraints c ON(c.constraint_name = cc.constraint_name)
WHERE cc.table_name = \'' . strtoupper($table) .'\'');
foreach ($indexes as $i => $idx) {
if ($idx['c']['constraint_type'] == 'P') {
@ -714,17 +714,13 @@ class DboOracle extends DboSource {
* @return unknown
* @access public
*/
function name($var) {
$name = $var;
if (strstr($var, '_create') OR
strstr($var, '_read') OR
strstr($var, '_update') OR
strstr($var, '_delete')) {
if (strstr($var, '.')) {
list($model, $field) = explode('.', $var);
function name($name) {
if (strpos($name, '.') !== false && strpos($name, '"') === false) {
list($model, $field) = explode('.', $name);
if ($field[0] == "_") {
$name = "$model.\"$field\"";
} else {
$name = "\"$var\"";
$name = "\"$name\"";
}
}
return $name;

View file

@ -29,6 +29,8 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
require_once LIBS.'model'.DS.'datasources'.DS.'dbo_source.php';
require_once LIBS.'model'.DS.'datasources'.DS.'dbo'.DS.'dbo_oracle.php';
/**
* DboOracleTest class
*
@ -36,15 +38,27 @@ require_once LIBS.'model'.DS.'datasources'.DS.'dbo_source.php';
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboOracleTest extends CakeTestCase {
/**
* setup method
*
* @access public
* @return void
*/
function setUp() {
$this->_initDb();
}
/**
* skip method
*
* @access public
* @return void
*/
function skip() {
function skip($case = null) {
$this->_initDb();
$this->skipif($this->db->config['driver'] != 'oracle', 'Oracle connection not available');
if ($this->db->config['driver'] != 'oracle' && $case) {
pr("Oracle connection not available not available for " . $case);
return true;
}
}
/**
* testLastErrorStatement method
@ -53,6 +67,10 @@ class DboOracleTest extends CakeTestCase {
* @return void
*/
function testLastErrorStatement() {
if ($this->skip('testLastErrorStatement')) {
return;
}
$this->expectError();
$this->db->execute("SELECT ' FROM dual");
$e = $this->db->lastError();
@ -66,6 +84,10 @@ class DboOracleTest extends CakeTestCase {
* @return void
*/
function testLastErrorConnect() {
if ($this->skip('testLastErrorConnect')) {
return;
}
$config = $this->db->config;
$this->db->config['password'] = 'keepmeout';
$this->db->connect();
@ -73,6 +95,37 @@ class DboOracleTest extends CakeTestCase {
$r = 'ORA-01017: invalid username/password; logon denied';
$this->assertEqual($e, $r);
}
/**
* testName method
*
* @access public
* @return void
*/
function testName() {
$Db =& new DboOracle($config = null, $autoConnect = false);
$r = $Db->name($Db->name($Db->name('foo.last_update_date')));
$e = '"foo.last_update_date"';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('foo._update')));
$e = 'foo."_update"';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('foo.last_update_date')));
$e = '"foo.last_update_date"';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('last_update_date')));
$e = 'last_update_date';
$this->assertEqual($e, $r);
$r = $Db->name($Db->name($Db->name('_update')));
$e = '_update';
$this->assertEqual($e, $r);
}
}
?>