Fixed DBAL-139 Oracle's sequences with NOCACHE #204

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@ghost
Contributor
ghost commented Sep 23, 2012

Added cache size to sequence object.
NOCACHE is set with value 0.

Tested on local machine with test function but there is 5 tests that fails on current master branch on oracle DB 11.2.0.1 so I did not incorporate my test function for this.

I'e used WriteTest and added 3 more sequences with cache 0,1 and 55 and it passed, sequences are created in current schema on oracle db.

@stof stof commented on the diff Sep 23, 2012
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
@@ -172,7 +172,8 @@ public function getCreateSequenceSQL(Sequence $sequence)
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
' START WITH ' . $sequence->getInitialValue() .
' MINVALUE ' . $sequence->getInitialValue() .
- ' INCREMENT BY ' . $sequence->getAllocationSize();
+ ' INCREMENT BY ' . $sequence->getAllocationSize().
+ $sequence->getCacheSize();
stof
stof Sep 23, 2012 Member

wrond indentation (it should use spaces, not tabs)

@ghost
ghost Sep 23, 2012 Contributor

Are there formatting rules specified, could not found it anywhere, or I should learn from current code?

@ghost
ghost Sep 23, 2012 Contributor

Cool, thnx, I'll flow this from now on.

@stof stof commented on the diff Sep 23, 2012
lib/Doctrine/DBAL/Schema/Sequence.php
@@ -74,7 +80,24 @@ public function setInitialValue($initialValue)
{
$this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
}
-
+
stof
stof Sep 23, 2012 Member

Please don't ad trailing whitespaces

@ghost
ghost Sep 23, 2012 Contributor

Maybe the same Q like last one, why not, just want to know for the future commits?

@stof stof commented on the diff Sep 23, 2012
lib/Doctrine/DBAL/Schema/Sequence.php
@@ -74,7 +80,24 @@ public function setInitialValue($initialValue)
{
$this->_initialValue = (is_numeric($initialValue))?$initialValue:1;
}
-
+
+ public function getCacheSize()
+ {
+ return $this->_cacheSize;
stof
stof Sep 23, 2012 Member

Please use 4 spaces for the indentation, not tabs

@stof stof commented on the diff Sep 23, 2012
lib/Doctrine/DBAL/Schema/Sequence.php
-
+
+ public function getCacheSize()
+ {
+ return $this->_cacheSize;
+ }
+
+ public function setCacheSize($cacheSize)
+ {
+ switch($cacheSize){
+ case 0: $this->_cacheSize = 'NOCACHE';
+ break;
+ case 1: $this->_cacheSize = 'CACHE 20';
+ break;
+ default:
+ $this->_cacheSize = 'CACHE '.((is_numeric($cacheSize))?($cacheSize >(ceil(pow(10,27) - $this->_initialValue))/abs($this->_allocationSize)?20:$cacheSize):20);
stof
stof Sep 23, 2012 Member

wrong formatting. It should look like this:

switch ($cacheSize) {
    case 0:
        $this->_cacheSize = 'NOCACHE';
        break;
    case 1:
        $this->_cacheSize = 'CACHE 20';
        break;
    default:
        switch (true) {
            case (!(is_numeric($cacheSize)):
                $size = 20;
                break;
            case ($cacheSize > (ceil(pow(10,27) - $this->_initialValue))/abs($this->_allocationSize)):
                $size = 20;
                break;
            default:
                $size = $cacheSize;
        }
        $this->_cacheSize = $this->_cacheSize = 'CACHE '.$size;
}
stof
stof Sep 23, 2012 Member

a better solution could even be to use a single switch (true) btw.

Member
stof commented Sep 23, 2012

and tests are missing

@ghost
Contributor
ghost commented Sep 23, 2012

Regarding tests, current branch does not pass 5 of them on oracle db.
I could write test for this in next few weeks when Ill have time.

@ghost
Contributor
ghost commented Sep 23, 2012

Will apply suggested changes in next weeks.
Please point me to formatting rules specified if there are any written.

Owner
beberlei commented Jan 6, 2013

@AduroIdea Please add this for PostgreSQL as well, as it supports the exact same syntax, see

http://www.postgresql.org/docs/9.2/static/sql-createsequence.html

Owner

Added in master for Oracle and PostgreSQL.

@beberlei beberlei closed this Dec 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment