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
87273b29
Commit
87273b29
authored
Dec 20, 2013
by
Steve Müller
Committed by
Martin Hasoň
Feb 10, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add column collation support for Drizzle
parent
e2a7688a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
4 deletions
+149
-4
DrizzlePlatform.php
lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
+119
-1
DrizzleSchemaManager.php
lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
+9
-2
DrizzleSchemaManagerTest.php
...Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php
+21
-1
No files found.
lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
View file @
87273b29
...
@@ -228,6 +228,116 @@ class DrizzlePlatform extends AbstractPlatform
...
@@ -228,6 +228,116 @@ class DrizzlePlatform extends AbstractPlatform
return
'DROP DATABASE '
.
$name
;
return
'DROP DATABASE '
.
$name
;
}
}
/**
* {@inheritDoc}
*/
protected
function
_getCreateTableSQL
(
$tableName
,
array
$columns
,
array
$options
=
array
())
{
$queryFields
=
$this
->
getColumnDeclarationListSQL
(
$columns
);
if
(
isset
(
$options
[
'uniqueConstraints'
])
&&
!
empty
(
$options
[
'uniqueConstraints'
]))
{
foreach
(
$options
[
'uniqueConstraints'
]
as
$index
=>
$definition
)
{
$queryFields
.=
', '
.
$this
->
getUniqueConstraintDeclarationSQL
(
$index
,
$definition
);
}
}
// add all indexes
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
foreach
(
$options
[
'indexes'
]
as
$index
=>
$definition
)
{
$queryFields
.=
', '
.
$this
->
getIndexDeclarationSQL
(
$index
,
$definition
);
}
}
// attach all primary keys
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$keyColumns
=
array_unique
(
array_values
(
$options
[
'primary'
]));
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
$query
=
'CREATE '
;
if
(
!
empty
(
$options
[
'temporary'
]))
{
$query
.=
'TEMPORARY '
;
}
$query
.=
'TABLE '
.
$tableName
.
' ('
.
$queryFields
.
') '
;
$query
.=
$this
->
buildTableOptions
(
$options
);
$query
.=
$this
->
buildPartitionOptions
(
$options
);
$sql
[]
=
$query
;
if
(
isset
(
$options
[
'foreignKeys'
]))
{
foreach
((
array
)
$options
[
'foreignKeys'
]
as
$definition
)
{
$sql
[]
=
$this
->
getCreateForeignKeySQL
(
$definition
,
$tableName
);
}
}
return
$sql
;
}
/**
* Build SQL for table options
*
* @param array $options
*
* @return string
*/
private
function
buildTableOptions
(
array
$options
)
{
if
(
isset
(
$options
[
'table_options'
]))
{
return
$options
[
'table_options'
];
}
$tableOptions
=
array
();
// Collate
if
(
!
isset
(
$options
[
'collate'
]))
{
$options
[
'collate'
]
=
'utf8_unicode_ci'
;
}
$tableOptions
[]
=
sprintf
(
'COLLATE %s'
,
$options
[
'collate'
]);
// Engine
if
(
!
isset
(
$options
[
'engine'
]))
{
$options
[
'engine'
]
=
'InnoDB'
;
}
$tableOptions
[]
=
sprintf
(
'ENGINE = %s'
,
$options
[
'engine'
]);
// Auto increment
if
(
isset
(
$options
[
'auto_increment'
]))
{
$tableOptions
[]
=
sprintf
(
'AUTO_INCREMENT = %s'
,
$options
[
'auto_increment'
]);
}
// Comment
if
(
isset
(
$options
[
'comment'
]))
{
$comment
=
trim
(
$options
[
'comment'
],
" '"
);
$tableOptions
[]
=
sprintf
(
"COMMENT = '%s' "
,
str_replace
(
"'"
,
"''"
,
$comment
));
}
// Row format
if
(
isset
(
$options
[
'row_format'
]))
{
$tableOptions
[]
=
sprintf
(
'ROW_FORMAT = %s'
,
$options
[
'row_format'
]);
}
return
implode
(
' '
,
$tableOptions
);
}
/**
* Build SQL for partition options.
*
* @param array $options
*
* @return string
*/
private
function
buildPartitionOptions
(
array
$options
)
{
return
(
isset
(
$options
[
'partition_options'
]))
?
' '
.
$options
[
'partition_options'
]
:
''
;
}
/**
/**
* {@inheritDoc}
* {@inheritDoc}
*/
*/
...
@@ -264,7 +374,7 @@ class DrizzlePlatform extends AbstractPlatform
...
@@ -264,7 +374,7 @@ class DrizzlePlatform extends AbstractPlatform
}
}
return
"SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT, IS_NULLABLE, IS_AUTO_INCREMENT, CHARACTER_MAXIMUM_LENGTH, COLUMN_DEFAULT,"
.
return
"SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT, IS_NULLABLE, IS_AUTO_INCREMENT, CHARACTER_MAXIMUM_LENGTH, COLUMN_DEFAULT,"
.
" NUMERIC_PRECISION, NUMERIC_SCALE"
.
" NUMERIC_PRECISION, NUMERIC_SCALE
, COLLATION_NAME
"
.
" FROM DATA_DICTIONARY.COLUMNS"
.
" FROM DATA_DICTIONARY.COLUMNS"
.
" WHERE TABLE_SCHEMA="
.
$database
.
" AND TABLE_NAME = '"
.
$table
.
"'"
;
" WHERE TABLE_SCHEMA="
.
$database
.
" AND TABLE_NAME = '"
.
$table
.
"'"
;
}
}
...
@@ -333,6 +443,14 @@ class DrizzlePlatform extends AbstractPlatform
...
@@ -333,6 +443,14 @@ class DrizzlePlatform extends AbstractPlatform
return
false
;
return
false
;
}
}
/**
* {@inheritdoc}
*/
public
function
supportsColumnCollation
()
{
return
true
;
}
/**
/**
* {@inheritDoc}
* {@inheritDoc}
*/
*/
...
...
lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
View file @
87273b29
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
namespace
Doctrine\DBAL\Schema
;
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Types\Type
;
/**
/**
* Schema manager for the Drizzle RDBMS.
* Schema manager for the Drizzle RDBMS.
*
*
...
@@ -31,7 +33,6 @@ class DrizzleSchemaManager extends AbstractSchemaManager
...
@@ -31,7 +33,6 @@ class DrizzleSchemaManager extends AbstractSchemaManager
*/
*/
protected
function
_getPortableTableColumnDefinition
(
$tableColumn
)
protected
function
_getPortableTableColumnDefinition
(
$tableColumn
)
{
{
$tableName
=
$tableColumn
[
'COLUMN_NAME'
];
$dbType
=
strtolower
(
$tableColumn
[
'DATA_TYPE'
]);
$dbType
=
strtolower
(
$tableColumn
[
'DATA_TYPE'
]);
$type
=
$this
->
_platform
->
getDoctrineTypeMapping
(
$dbType
);
$type
=
$this
->
_platform
->
getDoctrineTypeMapping
(
$dbType
);
...
@@ -48,7 +49,13 @@ class DrizzleSchemaManager extends AbstractSchemaManager
...
@@ -48,7 +49,13 @@ class DrizzleSchemaManager extends AbstractSchemaManager
'comment'
=>
(
isset
(
$tableColumn
[
'COLUMN_COMMENT'
])
?
$tableColumn
[
'COLUMN_COMMENT'
]
:
null
),
'comment'
=>
(
isset
(
$tableColumn
[
'COLUMN_COMMENT'
])
?
$tableColumn
[
'COLUMN_COMMENT'
]
:
null
),
);
);
return
new
Column
(
$tableName
,
\Doctrine\DBAL\Types\Type
::
getType
(
$type
),
$options
);
$column
=
new
Column
(
$tableColumn
[
'COLUMN_NAME'
],
Type
::
getType
(
$type
),
$options
);
if
(
!
empty
(
$tableColumn
[
'COLLATION_NAME'
]))
{
$column
->
setPlatformOption
(
'collation'
,
$tableColumn
[
'COLLATION_NAME'
]);
}
return
$column
;
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php
View file @
87273b29
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
namespace
Doctrine\Tests\DBAL\Functional\Schema
;
use
Doctrine\DBAL\Schema\Table
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
class
DrizzleSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
class
DrizzleSchemaManagerTest
extends
SchemaManagerFunctionalTestCase
...
@@ -10,7 +12,7 @@ class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -10,7 +12,7 @@ class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
{
$tableName
=
'test_binary_table'
;
$tableName
=
'test_binary_table'
;
$table
=
new
\Doctrine\DBAL\Schema\
Table
(
$tableName
);
$table
=
new
Table
(
$tableName
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'column_varbinary'
,
'binary'
,
array
());
$table
->
addColumn
(
'column_varbinary'
,
'binary'
,
array
());
$table
->
addColumn
(
'column_binary'
,
'binary'
,
array
(
'fixed'
=>
true
));
$table
->
addColumn
(
'column_binary'
,
'binary'
,
array
(
'fixed'
=>
true
));
...
@@ -26,4 +28,22 @@ class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -26,4 +28,22 @@ class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Types\BinaryType'
,
$table
->
getColumn
(
'column_binary'
)
->
getType
());
$this
->
assertInstanceOf
(
'Doctrine\DBAL\Types\BinaryType'
,
$table
->
getColumn
(
'column_binary'
)
->
getType
());
$this
->
assertFalse
(
$table
->
getColumn
(
'column_binary'
)
->
getFixed
());
$this
->
assertFalse
(
$table
->
getColumn
(
'column_binary'
)
->
getFixed
());
}
}
public
function
testColumnCollation
()
{
$table
=
new
Table
(
'test_collation'
);
$table
->
addOption
(
'collate'
,
$collation
=
'utf8_unicode_ci'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$table
->
addColumn
(
'text'
,
'text'
);
$table
->
addColumn
(
'foo'
,
'text'
)
->
setPlatformOption
(
'collation'
,
'utf8_swedish_ci'
);
$table
->
addColumn
(
'bar'
,
'text'
)
->
setPlatformOption
(
'collation'
,
'utf8_general_ci'
);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
'test_collation'
);
$this
->
assertArrayNotHasKey
(
'collation'
,
$columns
[
'id'
]
->
getPlatformOptions
());
$this
->
assertEquals
(
'utf8_unicode_ci'
,
$columns
[
'text'
]
->
getPlatformOption
(
'collation'
));
$this
->
assertEquals
(
'utf8_swedish_ci'
,
$columns
[
'foo'
]
->
getPlatformOption
(
'collation'
));
$this
->
assertEquals
(
'utf8_general_ci'
,
$columns
[
'bar'
]
->
getPlatformOption
(
'collation'
));
}
}
}
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