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
4090136a
Commit
4090136a
authored
Apr 09, 2014
by
Davi Koscianski Vidal
Committed by
lucasvanlierop
Jun 30, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handling all Postgres boolean literals
parent
449055af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
12 deletions
+48
-12
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+34
-12
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+14
-0
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
4090136a
...
...
@@ -44,6 +44,28 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
private
$useBooleanTrueFalseStrings
=
true
;
/**
* @var array PostgreSQL booleans literals
*/
private
$booleanLiterals
=
array
(
'true'
=>
array
(
't'
,
'true'
,
'y'
,
'yes'
,
'on'
,
'1'
),
'false'
=>
array
(
'f'
,
'false'
,
'n'
,
'no'
,
'off'
,
'0'
)
);
/**
* PostgreSQL has different behavior with some drivers
* with regard to how booleans have to be handled.
...
...
@@ -701,8 +723,9 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
$item
[
$key
]
=
(
$value
)
?
'true'
:
'false'
;
}
elseif
(
is_string
(
$value
))
{
$value
=
trim
(
strtolower
(
$value
));
if
(
'false'
!==
$value
&&
'f'
!==
$value
)
{
if
(
in_array
(
trim
(
strtolower
(
$value
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
[
$key
]
=
'false'
;
}
else
{
$item
[
$key
]
=
'true'
;
}
}
...
...
@@ -711,8 +734,9 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
is_bool
(
$item
)
||
is_numeric
(
$item
))
{
$item
=
(
$item
)
?
'true'
:
'false'
;
}
elseif
(
is_string
(
$item
))
{
$item
=
trim
(
strtolower
(
$item
));
if
(
'false'
!==
$item
&&
'f'
!==
$item
)
{
if
(
in_array
(
trim
(
strtolower
(
$item
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
=
'false'
;
}
else
{
$item
=
'true'
;
}
}
...
...
@@ -735,11 +759,10 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
$item
[
$key
]
=
$value
?
1
:
0
;
}
elseif
(
is_string
(
$value
))
{
$value
=
trim
(
strtolower
(
$item
));
if
(
'false'
!==
$value
&&
'f'
!==
$value
)
{
$item
[
$key
]
=
1
;
}
else
{
if
(
in_array
(
trim
(
strtolower
(
$item
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
[
$key
]
=
0
;
}
else
{
$item
[
$key
]
=
1
;
}
}
}
...
...
@@ -747,11 +770,10 @@ class PostgreSqlPlatform extends AbstractPlatform
if
(
is_bool
(
$item
)
||
is_numeric
(
$item
))
{
$item
=
$item
?
1
:
0
;
}
elseif
(
is_string
(
$item
))
{
$item
=
trim
(
strtolower
(
$item
));
if
(
'false'
!==
$item
&&
'f'
!==
$item
)
{
$item
=
1
;
}
else
{
if
(
in_array
(
trim
(
strtolower
(
$item
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
=
0
;
}
else
{
$item
=
1
;
}
}
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
4090136a
...
...
@@ -296,7 +296,21 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$platform
=
$this
->
createPlatform
();
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
't'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'true'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'y'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'yes'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'on'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'1'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
false
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'f'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'false'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'n'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'no'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'off'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'0'
));
}
/**
...
...
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