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
55128a65
Commit
55128a65
authored
Mar 04, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-457] Allow to change PostgreSQL platform behvaior with regard to booleans.
parent
042cfa61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
2 deletions
+51
-2
configuration.rst
docs/en/reference/configuration.rst
+5
-2
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+22
-0
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+24
-0
No files found.
docs/en/reference/configuration.rst
View file @
55128a65
...
...
@@ -119,6 +119,11 @@ pdo\_pgsql
- ``port`` (integer): Port of the database to connect to.
- ``dbname`` (string): Name of the database/schema to connect to.
PostgreSQL behaves differently with regard to booleans when you use
``PDO::ATTR_EMULATE_PREPARES`` or not. To switch from using ``'true'``
and ``'false'`` as strings you can change to integers by using:
``$conn->getDatabasePlatform()->setUseBooleanTrueFalseStrings($flag)``.
pdo\_oci / oci8
^^^^^^^^^^^^^^^
...
...
@@ -159,5 +164,3 @@ Custom Driver Options
The ``driverOptions`` option allows to pass arbitrary options
through to the driver. This is equivalent to the fourth argument of
the `PDO constructor <http://php.net/manual/en/pdo.construct.php>`_.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
55128a65
...
...
@@ -33,6 +33,24 @@ use Doctrine\DBAL\Schema\TableDiff,
*/
class
PostgreSqlPlatform
extends
AbstractPlatform
{
/**
* @var bool
*/
private
$useBooleanTrueFalseStrings
=
true
;
/**
* PostgreSQL has different behavior with some drivers
* with regard to how booleans have to be handled.
*
* Enables use of 'true'/'false' or otherwise 1 and 0 instead.
*
* @param bool $flag
*/
public
function
setUseBooleanTrueFalseStrings
(
$flag
)
{
$this
->
useBooleanTrueFalseStrings
=
(
bool
)
$flag
;
}
/**
* {@inheritDoc}
*/
...
...
@@ -522,6 +540,10 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
public
function
convertBooleans
(
$item
)
{
if
(
!
$this
->
useBooleanTrueFalseStrings
)
{
return
parent
::
convertBooleans
(
$item
);
}
if
(
is_array
(
$item
))
{
foreach
(
$item
as
$key
=>
$value
)
{
if
(
is_bool
(
$value
)
||
is_numeric
(
$item
))
{
...
...
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
View file @
55128a65
...
...
@@ -280,4 +280,28 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
'CREATE INDEX IDX_22660D028A90ABA9 ON "quoted" ("key")'
,
);
}
/**
* @group DBAL-457
*/
public
function
testConvertBooleanAsStrings
()
{
$platform
=
$this
->
createPlatform
();
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
false
));
}
/**
* @group DBAL-457
*/
public
function
testConvertBooleanAsIntegers
()
{
$platform
=
$this
->
createPlatform
();
$platform
->
setUseBooleanTrueFalseStrings
(
false
);
$this
->
assertEquals
(
'1'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'0'
,
$platform
->
convertBooleans
(
false
));
}
}
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