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
5eb1a93b
Commit
5eb1a93b
authored
Jan 24, 2017
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes #2427: fix negative default value introspection on PostgreSQL 9.4
parent
036abc08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletion
+47
-1
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+22
-1
PostgreSqlSchemaManagerTest.php
...ts/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
+25
-0
No files found.
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
5eb1a93b
...
@@ -316,7 +316,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -316,7 +316,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$autoincrement
=
true
;
$autoincrement
=
true
;
}
}
if
(
preg_match
(
"/^
'(.*)'
::.*$/"
,
$tableColumn
[
'default'
],
$matches
))
{
if
(
preg_match
(
"/^
['(](.*)[')]
::.*$/"
,
$tableColumn
[
'default'
],
$matches
))
{
$tableColumn
[
'default'
]
=
$matches
[
1
];
$tableColumn
[
'default'
]
=
$matches
[
1
];
}
}
...
@@ -354,15 +354,18 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -354,15 +354,18 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
switch
(
$dbType
)
{
switch
(
$dbType
)
{
case
'smallint'
:
case
'smallint'
:
case
'int2'
:
case
'int2'
:
$tableColumn
[
'default'
]
=
$this
->
fixVersion94NegativeNumericDefaultValue
(
$tableColumn
[
'default'
]);
$length
=
null
;
$length
=
null
;
break
;
break
;
case
'int'
:
case
'int'
:
case
'int4'
:
case
'int4'
:
case
'integer'
:
case
'integer'
:
$tableColumn
[
'default'
]
=
$this
->
fixVersion94NegativeNumericDefaultValue
(
$tableColumn
[
'default'
]);
$length
=
null
;
$length
=
null
;
break
;
break
;
case
'bigint'
:
case
'bigint'
:
case
'int8'
:
case
'int8'
:
$tableColumn
[
'default'
]
=
$this
->
fixVersion94NegativeNumericDefaultValue
(
$tableColumn
[
'default'
]);
$length
=
null
;
$length
=
null
;
break
;
break
;
case
'bool'
:
case
'bool'
:
...
@@ -398,6 +401,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -398,6 +401,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case
'decimal'
:
case
'decimal'
:
case
'money'
:
case
'money'
:
case
'numeric'
:
case
'numeric'
:
$tableColumn
[
'default'
]
=
$this
->
fixVersion94NegativeNumericDefaultValue
(
$tableColumn
[
'default'
]);
if
(
preg_match
(
'([A-Za-z]+\(([0-9]+)\,([0-9]+)\))'
,
$tableColumn
[
'complete_type'
],
$match
))
{
if
(
preg_match
(
'([A-Za-z]+\(([0-9]+)\,([0-9]+)\))'
,
$tableColumn
[
'complete_type'
],
$match
))
{
$precision
=
$match
[
1
];
$precision
=
$match
[
1
];
$scale
=
$match
[
2
];
$scale
=
$match
[
2
];
...
@@ -445,4 +450,20 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
...
@@ -445,4 +450,20 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
return
$column
;
return
$column
;
}
}
/**
* PostgreSQL 9.4 puts parentheses around negative numeric default values that need to be stripped eventually.
*
* @param mixed $defaultValue
*
* @return mixed
*/
private
function
fixVersion94NegativeNumericDefaultValue
(
$defaultValue
)
{
if
(
strpos
(
$defaultValue
,
'('
)
===
0
)
{
return
trim
(
$defaultValue
,
'()'
);
}
return
$defaultValue
;
}
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
View file @
5eb1a93b
...
@@ -383,6 +383,31 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -383,6 +383,31 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertEquals
(
'json_array'
,
$columns
[
'foo'
]
->
getType
()
->
getName
());
$this
->
assertEquals
(
'json_array'
,
$columns
[
'foo'
]
->
getType
()
->
getName
());
$this
->
assertEquals
(
true
,
$columns
[
'foo'
]
->
getPlatformOption
(
'jsonb'
));
$this
->
assertEquals
(
true
,
$columns
[
'foo'
]
->
getPlatformOption
(
'jsonb'
));
}
}
/**
* @group DBAL-2427
*/
public
function
testListNegativeColumnDefaultValue
()
{
$table
=
new
Schema\Table
(
'test_default_negative'
);
$table
->
addColumn
(
'col_smallint'
,
'smallint'
,
array
(
'default'
=>
-
1
));
$table
->
addColumn
(
'col_integer'
,
'integer'
,
array
(
'default'
=>
-
1
));
$table
->
addColumn
(
'col_bigint'
,
'bigint'
,
array
(
'default'
=>
-
1
));
$table
->
addColumn
(
'col_float'
,
'float'
,
array
(
'default'
=>
-
1.1
));
$table
->
addColumn
(
'col_decimal'
,
'decimal'
,
array
(
'default'
=>
-
1.1
));
$table
->
addColumn
(
'col_string'
,
'string'
,
array
(
'default'
=>
'(-1)'
));
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
'test_default_negative'
);
$this
->
assertEquals
(
-
1
,
$columns
[
'col_smallint'
]
->
getDefault
());
$this
->
assertEquals
(
-
1
,
$columns
[
'col_integer'
]
->
getDefault
());
$this
->
assertEquals
(
-
1
,
$columns
[
'col_bigint'
]
->
getDefault
());
$this
->
assertEquals
(
-
1.1
,
$columns
[
'col_float'
]
->
getDefault
());
$this
->
assertEquals
(
-
1.1
,
$columns
[
'col_decimal'
]
->
getDefault
());
$this
->
assertEquals
(
'(-1)'
,
$columns
[
'col_string'
]
->
getDefault
());
}
}
}
class
MoneyType
extends
Type
class
MoneyType
extends
Type
...
...
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