Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
e8efcd76
Commit
e8efcd76
authored
Dec 22, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-139] Add support for creating sequences with CACHE/NOCACHE options.
parent
6ce265d1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
117 additions
and
15 deletions
+117
-15
OraclePlatform.php
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
+22
-2
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+18
-2
Sequence.php
lib/Doctrine/DBAL/Schema/Sequence.php
+41
-11
OraclePlatformTest.php
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
+19
-0
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+17
-0
No files found.
lib/Doctrine/DBAL/Platforms/OraclePlatform.php
View file @
e8efcd76
...
...
@@ -188,7 +188,8 @@ class OraclePlatform extends AbstractPlatform
return
'CREATE SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' START WITH '
.
$sequence
->
getInitialValue
()
.
' MINVALUE '
.
$sequence
->
getInitialValue
()
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
();
' INCREMENT BY '
.
$sequence
->
getAllocationSize
()
.
$this
->
getSequenceCacheSQL
(
$sequence
);
}
/**
...
...
@@ -197,7 +198,26 @@ class OraclePlatform extends AbstractPlatform
public
function
getAlterSequenceSQL
(
\Doctrine\DBAL\Schema\Sequence
$sequence
)
{
return
'ALTER SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
();
' INCREMENT BY '
.
$sequence
->
getAllocationSize
()
.
$this
->
getSequenceCacheSQL
(
$sequence
);
}
/**
* Cache definition for sequences
*
* @return string
*/
private
function
getSequenceCacheSQL
(
\Doctrine\DBAL\Schema\Sequence
$sequence
)
{
if
(
$sequence
->
getCache
()
===
0
)
{
return
' NOCACHE'
;
}
else
if
(
$sequence
->
getCache
()
===
1
)
{
return
' CACHE 20'
;
}
else
if
(
$sequence
->
getCache
()
>
1
)
{
return
' CACHE '
.
$sequence
->
getCache
();
}
return
''
;
}
/**
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
e8efcd76
...
...
@@ -548,7 +548,8 @@ class PostgreSqlPlatform extends AbstractPlatform
return
'CREATE SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
()
.
' MINVALUE '
.
$sequence
->
getInitialValue
()
.
' START '
.
$sequence
->
getInitialValue
();
' START '
.
$sequence
->
getInitialValue
()
.
$this
->
getSequenceCacheSQL
(
$sequence
);
}
/**
...
...
@@ -557,7 +558,22 @@ class PostgreSqlPlatform extends AbstractPlatform
public
function
getAlterSequenceSQL
(
\Doctrine\DBAL\Schema\Sequence
$sequence
)
{
return
'ALTER SEQUENCE '
.
$sequence
->
getQuotedName
(
$this
)
.
' INCREMENT BY '
.
$sequence
->
getAllocationSize
();
' INCREMENT BY '
.
$sequence
->
getAllocationSize
()
.
$this
->
getSequenceCacheSQL
(
$sequence
);
}
/**
* Cache definition for sequences
*
* @return string
*/
private
function
getSequenceCacheSQL
(
\Doctrine\DBAL\Schema\Sequence
$sequence
)
{
if
(
$sequence
->
getCache
()
>
1
)
{
return
' CACHE '
.
$sequence
->
getCache
();
}
return
''
;
}
/**
...
...
lib/Doctrine/DBAL/Schema/Sequence.php
View file @
e8efcd76
...
...
@@ -33,23 +33,29 @@ class Sequence extends AbstractAsset
/**
* @var integer
*/
protected
$
_
allocationSize
=
1
;
protected
$allocationSize
=
1
;
/**
* @var integer
*/
protected
$_initialValue
=
1
;
protected
$initialValue
=
1
;
/**
* @var integer|null
*/
protected
$cache
=
null
;
/**
* @param string $name
* @param integer $allocationSize
* @param integer $initialValue
*/
public
function
__construct
(
$name
,
$allocationSize
=
1
,
$initialValue
=
1
)
public
function
__construct
(
$name
,
$allocationSize
=
1
,
$initialValue
=
1
,
$cache
=
null
)
{
$this
->
_setName
(
$name
);
$this
->
_allocationSize
=
(
is_numeric
(
$allocationSize
))
?
$allocationSize
:
1
;
$this
->
_initialValue
=
(
is_numeric
(
$initialValue
))
?
$initialValue
:
1
;
$this
->
allocationSize
=
is_numeric
(
$allocationSize
)
?
$allocationSize
:
1
;
$this
->
initialValue
=
is_numeric
(
$initialValue
)
?
$initialValue
:
1
;
$this
->
cache
=
$cache
;
}
/**
...
...
@@ -57,7 +63,7 @@ class Sequence extends AbstractAsset
*/
public
function
getAllocationSize
()
{
return
$this
->
_
allocationSize
;
return
$this
->
allocationSize
;
}
/**
...
...
@@ -65,27 +71,51 @@ class Sequence extends AbstractAsset
*/
public
function
getInitialValue
()
{
return
$this
->
_initialValue
;
return
$this
->
initialValue
;
}
/**
* @return integer|null
*/
public
function
getCache
()
{
return
$this
->
cache
;
}
/**
* @param integer $allocationSize
*
* @return
void
* @return
\Doctrine\DBAL\Schema\Sequence
*/
public
function
setAllocationSize
(
$allocationSize
)
{
$this
->
_allocationSize
=
(
is_numeric
(
$allocationSize
))
?
$allocationSize
:
1
;
$this
->
allocationSize
=
is_numeric
(
$allocationSize
)
?
$allocationSize
:
1
;
return
$this
;
}
/**
* @param integer $initialValue
*
* @return
void
* @return
\Doctrine\DBAL\Schema\Sequence
*/
public
function
setInitialValue
(
$initialValue
)
{
$this
->
_initialValue
=
(
is_numeric
(
$initialValue
))
?
$initialValue
:
1
;
$this
->
initialValue
=
is_numeric
(
$initialValue
)
?
$initialValue
:
1
;
return
$this
;
}
/**
* @param integer $cache
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public
function
setCache
(
$cache
)
{
$this
->
cache
=
$cache
;
return
$this
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
View file @
e8efcd76
...
...
@@ -346,4 +346,23 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{
$this
->
assertSame
(
'mytable_mycolumn_SEQ'
,
$this
->
_platform
->
getIdentitySequenceName
(
'mytable'
,
'mycolumn'
));
}
/**
* @dataProvider dataCreateSequenceWithCache
* @group DBAL-139
*/
public
function
testCreateSequenceWithCache
(
$cacheSize
,
$expectedSql
)
{
$sequence
=
new
\Doctrine\DBAL\Schema\Sequence
(
'foo'
,
1
,
1
,
$cacheSize
);
$this
->
assertContains
(
$expectedSql
,
$this
->
_platform
->
getCreateSequenceSQL
(
$sequence
));
}
public
function
dataCreateSequenceWithCache
()
{
return
array
(
array
(
1
,
'CACHE 20'
),
array
(
0
,
'NOCACHE'
),
array
(
3
,
'CACHE 3'
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
View file @
e8efcd76
...
...
@@ -426,4 +426,21 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
{
$this
->
assertSame
(
'mytable_mycolumn_seq'
,
$this
->
_platform
->
getIdentitySequenceName
(
'mytable'
,
'mycolumn'
));
}
/**
* @dataProvider dataCreateSequenceWithCache
* @group DBAL-139
*/
public
function
testCreateSequenceWithCache
(
$cacheSize
,
$expectedSql
)
{
$sequence
=
new
\Doctrine\DBAL\Schema\Sequence
(
'foo'
,
1
,
1
,
$cacheSize
);
$this
->
assertContains
(
$expectedSql
,
$this
->
_platform
->
getCreateSequenceSQL
(
$sequence
));
}
public
function
dataCreateSequenceWithCache
()
{
return
array
(
array
(
3
,
'CACHE 3'
)
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment