Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Oracle DBO Updates #49

Closed
wants to merge 3 commits into from

1 participant

@benmurden

A few bug fixes and efficiency updates for the Oracle DBO.

Ben

benmurden added some commits
@benmurden benmurden Added logic for use with defined schema in Oracle
A "schema" key can be used in the database config when you want to access a different schema without having to always use the dot syntax. This also improves efficiency when you only use tables from one schema.
fe4c193
@benmurden benmurden Added tablePrefix to described sequences
This avoids conflicts with separate sequences used in test suite fixtures, for example.
f7f097b
@benmurden benmurden Fix lastInsertId in Oracle when persistModel is used
The persistModel switch in controllers means describe is not always called, so the sequenceMap is not generated. This patch addresses that by checking the associated model for relevant information when the sequenceMap data is not available.
61a511a
@benmurden

I'm in the process of rewriting the sequence persistence fix, as well as adding some test cases, so I'll close this pull request.

@benmurden benmurden closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2011
  1. @benmurden

    Added logic for use with defined schema in Oracle

    benmurden authored
    A "schema" key can be used in the database config when you want to access a different schema without having to always use the dot syntax. This also improves efficiency when you only use tables from one schema.
Commits on Apr 6, 2011
  1. @benmurden

    Added tablePrefix to described sequences

    benmurden authored
    This avoids conflicts with separate sequences used in test suite fixtures, for example.
  2. @benmurden

    Fix lastInsertId in Oracle when persistModel is used

    benmurden authored
    The persistModel switch in controllers means describe is not always called, so the sequenceMap is not generated. This patch addresses that by checking the associated model for relevant information when the sequenceMap data is not available.
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 3 deletions.
  1. +23 −3 cake/libs/model/datasources/dbo/dbo_oracle.php
View
26 cake/libs/model/datasources/dbo/dbo_oracle.php
@@ -187,6 +187,9 @@ function connect() {
if (!empty($config['nls_comp'])) {
$this->execute('ALTER SESSION SET NLS_COMP='.$config['nls_comp']);
}
+ if (!empty($config['schema'])) {
+ $this->execute('ALTER SESSION SET CURRENT_SCHEMA='.$config['schema']);
+ }
$this->execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
} else {
$this->connected = false;
@@ -463,11 +466,17 @@ function createTrigger($table) {
* @access public
*/
function listSources() {
+ $config = $this->config;
$cache = parent::listSources();
if ($cache != null) {
return $cache;
}
- $sql = 'SELECT view_name AS name FROM all_views UNION SELECT table_name AS name FROM all_tables';
+
+ if (!empty($config['schema'])) {
+ $sql = 'SELECT view_name AS name FROM all_views WHERE owner = \'' . $config['schema'] . '\' UNION SELECT table_name AS name FROM all_tables WHERE owner = \'' . $config['schema'] . '\'';
+ } else {
+ $sql = 'SELECT view_name AS name FROM all_views UNION SELECT table_name AS name FROM all_tables';
+ }
if (!$this->execute($sql)) {
return false;
@@ -494,7 +503,7 @@ function describe(&$model) {
if (!empty($model->sequence)) {
$this->_sequenceMap[$table] = $model->sequence;
} elseif (!empty($model->table)) {
- $this->_sequenceMap[$table] = $model->table . '_seq';
+ $this->_sequenceMap[$table] = $model->tablePrefix . $model->table . '_seq';
}
$cache = parent::describe($model);
@@ -897,7 +906,18 @@ function value($data, $column = null, $safe = false) {
* @access public
*/
function lastInsertId($source) {
- $sequence = $this->_sequenceMap[$source];
+ if (empty($this->_sequenceMap[$source])) {
+
+ $model = ClassRegistry::init($source);
+
+ if (!empty($model->sequence)) {
+ $sequence = $model->sequence;
+ } elseif (!empty($model->table)) {
+ $sequence = $model->tablePrefix . $model->table . '_seq';
+ }
+ } else {
+ $sequence = $this->_sequenceMap[$source];
+ }
$sql = "SELECT $sequence.currval FROM dual";
if (!$this->execute($sql)) {
Something went wrong with that request. Please try again.