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
44637bfa
Unverified
Commit
44637bfa
authored
Dec 02, 2017
by
Adrien Crivelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Functional test of escaped default values via INSERT and SELECT
parent
7e65c84c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
22 deletions
+67
-22
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+13
-1
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-0
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+20
-15
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+24
-4
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+2
-2
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
44637bfa
...
...
@@ -2306,7 +2306,7 @@ abstract class AbstractPlatform
return
" DEFAULT '"
.
$this
->
convertBooleans
(
$default
)
.
"'"
;
}
return
" DEFAULT "
.
$this
->
quoteStringLiteral
(
$default
);
return
" DEFAULT "
.
$this
->
quote
Default
StringLiteral
(
$default
);
}
/**
...
...
@@ -3570,4 +3570,16 @@ abstract class AbstractPlatform
{
return
"'"
;
}
/**
* Quote a literal string for usage as DEFAULT value.
*
* @param string $str
*
* @return string
*/
protected
function
quoteDefaultStringLiteral
(
string
$str
)
:
string
{
return
$this
->
quoteStringLiteral
(
$str
);
}
}
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
44637bfa
...
...
@@ -1236,4 +1236,12 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return
$type
instanceof
IntegerType
||
$type
instanceof
BigIntType
;
}
/**
* {@inheritDoc}
*/
protected
function
quoteDefaultStringLiteral
(
string
$str
)
:
string
{
return
parent
::
quoteStringLiteral
(
$str
);
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
44637bfa
...
...
@@ -454,21 +454,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$platform
=
$this
->
_sm
->
getDatabasePlatform
();
$this
->
_conn
->
query
(
'DROP TABLE IF EXISTS test_column_defaults_with_create'
);
$escapeSequences
=
[
"
\\
0"
,
// An ASCII NUL (X'00') character
"
\\
'"
,
"''"
,
// Single quote
'\\"'
,
'""'
,
// Double quote
'\\b'
,
// A backspace character
'\\n'
,
// A new-line character
'\\r'
,
// A carriage return character
'\\t'
,
// A tab character
'\\Z'
,
// ASCII 26 (Control+Z)
'\\\\'
,
// A backslash (\) character
'\\%'
,
// A percent (%) character
'\\_'
,
// An underscore (_) character
];
$default
=
implode
(
'+'
,
$escapeSequences
);
$default
=
implode
(
'+'
,
$this
->
getEscapedLiterals
());
$sql
=
"CREATE TABLE test_column_defaults_with_create(
col1 VARCHAR(255) NULL DEFAULT
{
$platform
->
quoteStringLiteral
(
$default
)
}
...
...
@@ -477,4 +463,23 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
"test_column_defaults_with_create"
);
self
::
assertSame
(
$default
,
$onlineTable
->
getColumn
(
'col1'
)
->
getDefault
());
}
protected
function
getEscapedLiterals
()
:
array
{
return
[
"
\\
0"
,
// An ASCII NUL (X'00') character
"
\\
'"
,
// Single quote
"''"
,
// Single quote
'\\"'
,
// Double quote
'""'
,
// Double quote
'\\b'
,
// A backspace character
'\\n'
,
// A new-line character
'\\r'
,
// A carriage return character
'\\t'
,
// A tab character
'\\Z'
,
// ASCII 26 (Control+Z)
'\\\\'
,
// A backslash (\) character
'\\%'
,
// A percent (%) character
'\\_'
,
// An underscore (_) character
];
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
44637bfa
...
...
@@ -1398,18 +1398,38 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
self
::
assertEquals
(
$sequence2InitialValue
,
$actualSequence2
->
getInitialValue
());
}
public
function
testEscapedDefaultValueMustBePreserved
()
/**
* Returns literals that are platform specific escaped.
*
* @return array
*/
protected
function
getEscapedLiterals
()
:
array
{
$value
=
"a
\\
0b
\\
'c
\"
d
\t
e
\\
Zf
\\\\
g''h"
;
return
[
"
\\
'"
,
// A single quote
'\\"'
,
// A double quote
'\\n'
,
// A new-line character
'\\r'
,
// A carriage return character
];
}
public
function
testEscapedDefaultValueMustBePreserved
()
:
void
{
$value
=
implode
(
'+'
,
$this
->
getEscapedLiterals
());
$table
=
new
Table
(
'string_escaped_default_value'
);
$table
->
addColumn
(
'def_string'
,
'string'
,
array
(
'default'
=>
$value
));
$table
->
addColumn
(
'def_foo'
,
'string'
);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$onlineTable
=
$this
->
_sm
->
listTableDetails
(
'string_escaped_default_value'
);
$this
->
assertSame
(
$value
,
$onlineTable
->
getColumn
(
'def_string'
)
->
getDefault
()
);
self
::
assertSame
(
$value
,
$onlineTable
->
getColumn
(
'def_string'
)
->
getDefault
(),
'should be able introspect the value of default'
);
$comparator
=
new
Comparator
();
$this
->
assertFalse
(
$comparator
->
diffTable
(
$table
,
$onlineTable
));
self
::
assertFalse
(
$comparator
->
diffTable
(
$table
,
$onlineTable
),
'introspected schema should have no differences'
);
$this
->
_conn
->
insert
(
'string_escaped_default_value'
,
array
(
'def_foo'
=>
'foo'
));
$row
=
$this
->
_conn
->
fetchAssoc
(
'SELECT def_string FROM string_escaped_default_value'
);
self
::
assertSame
(
$value
,
$row
[
'def_string'
],
'inserted default value should be the configured default value'
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
44637bfa
...
...
@@ -977,7 +977,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
);
}
public
function
testGetDefaultValueDeclarationSQLEscaped
()
public
function
testGetDefaultValueDeclarationSQLEscaped
()
:
void
{
// string must be escaped
$field
=
[
...
...
@@ -985,6 +985,6 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
'default'
=>
'Foo\\Bar'
];
self
::
assertSame
(
" DEFAULT 'Foo
\\
\\
Bar'"
,
$this
->
_platform
->
getDefaultValueDeclarationSQL
(
$field
));
self
::
assertSame
(
" DEFAULT 'Foo
\\
Bar'"
,
$this
->
_platform
->
getDefaultValueDeclarationSQL
(
$field
));
}
}
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