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
2f4260c8
Commit
2f4260c8
authored
May 03, 2020
by
Guilherme Blanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporated code review suggestions
parent
96ddf9e8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
74 deletions
+61
-74
UPGRADE.md
UPGRADE.md
+11
-0
AbstractPlatform.php
src/Platforms/AbstractPlatform.php
+11
-21
SqlitePlatform.php
src/Platforms/SqlitePlatform.php
+5
-5
Table.php
src/Schema/Table.php
+20
-32
UniqueConstraint.php
src/Schema/UniqueConstraint.php
+11
-13
SQLAnywhere16PlatformTest.php
tests/Platforms/SQLAnywhere16PlatformTest.php
+3
-3
No files found.
UPGRADE.md
View file @
2f4260c8
# Upgrade to 3.0
## BC BREAK: Doctrine\DBAL\Schema\Table constructor new parameter
Deprecated parameter
`$idGeneratorType`
removed and added a new parameter
`$uniqueConstraints`
.
Constructor changed from:
`__construct($tableName, array $columns = [], array $indexes = [], array $fkConstraints = [], $idGeneratorType = 0, array $options = [])`
To the new constructor:
`__construct($tableName, array $columns = [], array $indexes = [], array $uniqueConstraints = [], array $fkConstraints = [], array $options = [])`
## BC BREAK: Dropped support for `FetchMode::CUSTOM_OBJECT` and `::STANDARD_OBJECT`
Instead of fetching an object, fetch an array and map it to an object of the desired class.
...
...
src/Platforms/AbstractPlatform.php
View file @
2f4260c8
...
...
@@ -1565,7 +1565,6 @@ abstract class AbstractPlatform
}
foreach
(
$table
->
getUniqueConstraints
()
as
$uniqueConstraint
)
{
/** @var UniqueConstraint $uniqueConstraint */
$options
[
'uniqueConstraints'
][
$uniqueConstraint
->
getQuotedName
(
$this
)]
=
$uniqueConstraint
;
}
}
...
...
@@ -1621,6 +1620,7 @@ abstract class AbstractPlatform
}
$sql
=
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
if
(
$this
->
supportsCommentOnStatement
())
{
if
(
$table
->
hasOption
(
'comment'
))
{
$sql
[]
=
$this
->
getCommentOnTableSQL
(
$tableName
,
$table
->
getOption
(
'comment'
));
...
...
@@ -1698,13 +1698,13 @@ abstract class AbstractPlatform
*
* @return string[]
*/
protected
function
_getCreateTableSQL
(
$
tableN
ame
,
array
$columns
,
array
$options
=
[])
protected
function
_getCreateTableSQL
(
$
n
ame
,
array
$columns
,
array
$options
=
[])
{
$columnListSql
=
$this
->
getColumnDeclarationListSQL
(
$columns
);
if
(
isset
(
$options
[
'uniqueConstraints'
])
&&
!
empty
(
$options
[
'uniqueConstraints'
]))
{
foreach
(
$options
[
'uniqueConstraints'
]
as
$
n
ame
=>
$definition
)
{
$columnListSql
.=
', '
.
$this
->
getUniqueConstraintDeclarationSQL
(
$
n
ame
,
$definition
);
foreach
(
$options
[
'uniqueConstraints'
]
as
$
constraintN
ame
=>
$definition
)
{
$columnListSql
.=
', '
.
$this
->
getUniqueConstraintDeclarationSQL
(
$
constraintN
ame
,
$definition
);
}
}
...
...
@@ -1718,19 +1718,20 @@ abstract class AbstractPlatform
}
}
$query
=
'CREATE TABLE '
.
$tableName
.
' ('
.
$columnListSql
;
$query
=
'CREATE TABLE '
.
$name
.
' ('
.
$columnListSql
;
$check
=
$this
->
getCheckDeclarationSQL
(
$columns
);
if
(
!
empty
(
$check
))
{
$query
.=
', '
.
$check
;
}
$query
.=
')'
;
$sql
=
[
$query
];
if
(
isset
(
$options
[
'foreignKeys'
]))
{
foreach
((
array
)
$options
[
'foreignKeys'
]
as
$definition
)
{
$sql
[]
=
$this
->
getCreateForeignKeySQL
(
$definition
,
$
tableN
ame
);
$sql
[]
=
$this
->
getCreateForeignKeySQL
(
$definition
,
$
n
ame
);
}
}
...
...
@@ -2393,17 +2394,11 @@ abstract class AbstractPlatform
throw
new
InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
}
$flags
=
[
'UNIQUE'
];
if
(
$constraint
->
hasFlag
(
'clustered'
))
{
$flags
[]
=
'CLUSTERED'
;
}
$constraintFlags
=
array_merge
([
'UNIQUE'
],
array_map
(
'strtoupper'
,
$constraint
->
getFlags
()));
$constraintName
=
$name
->
getQuotedName
(
$this
);
$constraintName
=
!
empty
(
$constraintName
)
?
$constraintName
.
' '
:
''
;
$columnListNames
=
$this
->
getIndexFieldDeclarationListSQL
(
$columns
);
return
sprintf
(
'CONSTRAINT %s
%s (%s)'
,
$constraintName
,
implode
(
' '
,
$f
lags
),
$columnListNames
);
return
sprintf
(
'CONSTRAINT %s
%s (%s)'
,
$constraintName
,
implode
(
' '
,
$constraintF
lags
),
$columnListNames
);
}
/**
...
...
@@ -3099,13 +3094,8 @@ abstract class AbstractPlatform
/**
* Gets the sequence name prefix based on table information.
*
* @param string $tableName
* @param string|null $schemaName
*
* @return string
*/
public
function
getSequencePrefix
(
$tableName
,
$schemaName
=
null
)
public
function
getSequencePrefix
(
string
$tableName
,
?
string
$schemaName
=
null
)
:
string
{
if
(
$schemaName
===
null
)
{
return
$tableName
;
...
...
src/Platforms/SqlitePlatform.php
View file @
2f4260c8
...
...
@@ -319,9 +319,9 @@ class SqlitePlatform extends AbstractPlatform
/**
* {@inheritDoc}
*/
protected
function
_getCreateTableSQL
(
$
tableN
ame
,
array
$columns
,
array
$options
=
[])
protected
function
_getCreateTableSQL
(
$
n
ame
,
array
$columns
,
array
$options
=
[])
{
$
tableName
=
str_replace
(
'.'
,
'__'
,
$tableN
ame
);
$
name
=
str_replace
(
'.'
,
'__'
,
$n
ame
);
$queryFields
=
$this
->
getColumnDeclarationListSQL
(
$columns
);
if
(
isset
(
$options
[
'uniqueConstraints'
])
&&
!
empty
(
$options
[
'uniqueConstraints'
]))
{
...
...
@@ -345,7 +345,7 @@ class SqlitePlatform extends AbstractPlatform
$tableComment
=
$this
->
getInlineTableCommentSQL
(
$comment
);
}
$query
=
[
'CREATE TABLE '
.
$
tableN
ame
.
' '
.
$tableComment
.
'('
.
$queryFields
.
')'
];
$query
=
[
'CREATE TABLE '
.
$
n
ame
.
' '
.
$tableComment
.
'('
.
$queryFields
.
')'
];
if
(
isset
(
$options
[
'alter'
])
&&
$options
[
'alter'
]
===
true
)
{
return
$query
;
...
...
@@ -353,13 +353,13 @@ class SqlitePlatform extends AbstractPlatform
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$indexDef
)
{
$query
[]
=
$this
->
getCreateIndexSQL
(
$indexDef
,
$
tableN
ame
);
$query
[]
=
$this
->
getCreateIndexSQL
(
$indexDef
,
$
n
ame
);
}
}
if
(
isset
(
$options
[
'unique'
])
&&
!
empty
(
$options
[
'unique'
]))
{
foreach
(
$options
[
'unique'
]
as
$indexDef
)
{
$query
[]
=
$this
->
getCreateIndexSQL
(
$indexDef
,
$
tableN
ame
);
$query
[]
=
$this
->
getCreateIndexSQL
(
$indexDef
,
$
n
ame
);
}
}
...
...
src/Schema/Table.php
View file @
2f4260c8
...
...
@@ -31,7 +31,7 @@ class Table extends AbstractAsset
protected
$_primaryKeyName
=
null
;
/** @var UniqueConstraint[] */
protected
$
_
uniqueConstraints
=
[];
protected
$uniqueConstraints
=
[];
/** @var ForeignKeyConstraint[] */
protected
$_fkConstraints
=
[];
...
...
@@ -149,7 +149,7 @@ class Table extends AbstractAsset
*
* @return self
*/
public
function
addUniqueConstraint
(
array
$columnNames
,
?
string
$indexName
=
null
,
array
$flags
=
[],
array
$options
=
[])
public
function
addUniqueConstraint
(
array
$columnNames
,
?
string
$indexName
=
null
,
array
$flags
=
[],
array
$options
=
[])
:
Table
{
if
(
$indexName
===
null
)
{
$indexName
=
$this
->
_generateIdentifierName
(
...
...
@@ -504,56 +504,44 @@ class Table extends AbstractAsset
/**
* Returns whether this table has a unique constraint with the given name.
*
* @param string $constraintName
*
* @return bool
*/
public
function
hasUniqueConstraint
(
$constraintName
)
public
function
hasUniqueConstraint
(
string
$name
)
:
bool
{
$
constraintName
=
$this
->
normalizeIdentifier
(
$constraintN
ame
);
$
name
=
$this
->
normalizeIdentifier
(
$n
ame
);
return
isset
(
$this
->
_uniqueConstraints
[
$constraintN
ame
]);
return
isset
(
$this
->
uniqueConstraints
[
$n
ame
]);
}
/**
* Returns the unique constraint with the given name.
*
* @param string $constraintName The constraint name.
*
* @return UniqueConstraint
*
* @throws SchemaException If the unique constraint does not exist.
*/
public
function
getUniqueConstraint
(
$constraintName
)
public
function
getUniqueConstraint
(
string
$name
)
:
UniqueConstraint
{
$
constraintName
=
$this
->
normalizeIdentifier
(
$constraintN
ame
);
$
name
=
$this
->
normalizeIdentifier
(
$n
ame
);
if
(
!
$this
->
hasUniqueConstraint
(
$
constraintN
ame
))
{
throw
SchemaException
::
uniqueConstraintDoesNotExist
(
$
constraintN
ame
,
$this
->
_name
);
if
(
!
$this
->
hasUniqueConstraint
(
$
n
ame
))
{
throw
SchemaException
::
uniqueConstraintDoesNotExist
(
$
n
ame
,
$this
->
_name
);
}
return
$this
->
_uniqueConstraints
[
$constraintN
ame
];
return
$this
->
uniqueConstraints
[
$n
ame
];
}
/**
* Removes the unique constraint with the given name.
*
* @param string $constraintName The constraint name.
*
* @return void
*
* @throws SchemaException
* @throws SchemaException If the unique constraint does not exist.
*/
public
function
removeUniqueConstraint
(
$constraintName
)
public
function
removeUniqueConstraint
(
string
$name
)
:
void
{
$
constraintName
=
$this
->
normalizeIdentifier
(
$constraintN
ame
);
$
name
=
$this
->
normalizeIdentifier
(
$n
ame
);
if
(
!
$this
->
hasForeignKey
(
$
constraintN
ame
))
{
throw
SchemaException
::
uniqueConstraintDoesNotExist
(
$
constraintN
ame
,
$this
->
_name
);
if
(
!
$this
->
hasForeignKey
(
$
n
ame
))
{
throw
SchemaException
::
uniqueConstraintDoesNotExist
(
$
n
ame
,
$this
->
_name
);
}
unset
(
$this
->
_uniqueConstraints
[
$constraintN
ame
]);
unset
(
$this
->
uniqueConstraints
[
$n
ame
]);
}
/**
...
...
@@ -711,7 +699,7 @@ class Table extends AbstractAsset
*/
public
function
getUniqueConstraints
()
{
return
$this
->
_
uniqueConstraints
;
return
$this
->
uniqueConstraints
;
}
/**
...
...
@@ -876,7 +864,7 @@ class Table extends AbstractAsset
/**
* @return self
*/
protected
function
_addUniqueConstraint
(
UniqueConstraint
$constraint
)
protected
function
_addUniqueConstraint
(
UniqueConstraint
$constraint
)
:
Table
{
$mergedNames
=
array_merge
([
$this
->
getName
()],
$constraint
->
getColumns
());
$name
=
strlen
(
$constraint
->
getName
())
>
0
...
...
@@ -885,7 +873,7 @@ class Table extends AbstractAsset
$name
=
$this
->
normalizeIdentifier
(
$name
);
$this
->
_
uniqueConstraints
[
$name
]
=
$constraint
;
$this
->
uniqueConstraints
[
$name
]
=
$constraint
;
// If there is already an index that fulfills this requirements drop the request. In the case of __construct
// calling this method during hydration from schema-details all the explicitly added indexes lead to duplicates.
...
...
@@ -984,7 +972,7 @@ class Table extends AbstractAsset
*
* @throws SchemaException
*/
private
function
_createUniqueConstraint
(
array
$columnNames
,
string
$indexName
,
array
$flags
=
[],
array
$options
=
[])
private
function
_createUniqueConstraint
(
array
$columnNames
,
string
$indexName
,
array
$flags
=
[],
array
$options
=
[])
:
UniqueConstraint
{
if
(
preg_match
(
'(([^a-zA-Z0-9_]+))'
,
$this
->
normalizeIdentifier
(
$indexName
))
===
1
)
{
throw
SchemaException
::
indexNameInvalid
(
$indexName
);
...
...
src/Schema/UniqueConstraint.php
View file @
2f4260c8
...
...
@@ -36,14 +36,14 @@ class UniqueConstraint extends AbstractAsset implements Constraint
private
$options
=
[];
/**
* @param string $
indexN
ame
* @param string $
n
ame
* @param string[] $columns
* @param string[] $flags
* @param mixed[] $options
*/
public
function
__construct
(
$indexN
ame
,
array
$columns
,
array
$flags
=
[],
array
$options
=
[])
public
function
__construct
(
string
$n
ame
,
array
$columns
,
array
$flags
=
[],
array
$options
=
[])
{
$this
->
_setName
(
$
indexN
ame
);
$this
->
_setName
(
$
n
ame
);
$this
->
options
=
$options
;
...
...
@@ -81,7 +81,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* @return string[]
*/
public
function
getUnquotedColumns
()
public
function
getUnquotedColumns
()
:
array
{
return
array_map
([
$this
,
'trimQuotes'
],
$this
->
getColumns
());
}
...
...
@@ -91,7 +91,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
*
* @return string[]
*/
public
function
getFlags
()
public
function
getFlags
()
:
array
{
return
array_keys
(
$this
->
flags
);
}
...
...
@@ -105,7 +105,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
*
* @example $uniqueConstraint->addFlag('CLUSTERED')
*/
public
function
addFlag
(
$flag
)
public
function
addFlag
(
string
$flag
)
:
UniqueConstraint
{
$this
->
flags
[
strtolower
(
$flag
)]
=
true
;
...
...
@@ -119,7 +119,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
*
* @return bool
*/
public
function
hasFlag
(
$flag
)
public
function
hasFlag
(
string
$flag
)
:
bool
{
return
isset
(
$this
->
flags
[
strtolower
(
$flag
)]);
}
...
...
@@ -131,7 +131,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
*
* @return void
*/
public
function
removeFlag
(
$flag
)
public
function
removeFlag
(
string
$flag
)
:
void
{
unset
(
$this
->
flags
[
strtolower
(
$flag
)]);
}
...
...
@@ -141,17 +141,15 @@ class UniqueConstraint extends AbstractAsset implements Constraint
*
* @return bool
*/
public
function
hasOption
(
$name
)
public
function
hasOption
(
string
$name
)
:
bool
{
return
isset
(
$this
->
options
[
strtolower
(
$name
)]);
}
/**
* @param string $name
*
* @return mixed
*/
public
function
getOption
(
$name
)
public
function
getOption
(
string
$name
)
:
mixed
{
return
$this
->
options
[
strtolower
(
$name
)];
}
...
...
@@ -159,7 +157,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* @return mixed[]
*/
public
function
getOptions
()
public
function
getOptions
()
:
array
{
return
$this
->
options
;
}
...
...
tests/Platforms/SQLAnywhere16PlatformTest.php
View file @
2f4260c8
...
...
@@ -394,13 +394,13 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)'
,
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'unique_constraint'
,
new
UniqueConstraint
(
null
,
[
'a'
,
'b'
],
[
'clustered'
])
new
UniqueConstraint
(
'unique_constraint'
,
[
'a'
,
'b'
],
[
'clustered'
])
)
);
self
::
assertEquals
(
'CONSTRAINT UNIQUE (a, b)'
,
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
null
,
new
UniqueConstraint
(
null
,
[
'a'
,
'b'
]))
'CONSTRAINT
foo
UNIQUE (a, b)'
,
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'foo'
,
new
UniqueConstraint
(
'foo'
,
[
'a'
,
'b'
]))
);
}
...
...
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