Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support oci8 in TableGenerator #136

Closed
wants to merge 1 commit into from

2 participants

@dpb587

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Build Status

This test was breaking when running under oci8 due to Oracle's deference to upper case column names. I realize Oracle has built-in sequences and TableGenerator is unnecessary, in theory, but it seemed like the class should work if possible. I see pgsql is in the same boat.

Tested with:

phpunit -c oci8.phpunit.xml.dist tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php

Before:

PHPUnit 3.5.13 by Sebastian Bergmann.

EE

Time: 0 seconds, Memory: 10.25Mb

There were 2 errors:

1) Doctrine\Tests\DBAL\Functional\TableGeneratorTest::testNextVal
Exception: [Doctrine\DBAL\DBALException] Error occured while generating ID with TableGenerator, aborted generation: Undefined index: sequence_value

2) Doctrine\Tests\DBAL\Functional\TableGeneratorTest::testNextValNotAffectedByOuterTransactions
Exception: [Doctrine\DBAL\DBALException] Error occured while generating ID with TableGenerator, aborted generation: Undefined index: sequence_value

After:

PHPUnit 3.5.13 by Sebastian Bergmann.

..

Time: 1 second, Memory: 10.25Mb

OK (2 tests, 5 assertions)
@beberlei beberlei commented on the diff
lib/Doctrine/DBAL/Id/TableGenerator.php
@@ -119,20 +119,22 @@ public function nextValue($sequenceName)
$stmt = $this->conn->executeQuery($sql, array($sequenceName));
if ($row = $stmt->fetch()) {
- $value = $row['sequence_value'];
@beberlei Owner
beberlei added a note

I don't like this, since its depends on the default fetch value which could be assoc. Can you just use array_change_key_case($row, CASE_LOWER) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@beberlei
Owner

Committed the array_change_key_case() way under your author.

@beberlei beberlei closed this
@dpb587

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 28, 2012
  1. @dpb587

    Support oci8 in TableGenerator

    dpb587 authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 5 deletions.
  1. +7 −5 lib/Doctrine/DBAL/Id/TableGenerator.php
View
12 lib/Doctrine/DBAL/Id/TableGenerator.php
@@ -119,20 +119,22 @@ public function nextValue($sequenceName)
$stmt = $this->conn->executeQuery($sql, array($sequenceName));
if ($row = $stmt->fetch()) {
- $value = $row['sequence_value'];
@beberlei Owner
beberlei added a note

I don't like this, since its depends on the default fetch value which could be assoc. Can you just use array_change_key_case($row, CASE_LOWER) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- $value++;
+ $sequence_value = $row[0];
+ $sequence_increment_by = $row[1];
- if ($row['sequence_increment_by'] > 1) {
+ $value = $sequence_value + 1;
+
+ if ($sequence_increment_by > 1) {
$this->sequences[$sequenceName] = array(
'value' => $value,
- 'max' => $row['sequence_value'] + $row['sequence_increment_by']
+ 'max' => $sequence_value + $sequence_increment_by
);
}
$sql = "UPDATE " . $this->generatorTableName . " ".
"SET sequence_value = sequence_value + sequence_increment_by " .
"WHERE sequence_name = ? AND sequence_value = ?";
- $rows = $this->conn->executeUpdate($sql, array($sequenceName, $row['sequence_value']));
+ $rows = $this->conn->executeUpdate($sql, array($sequenceName, $sequence_value));
if ($rows != 1) {
throw new \Doctrine\DBAL\DBALException("Race-condition detected while updating sequence. Aborting generation");
Something went wrong with that request. Please try again.