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
73f38e72
Commit
73f38e72
authored
Dec 28, 2018
by
AlterTable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add column charset for MySql
parent
df4071e1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
0 deletions
+72
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+8
-0
MySqlSchemaManager.php
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
+3
-0
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+53
-0
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+8
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
73f38e72
...
...
@@ -953,6 +953,14 @@ SQL
return
$this
->
getUnsignedDeclaration
(
$columnDef
)
.
$autoinc
;
}
/**
* {@inheritDoc}
*/
public
function
getColumnCharsetDeclarationSQL
(
$charset
)
{
return
'CHARACTER SET '
.
$charset
;
}
/**
* {@inheritDoc}
*/
...
...
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
View file @
73f38e72
...
...
@@ -192,6 +192,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
$column
=
new
Column
(
$tableColumn
[
'field'
],
Type
::
getType
(
$type
),
$options
);
if
(
isset
(
$tableColumn
[
'characterset'
]))
{
$column
->
setPlatformOption
(
'charset'
,
$tableColumn
[
'characterset'
]);
}
if
(
isset
(
$tableColumn
[
'collation'
]))
{
$column
->
setPlatformOption
(
'collation'
,
$tableColumn
[
'collation'
]);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
73f38e72
...
...
@@ -201,6 +201,59 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertFalse
(
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getNotnull
());
}
public
function
testColumnCharset
()
{
$table
=
new
Table
(
'test_column_charset'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'no_charset'
,
'text'
);
$table
->
addColumn
(
'foo'
,
'text'
)
->
setPlatformOption
(
'charset'
,
'ascii'
);
$table
->
addColumn
(
'bar'
,
'text'
)
->
setPlatformOption
(
'charset'
,
'latin1'
);
$this
->
schemaManager
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'test_column_charset'
);
self
::
assertFalse
(
$columns
[
'id'
]
->
hasPlatformOption
(
'charset'
));
self
::
assertEquals
(
'utf8'
,
$columns
[
'no_charset'
]
->
getPlatformOption
(
'charset'
));
self
::
assertEquals
(
'ascii'
,
$columns
[
'foo'
]
->
getPlatformOption
(
'charset'
));
self
::
assertEquals
(
'latin1'
,
$columns
[
'bar'
]
->
getPlatformOption
(
'charset'
));
}
public
function
testAlterColumnCharset
()
{
$tableName
=
'test_alter_column_charset'
;
$table
=
new
Table
(
$tableName
);
$table
->
addColumn
(
'col_text'
,
'text'
)
->
setPlatformOption
(
'charset'
,
'utf8'
);
$this
->
schemaManager
->
dropAndCreateTable
(
$table
);
$diffTable
=
clone
$table
;
$diffTable
->
getColumn
(
'col_text'
)
->
setPlatformOption
(
'charset'
,
'ascii'
);
$comparator
=
new
Comparator
();
$this
->
schemaManager
->
alterTable
(
$comparator
->
diffTable
(
$table
,
$diffTable
));
$table
=
$this
->
schemaManager
->
listTableDetails
(
$tableName
);
self
::
assertEquals
(
'ascii'
,
$table
->
getColumn
(
'col_text'
)
->
getPlatformOption
(
'charset'
));
}
public
function
testColumnCharsetChange
()
{
$table
=
new
Table
(
'test_column_charset_change'
);
$table
->
addColumn
(
'col_string'
,
'string'
)
->
setLength
(
100
)
->
setNotnull
(
true
)
->
setPlatformOption
(
'charset'
,
'utf8'
);
$diffTable
=
clone
$table
;
$diffTable
->
getColumn
(
'col_string'
)
->
setPlatformOption
(
'charset'
,
'ascii'
);
$fromSchema
=
new
Schema
([
$table
]);
$toSchema
=
new
Schema
([
$diffTable
]);
$diff
=
$fromSchema
->
getMigrateToSql
(
$toSchema
,
$this
->
connection
->
getDatabasePlatform
());
self
::
assertContains
(
'ALTER TABLE test_column_charset_change CHANGE col_string col_string VARCHAR(100) CHARACTER SET ascii NOT NULL'
,
$diff
);
}
public
function
testColumnCollation
()
{
$table
=
new
Table
(
'test_collation'
);
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
73f38e72
...
...
@@ -905,6 +905,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
self
::
assertNotContains
(
'DATABASE()'
,
$sql
);
}
public
function
testColumnCharsetDeclarationSQL
()
:
void
{
self
::
assertSame
(
'CHARACTER SET ascii'
,
$this
->
platform
->
getColumnCharsetDeclarationSQL
(
'ascii'
)
);
}
public
function
testSupportsColumnCollation
()
:
void
{
self
::
assertTrue
(
$this
->
platform
->
supportsColumnCollation
());
...
...
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