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
b841ba7c
Unverified
Commit
b841ba7c
authored
Oct 15, 2017
by
Adrien Crivelli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for backslashes in default values on PostgreSQL and SQLite
parent
b83ba1a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+22
-2
SqliteSchemaManager.php
lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
+3
-2
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+1
-1
No files found.
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
b841ba7c
...
@@ -384,11 +384,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -384,11 +384,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$length
=
null
;
$length
=
null
;
break
;
break
;
case
'text'
:
case
'text'
:
case
'_varchar'
:
case
'varchar'
:
$tableColumn
[
'default'
]
=
$this
->
fixDefaultValueQuotes
(
$tableColumn
[
'default'
]);
$fixed
=
false
;
$fixed
=
false
;
break
;
break
;
case
'varchar'
:
case
'interval'
:
case
'interval'
:
case
'_varchar'
:
$fixed
=
false
;
$fixed
=
false
;
break
;
break
;
case
'char'
:
case
'char'
:
...
@@ -468,4 +469,23 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -468,4 +469,23 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
return
$defaultValue
;
return
$defaultValue
;
}
}
/**
* Un-escape a default value as given by PostgreSQL
*
* @param null|string $default
*
* @return null|string
*/
private
function
fixDefaultValueQuotes
(
?
string
$default
)
:
?
string
{
if
(
$default
===
null
)
{
return
$default
;
}
$default
=
str_replace
(
"
\\\\
"
,
"
\\
"
,
$default
);
$default
=
str_replace
(
"''"
,
"'"
,
$default
);
return
$default
;
}
}
}
lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
View file @
b841ba7c
...
@@ -308,8 +308,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
...
@@ -308,8 +308,9 @@ class SqliteSchemaManager extends AbstractSchemaManager
$default
=
null
;
$default
=
null
;
}
}
if
(
$default
!==
null
)
{
if
(
$default
!==
null
)
{
// SQLite returns strings wrapped in single quotes, so we need to strip them
// SQLite returns strings wrapped in single quotes and escaped, so we need to strip them
$default
=
preg_replace
(
"/^'(.*)'$/"
,
'\1'
,
$default
);
$default
=
preg_replace
(
"/^'(.*)'$/s"
,
'\1'
,
$default
);
$default
=
str_replace
(
"''"
,
"'"
,
$default
);
}
}
$notnull
=
(
bool
)
$tableColumn
[
'notnull'
];
$notnull
=
(
bool
)
$tableColumn
[
'notnull'
];
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
b841ba7c
...
@@ -1400,7 +1400,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
...
@@ -1400,7 +1400,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
public
function
testEscapedDefaultValueMustBePreserved
()
public
function
testEscapedDefaultValueMustBePreserved
()
{
{
$value
=
"a
\\
0
a
\\
'a
\"
a
\n
a
\r
a
\t
a
\\
Za
\\\\
a"
;
$value
=
"a
\\
0
b
\\
'c
\"
d
\t
e
\\
Zf
\\\\
g"
;
$table
=
new
Table
(
'string_escaped_default_value'
);
$table
=
new
Table
(
'string_escaped_default_value'
);
$table
->
addColumn
(
'def_string'
,
'string'
,
array
(
'default'
=>
$value
));
$table
->
addColumn
(
'def_string'
,
'string'
,
array
(
'default'
=>
$value
));
...
...
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