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
63efa539
Commit
63efa539
authored
Feb 07, 2018
by
Tom Van Looy
Committed by
mikeSimonson
Feb 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inherit table charset/collation from db charset (#3003)
Inherit table charset/collation from db charset
parent
de568088
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
3 deletions
+91
-3
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+1
-1
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+6
-2
MySqlInheritCharsetTest.php
tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php
+84
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
63efa539
...
...
@@ -496,7 +496,7 @@ class MySqlPlatform extends AbstractPlatform
// Collate
if
(
!
isset
(
$options
[
'collate'
]))
{
$options
[
'collate'
]
=
'utf8
_unicode_ci'
;
$options
[
'collate'
]
=
$options
[
'charset'
]
.
'
_unicode_ci'
;
}
$tableOptions
[]
=
sprintf
(
'COLLATE %s'
,
$options
[
'collate'
]);
...
...
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
63efa539
...
...
@@ -1058,9 +1058,13 @@ abstract class AbstractSchemaManager
}
$params
=
$this
->
_conn
->
getParams
();
if
(
isset
(
$params
[
'defaultTableOptions'
]))
{
$
schemaConfig
->
setDefaultTableOptions
(
$params
[
'defaultTableOptions'
])
;
if
(
!
isset
(
$params
[
'defaultTableOptions'
]))
{
$
params
[
'defaultTableOptions'
]
=
[]
;
}
if
(
!
isset
(
$params
[
'defaultTableOptions'
][
'charset'
])
&&
isset
(
$params
[
'charset'
]))
{
$params
[
'defaultTableOptions'
][
'charset'
]
=
$params
[
'charset'
];
}
$schemaConfig
->
setDefaultTableOptions
(
$params
[
'defaultTableOptions'
]);
return
$schemaConfig
;
}
...
...
tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php
0 → 100644
View file @
63efa539
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\Tests\DBAL\Schema
;
use
Doctrine\Common\EventManager
;
use
Doctrine\DBAL\Configuration
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\MySqlSchemaManager
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\Type
;
use
PHPUnit\Framework\TestCase
;
class
MySqlInheritCharsetTest
extends
TestCase
{
public
function
testInheritTableOptionsFromDatabase
()
:
void
{
// default, no overrides
$options
=
$this
->
getTableOptionsForOverride
();
self
::
assertFalse
(
isset
(
$options
[
'charset'
]));
// explicit utf8
$options
=
$this
->
getTableOptionsForOverride
([
'charset'
=>
'utf8'
]);
self
::
assertTrue
(
isset
(
$options
[
'charset'
]));
self
::
assertSame
(
$options
[
'charset'
],
'utf8'
);
// explicit utf8mb4
$options
=
$this
->
getTableOptionsForOverride
([
'charset'
=>
'utf8mb4'
]);
self
::
assertTrue
(
isset
(
$options
[
'charset'
]));
self
::
assertSame
(
$options
[
'charset'
],
'utf8mb4'
);
}
public
function
testTableOptions
()
:
void
{
$eventManager
=
new
EventManager
();
$driverMock
=
$this
->
createMock
(
'Doctrine\DBAL\Driver'
);
$platform
=
new
\Doctrine\DBAL\Platforms\MySqlPlatform
();
// default, no overrides
$table
=
new
Table
(
'foobar'
,
[
new
Column
(
'aa'
,
Type
::
getType
(
'integer'
))]);
self
::
assertSame
(
$platform
->
getCreateTableSQL
(
$table
),
[
'CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
]
);
// explicit utf8
$table
=
new
Table
(
'foobar'
,
[
new
Column
(
'aa'
,
Type
::
getType
(
'integer'
))]);
$table
->
addOption
(
'charset'
,
'utf8'
);
self
::
assertSame
(
$platform
->
getCreateTableSQL
(
$table
),
[
'CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
]
);
// explicit utf8mb4
$table
=
new
Table
(
'foobar'
,
[
new
Column
(
'aa'
,
Type
::
getType
(
'integer'
))]);
$table
->
addOption
(
'charset'
,
'utf8mb4'
);
self
::
assertSame
(
$platform
->
getCreateTableSQL
(
$table
),
[
'CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'
]
);
}
/**
* @param string[] $overrideOptions
*
* @return string[]
*/
private
function
getTableOptionsForOverride
(
array
$overrideOptions
=
[])
:
array
{
$eventManager
=
new
EventManager
();
$driverMock
=
$this
->
createMock
(
'Doctrine\DBAL\Driver'
);
$platform
=
new
MySqlPlatform
();
$connOptions
=
array_merge
([
'platform'
=>
$platform
],
$overrideOptions
);
$conn
=
new
Connection
(
$connOptions
,
$driverMock
,
new
Configuration
(),
$eventManager
);
$manager
=
new
MySqlSchemaManager
(
$conn
,
$platform
);
$schemaConfig
=
$manager
->
createSchemaConfig
();
return
$schemaConfig
->
getDefaultTableOptions
();
}
}
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