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
30359f81
Commit
30359f81
authored
Jan 16, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix default values for TEXT/BLOB column type on MySQL
parent
0a7df7c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+24
-0
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+36
-0
AbstractMySQLPlatformTestCase.php
...ne/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
+24
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
30359f81
...
...
@@ -23,6 +23,8 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\BlobType
;
use
Doctrine\DBAL\Types\TextType
;
/**
* The MySqlPlatform provides the behavior, features and SQL dialect of the
...
...
@@ -463,6 +465,19 @@ class MySqlPlatform extends AbstractPlatform
return
$sql
;
}
/**
* {@inheritdoc}
*/
public
function
getDefaultValueDeclarationSQL
(
$field
)
{
// Unset the default value if the given field definition does not allow default values.
if
(
$field
[
'type'
]
instanceof
TextType
||
$field
[
'type'
]
instanceof
BlobType
)
{
$field
[
'default'
]
=
null
;
}
return
parent
::
getDefaultValueDeclarationSQL
(
$field
);
}
/**
* Build SQL for table options
*
...
...
@@ -570,6 +585,15 @@ class MySqlPlatform extends AbstractPlatform
/* @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */
$column
=
$columnDiff
->
column
;
$columnArray
=
$column
->
toArray
();
// Don't propagate default value changes for unsupported column types.
if
(
$columnDiff
->
hasChanged
(
'default'
)
&&
count
(
$columnDiff
->
changedProperties
)
===
1
&&
(
$columnArray
[
'type'
]
instanceof
TextType
||
$columnArray
[
'type'
]
instanceof
BlobType
)
)
{
continue
;
}
$columnArray
[
'comment'
]
=
$this
->
getColumnComment
(
$column
);
$queryParts
[]
=
'CHANGE '
.
(
$columnDiff
->
getOldColumnName
()
->
getQuotedName
(
$this
))
.
' '
.
$this
->
getColumnDeclarationSQL
(
$column
->
getQuotedName
(
$this
),
$columnArray
);
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
30359f81
...
...
@@ -117,4 +117,40 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertFalse
(
$table
->
hasPrimaryKey
());
$this
->
assertFalse
(
$table
->
getColumn
(
'id'
)
->
getAutoincrement
());
}
/**
* @group DBAL-789
*/
public
function
testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes
()
{
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_text_null'
,
'text'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
));
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_blob_null'
,
'blob'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
));
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"text_blob_default_value"
);
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_text'
)
->
getDefault
());
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getDefault
());
$this
->
assertFalse
(
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getNotnull
());
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_blob'
)
->
getDefault
());
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getDefault
());
$this
->
assertFalse
(
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getNotnull
());
$comparator
=
new
Comparator
();
$this
->
_sm
->
alterTable
(
$comparator
->
diffTable
(
$table
,
$onlineTable
));
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"text_blob_default_value"
);
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_text'
)
->
getDefault
());
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getDefault
());
$this
->
assertFalse
(
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getNotnull
());
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_blob'
)
->
getDefault
());
$this
->
assertNull
(
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getDefault
());
$this
->
assertFalse
(
$onlineTable
->
getColumn
(
'def_blob_null'
)
->
getNotnull
());
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php
View file @
30359f81
...
...
@@ -501,4 +501,28 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
'CREATE INDEX `bar` ON `table` (id)'
,
);
}
public
function
testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes
()
{
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_text_null'
,
'text'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
));
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_blob_null'
,
'blob'
,
array
(
'notnull'
=>
false
,
'default'
=>
'def'
));
$this
->
assertSame
(
array
(
'CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
),
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'def_text'
,
array
(
'default'
=>
null
));
$diffTable
->
changeColumn
(
'def_text_null'
,
array
(
'default'
=>
null
));
$diffTable
->
changeColumn
(
'def_blob'
,
array
(
'default'
=>
null
));
$diffTable
->
changeColumn
(
'def_blob_null'
,
array
(
'default'
=>
null
));
$comparator
=
new
Comparator
();
$this
->
assertEmpty
(
$this
->
_platform
->
getAlterTableSQL
(
$comparator
->
diffTable
(
$table
,
$diffTable
)));
}
}
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