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
4fff9761
Unverified
Commit
4fff9761
authored
Sep 27, 2017
by
belgattitude
Committed by
Luís Cobucci
Nov 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test JSON default values and refactoring
parent
1f9deec3
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
235 additions
and
124 deletions
+235
-124
AbstractMySQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
+9
-6
MariaDb102Platform.php
lib/Doctrine/DBAL/Platforms/MariaDb102Platform.php
+3
-4
MySqlSchemaManager.php
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
+9
-13
AbstractMySQLDriverTest.php
tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
+4
-4
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+116
-97
MariaDb102PlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/MariaDb102PlatformTest.php
+94
-0
No files found.
lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
View file @
4fff9761
...
...
@@ -23,9 +23,10 @@ use Doctrine\DBAL\DBALException;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Exception
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySQL57Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Doctrine\DBAL\Schema\MySqlSchemaManager
;
use
Doctrine\DBAL\VersionAwarePlatformDriver
;
...
...
@@ -126,7 +127,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*
* @return AbstractPlatform|MariaDb102
7
Platform|MySQL57Platform|MySqlPlatform
* @return AbstractPlatform|MariaDb102Platform|MySQL57Platform|MySqlPlatform
* @throws DBALException
*/
public
function
createDatabasePlatformForVersion
(
$version
)
:
AbstractPlatform
...
...
@@ -134,7 +135,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
if
(
false
!==
stripos
(
$version
,
'mariadb'
))
{
$versionNumber
=
$this
->
getMariaDbMysqlVersionNumber
(
$version
);
if
(
version_compare
(
$versionNumber
,
'10.2.7'
,
'>='
))
{
return
new
MariaDb102
7
Platform
();
return
new
MariaDb102Platform
();
}
}
else
{
$versionNumber
=
$this
->
getOracleMysqlVersionNumber
(
$version
);
...
...
@@ -196,7 +197,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*/
public
function
getDatabase
(
\Doctrine\DBAL\Connection
$conn
)
public
function
getDatabase
(
\Doctrine\DBAL\Connection
$conn
)
:
?
string
{
$params
=
$conn
->
getParams
();
...
...
@@ -209,16 +210,18 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
* @return MySqlPlatform
*/
public
function
getDatabasePlatform
()
public
function
getDatabasePlatform
()
:
AbstractPlatform
{
return
new
MySqlPlatform
();
}
/**
* {@inheritdoc}
* @return MySqlSchemaManager
*/
public
function
getSchemaManager
(
\Doctrine\DBAL\Connection
$conn
)
public
function
getSchemaManager
(
\Doctrine\DBAL\Connection
$conn
)
:
AbstractSchemaManager
{
return
new
MySqlSchemaManager
(
$conn
);
}
...
...
lib/Doctrine/DBAL/Platforms/MariaDb102
7
Platform.php
→
lib/Doctrine/DBAL/Platforms/MariaDb102Platform.php
View file @
4fff9761
...
...
@@ -19,18 +19,17 @@
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\Types\BlobType
;
use
Doctrine\DBAL\Types\StringType
;
use
Doctrine\DBAL\Types\TextType
;
use
Doctrine\DBAL\Types\Type
;
/**
* Provides the behavior, features and SQL dialect of the MariaDB 10.2 (10.2.7 GA) database platform.
*
* Note: Should not be used with versions prior ro 10.2.7.
*
* @author Vanvelthem Sébastien
* @link www.doctrine-project.org
*/
final
class
MariaDb102
7
Platform
extends
MySqlPlatform
final
class
MariaDb102Platform
extends
MySqlPlatform
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
View file @
4fff9761
...
...
@@ -19,7 +19,7 @@
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Types\Type
;
...
...
@@ -181,7 +181,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$isNotNull
=
$tableColumn
[
'null'
]
!==
'YES'
;
if
(
$this
->
_platform
instanceof
MariaDb102
7
Platform
)
{
if
(
$this
->
_platform
instanceof
MariaDb102Platform
)
{
$columnDefault
=
$this
->
getMariaDb1027ColumnDefault
(
$this
->
_platform
,
$tableColumn
[
'default'
]
??
null
);
}
else
{
$columnDefault
=
(
isset
(
$tableColumn
[
'default'
]))
?
$tableColumn
[
'default'
]
:
null
;
...
...
@@ -217,24 +217,20 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* Return column default value for MariaDB >= 10.2.7 servers that is
* compatible with existing doctrine mysql implementation (unquoted literals)
* Return Doctrine/Mysql-compatible column default values for MariaDB 10.2.7+ servers.
*
* Since 10.2.7:
*
* 1. Column defaults stored in information_schema are now quoted
* to distinguish them from expressions (see MDEV-10134 for a what is an expression).
* - Since MariaDb 10.2.7 column defaults stored in information_schema are now quoted
* to distinguish them from expressions (see MDEV-10134 for a what is an expression).
* - CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE are stored in information_schema
* as current_timestamp(), currdate(), currtime()
* - Literal escaping is normalized in information schema (store "''" instead of "\'")
*
* @link https://mariadb.com/kb/en/library/information-schema-columns-table/
* @link https://jira.mariadb.org/browse/MDEV-13132
*
* 2. Quoted string defaults use double single quotes as escaping character in information_schema.
*
* @links https://mariadb.com/kb/en/library/string-literals/
*
* @param null|string $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7
*/
private
function
getMariaDb1027ColumnDefault
(
MariaDb102
7
Platform
$platform
,
?
string
$columnDefault
)
:
?
string
{
private
function
getMariaDb1027ColumnDefault
(
MariaDb102Platform
$platform
,
?
string
$columnDefault
)
:
?
string
{
if
(
$columnDefault
===
'NULL'
||
$columnDefault
===
null
)
{
$defaultValue
=
null
;
}
elseif
(
strpos
(
$columnDefault
,
"'"
)
===
0
)
{
...
...
tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
View file @
4fff9761
...
...
@@ -3,7 +3,7 @@
namespace
Doctrine\Tests\DBAL\Driver
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Platforms\MySQL57Platform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Schema\MySqlSchemaManager
;
...
...
@@ -69,9 +69,9 @@ class AbstractMySQLDriverTest extends AbstractDriverTest
array
(
'10.1.2a-MariaDB-a1~lenny-log'
,
MySqlPlatform
::
class
),
array
(
'5.5.40-MariaDB-1~wheezy'
,
MySqlPlatform
::
class
),
array
(
'5.5.40-MariaDB-1~wheezy'
,
MySqlPlatform
::
class
),
array
(
'5.5.5-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102
7
Platform
::
class
),
array
(
'10.2.8-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102
7
Platform
::
class
),
array
(
'10.2.8-MariaDB-1~lenny-log'
,
MariaDb102
7
Platform
::
class
)
array
(
'5.5.5-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102Platform
::
class
),
array
(
'10.2.8-MariaDB-10.2.8+maria~xenial-log'
,
MariaDb102Platform
::
class
),
array
(
'10.2.8-MariaDB-1~lenny-log'
,
MariaDb102Platform
::
class
)
);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
4fff9761
This diff is collapsed.
Click to expand it.
tests/Doctrine/Tests/DBAL/Platforms/MariaDb102
7
PlatformTest.php
→
tests/Doctrine/Tests/DBAL/Platforms/MariaDb102PlatformTest.php
View file @
4fff9761
...
...
@@ -2,19 +2,19 @@
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\MariaDb102
7
Platform
;
use
Doctrine\DBAL\Platforms\MariaDb102Platform
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\Type
;
class
MariaDb102
7
PlatformTest
extends
AbstractMySQLPlatformTestCase
class
MariaDb102PlatformTest
extends
AbstractMySQLPlatformTestCase
{
/**
* {@inheritdoc}
*/
public
function
createPlatform
()
{
return
new
MariaDb102
7
Platform
();
return
new
MariaDb102Platform
();
}
public
function
testHasNativeJsonType
()
...
...
@@ -34,29 +34,61 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
}
/**
* Overrides AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
* Overrides and skips AbstractMySQLPlatformTestCase test regarding propagation
* of unsupported default values for Blob and Text columns.
*
* @see AbstractMySQLPlatformTestCase::testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
*/
public
function
testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes
()
{
$this
->
markTestSkipped
(
'MariaDB102Platform support propagation of default values for BLOB and TEXT columns'
);
}
/**
* Since MariaDB 10.2, Text and Blob can have a default value.
*/
public
function
testPropagateDefaultValuesForTextAndBlobColumnTypes
()
{
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
'def'
));
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
"d''ef"
));
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
));
self
::
assertSame
(
array
(
'CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT \'def\' NOT NULL, def_blob LONGBLOB DEFAULT \'def\' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
)
,
[
"CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT 'd''''ef' NOT NULL, def_blob LONGBLOB DEFAULT 'def' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"
]
,
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'def_text'
,
array
(
'default'
=>
'def'
)
);
$diffTable
->
changeColumn
(
'def_blob'
,
array
(
'default'
=>
'def'
)
);
$diffTable
->
changeColumn
(
'def_text'
,
[
'default'
=>
"d''ef"
]
);
$diffTable
->
changeColumn
(
'def_blob'
,
[
'default'
=>
'def'
]
);
$comparator
=
new
Comparator
();
self
::
assertFalse
(
$comparator
->
diffTable
(
$table
,
$diffTable
));
}
public
function
testPropagateDefaultValuesForJsonColumnType
()
{
$table
=
new
Table
(
"text_json_default_value"
);
$json
=
json_encode
([
'prop1'
=>
"O'Connor"
,
'prop2'
=>
10
]);
$table
->
addColumn
(
'def_json'
,
'text'
,
[
'default'
=>
$json
]);
self
::
assertSame
(
[
"CREATE TABLE text_json_default_value (def_json LONGTEXT DEFAULT '
{
\"prop1\":\"O''Connor\",\"prop2\":10
}
' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"
],
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'def_json'
,
[
'default'
=>
$json
]);
$comparator
=
new
Comparator
();
self
::
assertFalse
(
$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