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
03af26ab
Commit
03af26ab
authored
Nov 17, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBAL-64 - Fix optional quoting of identifiers in DBAL\Schema assets.
parent
3d7bb1e6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
11 deletions
+64
-11
AbstractAsset.php
lib/Doctrine/DBAL/Schema/AbstractAsset.php
+20
-0
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+7
-7
CreateSchemaSqlCollector.php
...Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
+3
-1
DropSchemaSqlCollector.php
lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
+3
-3
ColumnTest.php
tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
+16
-0
TableTest.php
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
+15
-0
No files found.
lib/Doctrine/DBAL/Schema/AbstractAsset.php
View file @
03af26ab
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
namespace
Doctrine\DBAL\Schema
;
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
/**
* The abstract asset allows to reset the name of all assets without publishing this to the public userland.
* The abstract asset allows to reset the name of all assets without publishing this to the public userland.
*
*
...
@@ -40,6 +42,8 @@ abstract class AbstractAsset
...
@@ -40,6 +42,8 @@ abstract class AbstractAsset
*/
*/
protected
$_name
;
protected
$_name
;
protected
$_quoted
=
false
;
/**
/**
* Set name of this asset
* Set name of this asset
*
*
...
@@ -47,6 +51,10 @@ abstract class AbstractAsset
...
@@ -47,6 +51,10 @@ abstract class AbstractAsset
*/
*/
protected
function
_setName
(
$name
)
protected
function
_setName
(
$name
)
{
{
if
(
strlen
(
$name
)
&&
$name
[
0
]
==
'`'
)
{
$this
->
_quoted
=
true
;
$name
=
trim
(
$name
,
'`'
);
}
$this
->
_name
=
$name
;
$this
->
_name
=
$name
;
}
}
...
@@ -60,6 +68,18 @@ abstract class AbstractAsset
...
@@ -60,6 +68,18 @@ abstract class AbstractAsset
return
$this
->
_name
;
return
$this
->
_name
;
}
}
/**
* Get the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted.
*
* @param AbstractPlatform $platform
* @return string
*/
public
function
getQuotedName
(
AbstractPlatform
$platform
)
{
return
(
$this
->
_quoted
)
?
$platform
->
quoteIdentifier
(
$this
->
_name
)
:
$this
->
_name
;
}
/**
/**
* Generate an identifier from a list of column names obeying a certain string length.
* Generate an identifier from a list of column names obeying a certain string length.
*
*
...
...
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
03af26ab
...
@@ -293,7 +293,7 @@ abstract class AbstractSchemaManager
...
@@ -293,7 +293,7 @@ abstract class AbstractSchemaManager
public
function
dropIndex
(
$index
,
$table
)
public
function
dropIndex
(
$index
,
$table
)
{
{
if
(
$index
instanceof
Index
)
{
if
(
$index
instanceof
Index
)
{
$index
=
$index
->
get
Name
(
);
$index
=
$index
->
get
QuotedName
(
$this
->
_platform
);
}
}
$this
->
_execSql
(
$this
->
_platform
->
getDropIndexSQL
(
$index
,
$table
));
$this
->
_execSql
(
$this
->
_platform
->
getDropIndexSQL
(
$index
,
$table
));
...
@@ -418,7 +418,7 @@ abstract class AbstractSchemaManager
...
@@ -418,7 +418,7 @@ abstract class AbstractSchemaManager
*/
*/
public
function
createView
(
View
$view
)
public
function
createView
(
View
$view
)
{
{
$this
->
_execSql
(
$this
->
_platform
->
getCreateViewSQL
(
$view
->
get
Name
(
),
$view
->
getSql
()));
$this
->
_execSql
(
$this
->
_platform
->
getCreateViewSQL
(
$view
->
get
QuotedName
(
$this
->
_platform
),
$view
->
getSql
()));
}
}
/* dropAndCreate*() Methods */
/* dropAndCreate*() Methods */
...
@@ -445,7 +445,7 @@ abstract class AbstractSchemaManager
...
@@ -445,7 +445,7 @@ abstract class AbstractSchemaManager
*/
*/
public
function
dropAndCreateIndex
(
Index
$index
,
$table
)
public
function
dropAndCreateIndex
(
Index
$index
,
$table
)
{
{
$this
->
tryMethod
(
'dropIndex'
,
$index
->
get
Name
(
),
$table
);
$this
->
tryMethod
(
'dropIndex'
,
$index
->
get
QuotedName
(
$this
->
_platform
),
$table
);
$this
->
createIndex
(
$index
,
$table
);
$this
->
createIndex
(
$index
,
$table
);
}
}
...
@@ -480,7 +480,7 @@ abstract class AbstractSchemaManager
...
@@ -480,7 +480,7 @@ abstract class AbstractSchemaManager
*/
*/
public
function
dropAndCreateTable
(
Table
$table
)
public
function
dropAndCreateTable
(
Table
$table
)
{
{
$this
->
tryMethod
(
'dropTable'
,
$table
->
get
Name
(
));
$this
->
tryMethod
(
'dropTable'
,
$table
->
get
QuotedName
(
$this
->
_platform
));
$this
->
createTable
(
$table
);
$this
->
createTable
(
$table
);
}
}
...
@@ -502,7 +502,7 @@ abstract class AbstractSchemaManager
...
@@ -502,7 +502,7 @@ abstract class AbstractSchemaManager
*/
*/
public
function
dropAndCreateView
(
View
$view
)
public
function
dropAndCreateView
(
View
$view
)
{
{
$this
->
tryMethod
(
'dropView'
,
$view
->
get
Name
(
));
$this
->
tryMethod
(
'dropView'
,
$view
->
get
QuotedName
(
$this
->
_platform
));
$this
->
createView
(
$view
);
$this
->
createView
(
$view
);
}
}
...
@@ -622,7 +622,7 @@ abstract class AbstractSchemaManager
...
@@ -622,7 +622,7 @@ abstract class AbstractSchemaManager
$list
=
array
();
$list
=
array
();
foreach
(
$tableColumns
as
$key
=>
$column
)
{
foreach
(
$tableColumns
as
$key
=>
$column
)
{
if
(
$column
=
$this
->
_getPortableTableColumnDefinition
(
$column
))
{
if
(
$column
=
$this
->
_getPortableTableColumnDefinition
(
$column
))
{
$name
=
strtolower
(
$column
->
get
Name
(
));
$name
=
strtolower
(
$column
->
get
QuotedName
(
$this
->
_platform
));
$list
[
$name
]
=
$column
;
$list
[
$name
]
=
$column
;
}
}
}
}
...
@@ -711,7 +711,7 @@ abstract class AbstractSchemaManager
...
@@ -711,7 +711,7 @@ abstract class AbstractSchemaManager
$list
=
array
();
$list
=
array
();
foreach
(
$views
as
$key
=>
$value
)
{
foreach
(
$views
as
$key
=>
$value
)
{
if
(
$view
=
$this
->
_getPortableViewDefinition
(
$value
))
{
if
(
$view
=
$this
->
_getPortableViewDefinition
(
$value
))
{
$viewName
=
strtolower
(
$view
->
get
Name
(
));
$viewName
=
strtolower
(
$view
->
get
QuotedName
(
$this
->
_platform
));
$list
[
$viewName
]
=
$view
;
$list
[
$viewName
]
=
$view
;
}
}
}
}
...
...
lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
View file @
03af26ab
...
@@ -95,7 +95,9 @@ class CreateSchemaSqlCollector implements Visitor
...
@@ -95,7 +95,9 @@ class CreateSchemaSqlCollector implements Visitor
// Append the foreign key constraints SQL
// Append the foreign key constraints SQL
if
(
$this
->
_platform
->
supportsForeignKeyConstraints
())
{
if
(
$this
->
_platform
->
supportsForeignKeyConstraints
())
{
$this
->
_createFkConstraintQueries
=
array_merge
(
$this
->
_createFkConstraintQueries
,
$this
->
_createFkConstraintQueries
=
array_merge
(
$this
->
_createFkConstraintQueries
,
(
array
)
$this
->
_platform
->
getCreateForeignKeySQL
(
$fkConstraint
,
$localTable
->
getName
())
(
array
)
$this
->
_platform
->
getCreateForeignKeySQL
(
$fkConstraint
,
$localTable
->
getQuotedName
(
$this
->
_platform
)
)
);
);
}
}
}
}
...
...
lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
View file @
03af26ab
...
@@ -83,7 +83,7 @@ class DropSchemaSqlCollector implements Visitor
...
@@ -83,7 +83,7 @@ class DropSchemaSqlCollector implements Visitor
*/
*/
public
function
acceptTable
(
Table
$table
)
public
function
acceptTable
(
Table
$table
)
{
{
$this
->
_tables
[]
=
$this
->
_platform
->
getDropTableSQL
(
$table
->
get
Name
(
));
$this
->
_tables
[]
=
$this
->
_platform
->
getDropTableSQL
(
$table
->
get
QuotedName
(
$this
->
_platform
));
}
}
/**
/**
...
@@ -104,7 +104,7 @@ class DropSchemaSqlCollector implements Visitor
...
@@ -104,7 +104,7 @@ class DropSchemaSqlCollector implements Visitor
throw
SchemaException
::
namedForeignKeyRequired
(
$localTable
,
$fkConstraint
);
throw
SchemaException
::
namedForeignKeyRequired
(
$localTable
,
$fkConstraint
);
}
}
$this
->
_constraints
[]
=
$this
->
_platform
->
getDropForeignKeySQL
(
$fkConstraint
->
get
Name
(),
$localTable
->
getName
(
));
$this
->
_constraints
[]
=
$this
->
_platform
->
getDropForeignKeySQL
(
$fkConstraint
->
get
QuotedName
(
$this
->
_platform
),
$localTable
->
getQuotedName
(
$this
->
_platform
));
}
}
/**
/**
...
@@ -121,7 +121,7 @@ class DropSchemaSqlCollector implements Visitor
...
@@ -121,7 +121,7 @@ class DropSchemaSqlCollector implements Visitor
*/
*/
public
function
acceptSequence
(
Sequence
$sequence
)
public
function
acceptSequence
(
Sequence
$sequence
)
{
{
$this
->
_sequences
[]
=
$this
->
_platform
->
getDropSequenceSQL
(
$sequence
->
get
Name
(
));
$this
->
_sequences
[]
=
$this
->
_platform
->
getDropSequenceSQL
(
$sequence
->
get
QuotedName
(
$this
->
_platform
));
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php
View file @
03af26ab
...
@@ -71,4 +71,20 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
...
@@ -71,4 +71,20 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
$string
=
Type
::
getType
(
'string'
);
$string
=
Type
::
getType
(
'string'
);
return
new
Column
(
"foo"
,
$string
,
$options
);
return
new
Column
(
"foo"
,
$string
,
$options
);
}
}
/**
* @group DBAL-64
*/
public
function
testQuotedColumnName
()
{
$string
=
Type
::
getType
(
'string'
);
$column
=
new
Column
(
"`bar`"
,
$string
,
array
());
$mysqlPlatform
=
new
\Doctrine\DBAL\Platforms\MySqlPlatform
();
$sqlitePlatform
=
new
\Doctrine\DBAL\Platforms\SqlitePlatform
();
$this
->
assertEquals
(
'bar'
,
$column
->
getName
());
$this
->
assertEquals
(
'`bar`'
,
$column
->
getQuotedName
(
$mysqlPlatform
));
$this
->
assertEquals
(
'"bar"'
,
$column
->
getQuotedName
(
$sqlitePlatform
));
}
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/Schema/TableTest.php
View file @
03af26ab
...
@@ -400,4 +400,19 @@ class TableTest extends \PHPUnit_Framework_TestCase
...
@@ -400,4 +400,19 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this
->
assertFalse
(
$table
->
hasIndex
(
'bar_baz_idx'
));
$this
->
assertFalse
(
$table
->
hasIndex
(
'bar_baz_idx'
));
$this
->
assertTrue
(
$table
->
hasIndex
(
'bar_baz_uniq'
));
$this
->
assertTrue
(
$table
->
hasIndex
(
'bar_baz_uniq'
));
}
}
/**
* @group DBAL-64
*/
public
function
testQuotedTableName
()
{
$table
=
new
Table
(
"`bar`"
);
$mysqlPlatform
=
new
\Doctrine\DBAL\Platforms\MySqlPlatform
();
$sqlitePlatform
=
new
\Doctrine\DBAL\Platforms\SqlitePlatform
();
$this
->
assertEquals
(
'bar'
,
$table
->
getName
());
$this
->
assertEquals
(
'`bar`'
,
$table
->
getQuotedName
(
$mysqlPlatform
));
$this
->
assertEquals
(
'"bar"'
,
$table
->
getQuotedName
(
$sqlitePlatform
));
}
}
}
\ No newline at end of file
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