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
b075331d
Unverified
Commit
b075331d
authored
Oct 30, 2017
by
belgattitude
Committed by
Luís Cobucci
Nov 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes introduced quoting literal support
parent
d2543cab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
109 deletions
+24
-109
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+2
-2
MariaDb1027Platform.php
lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php
+2
-1
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+5
-97
MariaDb1027PlatformTest.php
...Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php
+15
-9
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
b075331d
...
...
@@ -2281,7 +2281,7 @@ abstract class AbstractPlatform
$default
=
$field
[
'default'
];
if
(
!
isset
(
$field
[
'type'
]))
{
return
' DEFAULT '
.
$this
->
quoteStringLiteral
(
$default
)
;
return
" DEFAULT '"
.
$default
.
"'"
;
}
$type
=
$field
[
'type'
];
...
...
@@ -2306,7 +2306,7 @@ abstract class AbstractPlatform
return
" DEFAULT '"
.
$this
->
convertBooleans
(
$default
)
.
"'"
;
}
return
' DEFAULT '
.
$this
->
quoteStringLiteral
(
$default
)
;
return
" DEFAULT '"
.
$default
.
"'"
;
}
/**
...
...
lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php
View file @
b075331d
...
...
@@ -41,11 +41,12 @@ final class MariaDb1027Platform extends MySqlPlatform
/**
* {@inheritdoc}
*
* @link https://mariadb.com/kb/en/library/json-data-type/
*/
public
function
getJsonTypeDeclarationSQL
(
array
$field
)
:
string
{
return
'
JSON
'
;
return
'
LONGTEXT
'
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
b075331d
...
...
@@ -333,68 +333,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertTrue
(
$columns
[
'col_unsigned'
]
->
getUnsigned
());
}
/**
* As of MariaDB 10.2.7, nullable default values literals are always single quoted in
* information_schema. Non-nullable defaults behaviour is not affected.
* This test ensure accidental removal of double single encoded defaults for MariaDB >= 10.2.7.
*
* @link https://mariadb.com/kb/en/library/information-schema-columns-table/
* @link https://dev.mysql.com/doc/refman/5.5/en/string-literals.html
*/
public
function
testColumnDefaultValuesDoubleQuoted
()
:
void
{
$table
=
new
Table
(
"test_column_default_values_double_quoted"
);
$table
->
addColumn
(
'string_nullable_quoted'
,
'string'
,
[
'notnull'
=>
false
,
'default'
=>
'NULL'
]);
$table
->
addColumn
(
'string_nullable_double_quoted'
,
'string'
,
[
'notnull'
=>
false
,
'default'
=>
"'NULL'"
]);
$table
->
addColumn
(
'string_notnull_quoted'
,
'string'
,
[
'notnull'
=>
true
,
'default'
=>
'NULL'
]);
$table
->
addColumn
(
'string_notnull_double_quoted'
,
'string'
,
[
'notnull'
=>
true
,
'default'
=>
"
\\
'NULL
\\
'"
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_default_values_double_quoted"
);
self
::
assertSame
(
'NULL'
,
$onlineTable
->
getColumn
(
'string_nullable_quoted'
)
->
getDefault
());
self
::
assertSame
(
"'NULL'"
,
$onlineTable
->
getColumn
(
'string_nullable_double_quoted'
)
->
getDefault
());
self
::
assertSame
(
"NULL"
,
$onlineTable
->
getColumn
(
'string_notnull_quoted'
)
->
getDefault
());
self
::
assertSame
(
"
\\
'NULL
\\
'"
,
$onlineTable
->
getColumn
(
'string_notnull_double_quoted'
)
->
getDefault
());
$comparator
=
new
Comparator
();
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
,
"Tables should be identical with double quoted literals."
);
}
/**
* @link https://mariadb.com/kb/en/library/string-literals
* @link https://dev.mysql.com/doc/refman/5.7/en/string-literals.html
*/
public
function
testColumnEscapingDefaultValuesDoesNotTriggerSchemaChange
()
:
void
{
$table
=
new
Table
(
"test_column_default_values_escaping"
);
$table
->
addColumn
(
'single_backslash'
,
'string'
,
[
'default'
=>
'F\Q\D\N'
]);
$table
->
addColumn
(
'double_backslash'
,
'string'
,
[
'default'
=>
'F\\Q\\D\\N'
]);
$table
->
addColumn
(
'triple_backslash'
,
'string'
,
[
'default'
=>
'a\\\z'
]);
$table
->
addColumn
(
'repeated_single_quotes'
,
'string'
,
[
'default'
=>
"a''z"
]);
$table
->
addColumn
(
'backslash_double_quote'
,
'string'
,
[
'default'
=>
'a\"z'
]);
$table
->
addColumn
(
'backslash_newline'
,
'string'
,
[
'default'
=>
'a\nz'
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_default_values_escaping"
);
self
::
assertSame
(
'F\Q\D\N'
,
$onlineTable
->
getColumn
(
'single_backslash'
)
->
getDefault
());
self
::
assertSame
(
'F\\Q\\D\\N'
,
$onlineTable
->
getColumn
(
'double_backslash'
)
->
getDefault
());
self
::
assertSame
(
'a\\\z'
,
$onlineTable
->
getColumn
(
'triple_backslash'
)
->
getDefault
());
self
::
assertSame
(
"a''z"
,
$onlineTable
->
getColumn
(
'repeated_single_quotes'
)
->
getDefault
());
self
::
assertSame
(
'a\"z'
,
$onlineTable
->
getColumn
(
'backslash_double_quote'
)
->
getDefault
());
self
::
assertSame
(
'a\nz'
,
$onlineTable
->
getColumn
(
'backslash_newline'
)
->
getDefault
());
$comparator
=
new
Comparator
();
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
,
"Tables should be identical with values escape sequences."
);
}
public
function
testJsonColumnType
()
:
void
{
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
...
...
@@ -411,36 +349,6 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertSame
(
TYPE
::
JSON
,
$columns
[
'col_json'
]
->
getType
()
->
getName
());
}
/**
* Ensure that a table created outside doctrine and containing
* quoted default values does not trigger a table diff change. I
* Note: MariaDb 10.2 silently change "\'" into "''" when storing in
* information schema, MariaDb102Platform should normalize the table details.
*/
public
function
testExistingTableWithQuotedDefaultsDoesNotTriggerChange
()
:
void
{
$this
->
_conn
->
query
(
'DROP TABLE IF EXISTS test_column_defaults_with_create'
);
$sql
=
"
CREATE TABLE test_column_defaults_with_create (
col1 VARCHAR(255) NULL DEFAULT 'O''Connor\'
\"
',
col2 VARCHAR(255) NOT NULL DEFAULT 'O''Connor\'
\"
'
);
"
;
$this
->
_conn
->
query
(
$sql
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_defaults_with_create"
);
self
::
assertSame
(
"O'Connor'
\"
"
,
$onlineTable
->
getColumn
(
'col1'
)
->
getDefault
());
self
::
assertSame
(
"O'Connor'
\"
"
,
$onlineTable
->
getColumn
(
'col2'
)
->
getDefault
());
$table
=
new
Table
(
"test_column_defaults_no_diff"
);
$table
->
addColumn
(
'col1'
,
'string'
,
[
'notnull'
=>
false
,
'default'
=>
"O'Connor'
\"
"
]);
$table
->
addColumn
(
'col2'
,
'string'
,
[
'notnull'
=>
true
,
'default'
=>
"O'Connor'
\"
"
]);
$comparator
=
new
Comparator
();
$diff
=
$comparator
->
diffTable
(
$table
,
$onlineTable
);
self
::
assertFalse
(
$diff
);
}
public
function
testColumnDefaultCurrentTimestamp
()
:
void
{
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
...
...
@@ -552,20 +460,20 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table
=
new
Table
(
"text_blob_default_value"
);
$json
=
json_encode
([
'prop1'
=>
"
O'Connor
"
,
'prop2'
=>
10
]);
$json
=
json_encode
([
'prop1'
=>
"
Hello
"
,
'prop2'
=>
10
]);
$table
->
addColumn
(
'def_text'
,
'text'
,
[
'default'
=>
"
O'Connor
"
]);
$table
->
addColumn
(
'def_text'
,
'text'
,
[
'default'
=>
"
Hello
"
]);
$table
->
addColumn
(
'def_text_null'
,
'text'
,
[
'notnull'
=>
false
,
'default'
=>
'def'
]);
$table
->
addColumn
(
'def_blob'
,
'blob'
,
[
'default'
=>
'
\F\Q\D\N
'
]);
$table
->
addColumn
(
'def_blob'
,
'blob'
,
[
'default'
=>
'
World
'
]);
$table
->
addColumn
(
'def_json'
,
'json'
,
[
'default'
=>
$json
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"text_blob_default_value"
);
self
::
assertSame
(
"
O'Connor
"
,
$onlineTable
->
getColumn
(
'def_text'
)
->
getDefault
());
self
::
assertSame
(
"
Hello
"
,
$onlineTable
->
getColumn
(
'def_text'
)
->
getDefault
());
self
::
assertSame
(
'def'
,
$onlineTable
->
getColumn
(
'def_text_null'
)
->
getDefault
());
self
::
assertSame
(
'
\F\Q\D\N
'
,
$onlineTable
->
getColumn
(
'def_blob'
)
->
getDefault
());
self
::
assertSame
(
'
World
'
,
$onlineTable
->
getColumn
(
'def_blob'
)
->
getDefault
());
self
::
assertSame
(
$json
,
$onlineTable
->
getColumn
(
'def_json'
)
->
getDefault
());
$comparator
=
new
Comparator
();
...
...
tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php
View file @
b075331d
...
...
@@ -22,9 +22,13 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
self
::
assertTrue
(
$this
->
_platform
->
hasNativeJsonType
());
}
/**
* From MariaDB 10.2.7, JSON type is an alias to LONGTEXT
* @link https://mariadb.com/kb/en/library/json-data-type/
*/
public
function
testReturnsJsonTypeDeclarationSQL
()
:
void
{
self
::
assertSame
(
'
JSON
'
,
$this
->
_platform
->
getJsonTypeDeclarationSQL
([]));
self
::
assertSame
(
'
LONGTEXT
'
,
$this
->
_platform
->
getJsonTypeDeclarationSQL
([]));
}
public
function
testInitializesJsonTypeMapping
()
:
void
...
...
@@ -51,18 +55,18 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
{
$table
=
new
Table
(
"text_blob_default_value"
);
$table
->
addColumn
(
'def_text'
,
'text'
,
array
(
'default'
=>
"d''ef"
)
);
$table
->
addColumn
(
'def_blob'
,
'blob'
,
array
(
'default'
=>
'def'
)
);
$table
->
addColumn
(
'def_text'
,
Type
::
TEXT
,
[
'default'
=>
"hello"
]
);
$table
->
addColumn
(
'def_blob'
,
Type
::
BLOB
,
[
'default'
=>
'world'
]
);
self
::
assertSame
(
[
"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"
],
[
"CREATE TABLE text_blob_default_value (def_text LONGTEXT DEFAULT '
hello' NOT NULL, def_blob LONGBLOB DEFAULT 'world
' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"
],
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
$diffTable
=
clone
$table
;
$diffTable
->
changeColumn
(
'def_text'
,
[
'default'
=>
"
d''ef
"
]);
$diffTable
->
changeColumn
(
'def_blob'
,
[
'default'
=>
'
def
'
]);
$diffTable
->
changeColumn
(
'def_text'
,
[
'default'
=>
"
hello
"
]);
$diffTable
->
changeColumn
(
'def_blob'
,
[
'default'
=>
'
world
'
]);
$comparator
=
new
Comparator
();
...
...
@@ -73,12 +77,14 @@ class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase
{
$table
=
new
Table
(
"text_json_default_value"
);
$json
=
json_encode
([
'prop1'
=>
"O'Connor"
,
'prop2'
=>
10
]);
$json
=
json_encode
([
'prop1'
=>
"Hello"
,
'prop2'
=>
10
]);
$table
->
addColumn
(
'def_json'
,
Type
::
TEXT
,
[
'default'
=>
$json
]);
$
table
->
addColumn
(
'def_json'
,
'text'
,
[
'default'
=>
$json
]
);
$
jsonType
=
$this
->
createPlatform
()
->
getJsonTypeDeclarationSQL
(
$table
->
getColumn
(
'def_json'
)
->
toArray
()
);
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"
],
[
"CREATE TABLE text_json_default_value (def_json
$jsonType
DEFAULT '
{
\"prop1\":\"Hello
\",\"prop2\":10
}
' NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"
],
$this
->
_platform
->
getCreateTableSQL
(
$table
)
);
...
...
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