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
b35b6824
Commit
b35b6824
authored
Apr 04, 2014
by
Davi Koscianski Vidal
Committed by
lucasvanlierop
Jun 30, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on PostgreSQL incorrect boolean handling when emulating prepared statements
parent
86e58794
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
19 deletions
+92
-19
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+17
-3
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+38
-6
BooleanType.php
lib/Doctrine/DBAL/Types/BooleanType.php
+1
-1
DBAL630Test.php
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php
+7
-3
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+29
-6
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
b35b6824
...
...
@@ -2245,7 +2245,7 @@ abstract class AbstractPlatform
}
elseif
((
string
)
$field
[
'type'
]
==
'Date'
&&
$field
[
'default'
]
==
$this
->
getCurrentDateSQL
())
{
$default
=
" DEFAULT "
.
$this
->
getCurrentDateSQL
();
}
elseif
((
string
)
$field
[
'type'
]
==
'Boolean'
)
{
$default
=
" DEFAULT '"
.
$this
->
convertBool
eans
(
$field
[
'default'
])
.
"'"
;
$default
=
" DEFAULT '"
.
$this
->
convertBool
ToSqlLiteral
(
$field
[
'default'
])
.
"'"
;
}
}
}
...
...
@@ -2562,11 +2562,13 @@ abstract class AbstractPlatform
*
* The default conversion in this implementation converts to integers (false => 0, true => 1).
*
* @param mixed $item
* There are two contexts when converting booleans: Literals and Prepared Statements.
* This method should handle the literal case
*
* @param mixed $item
* @return mixed
*/
public
function
convertBool
eans
(
$item
)
public
function
convertBool
ToSqlLiteral
(
$item
)
{
if
(
is_array
(
$item
))
{
foreach
(
$item
as
$k
=>
$value
)
{
...
...
@@ -2595,6 +2597,18 @@ abstract class AbstractPlatform
return
null
===
$item
?
null
:
(
bool
)
$item
;
}
/**
* This method should handle the prepared statements case. When there is no
* distinction, it's OK to use the same method.
*
* @param mixed $item
* @return mixed
*/
public
function
convertBoolToDbValue
(
$item
)
{
return
self
::
convertBoolToSqlLiteral
(
$item
);
}
/**
* Returns the SQL specific for the platform to get the current date.
*
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
b35b6824
...
...
@@ -690,10 +690,10 @@ class PostgreSqlPlatform extends AbstractPlatform
*
* Postgres wants boolean values converted to the strings 'true'/'false'.
*/
public
function
convertBool
eans
(
$item
)
public
function
convertBool
ToSqlLiteral
(
$item
)
{
if
(
!
$this
->
useBooleanTrueFalseStrings
)
{
return
parent
::
convertBool
eans
(
$item
);
if
(
!
$this
->
useBooleanTrueFalseStrings
)
{
return
parent
::
convertBool
ToSqlLiteral
(
$item
);
}
if
(
is_array
(
$item
))
{
...
...
@@ -711,6 +711,38 @@ class PostgreSqlPlatform extends AbstractPlatform
return
$item
;
}
/**
* {@inheritDoc}
*/
public
function
convertBoolToDbValue
(
$item
)
{
if
(
!
$this
->
useBooleanTrueFalseStrings
)
{
return
parent
::
convertBoolToDbValue
(
$item
);
}
if
(
is_array
(
$item
))
{
foreach
(
$item
as
$key
=>
$value
)
{
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
$item
[
$key
]
=
$value
?
1
:
0
;
}
elseif
(
is_string
(
$value
))
{
$item
[
$key
]
=
(
trim
(
strtolower
(
$value
))
===
'false'
);
}
}
}
else
{
if
(
is_bool
(
$item
)
||
is_numeric
(
$item
))
{
$item
=
$item
?
1
:
0
;
}
elseif
(
is_string
(
$item
))
{
if
(
trim
(
strtolower
(
$item
))
===
'false'
)
{
$item
=
0
;
}
else
{
$item
=
1
;
}
}
}
return
$item
;
}
/**
* {@inheritDoc}
*/
...
...
lib/Doctrine/DBAL/Types/BooleanType.php
View file @
b35b6824
...
...
@@ -41,7 +41,7 @@ class BooleanType extends Type
*/
public
function
convertToDatabaseValue
(
$value
,
AbstractPlatform
$platform
)
{
return
$platform
->
convertBool
eans
(
$value
);
return
$platform
->
convertBool
ToDbValue
(
$value
);
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php
View file @
b35b6824
...
...
@@ -33,6 +33,7 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
{
if
(
$this
->
running
)
{
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
ATTR_EMULATE_PREPARES
,
false
);
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT
,
false
);
}
}
...
...
@@ -60,12 +61,15 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
public
function
testBooleanConversionBoolParamEmulatedPrepares
()
{
$this
->
markTestIncomplete
(
'There is something missing here, on some machines it fails on some it passes.'
);
//
$this->markTestIncomplete('There is something missing here, on some machines it fails on some it passes.');
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
ATTR_EMULATE_PREPARES
,
true
);
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT
,
true
);
$platform
=
$this
->
_conn
->
getDatabasePlatform
();
$stmt
=
$this
->
_conn
->
prepare
(
'INSERT INTO dbal630 (bool_col) VALUES(?)'
);
$stmt
->
bindValue
(
1
,
'false'
,
PDO
::
PARAM_BOOL
);
$stmt
->
bindValue
(
1
,
$platform
->
convertBoolToDbValue
(
'false'
)
,
PDO
::
PARAM_BOOL
);
$stmt
->
execute
();
$id
=
$this
->
_conn
->
lastInsertId
(
'dbal630_id_seq'
);
...
...
@@ -74,6 +78,6 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
$row
=
$this
->
_conn
->
fetchAssoc
(
'SELECT bool_col FROM dbal630 WHERE id = ?'
,
array
(
$id
));
$this
->
assert
Tru
e
(
$row
[
'bool_col'
]);
$this
->
assert
Fals
e
(
$row
[
'bool_col'
]);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
b35b6824
...
...
@@ -291,24 +291,47 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
/**
* @group DBAL-457
*/
public
function
testConvertBooleanAsStrings
()
public
function
testConvertBooleanAs
Literal
Strings
()
{
$platform
=
$this
->
createPlatform
();
$this
->
assertEquals
(
'true'
,
$platform
->
convertBool
eans
(
true
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBool
eans
(
false
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBool
ToSqlLiteral
(
true
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBool
ToSqlLiteral
(
false
));
}
/**
* @group DBAL-457
*/
public
function
testConvertBooleanAsIntegers
()
public
function
testConvertBooleanAs
Literal
Integers
()
{
$platform
=
$this
->
createPlatform
();
$platform
->
setUseBooleanTrueFalseStrings
(
false
);
$this
->
assertEquals
(
'1'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'0'
,
$platform
->
convertBooleans
(
false
));
$this
->
assertEquals
(
'1'
,
$platform
->
convertBoolToSqlLiteral
(
true
));
$this
->
assertEquals
(
'0'
,
$platform
->
convertBoolToSqlLiteral
(
false
));
}
/**
* @group DBAL-630
*/
public
function
testConvertBooleanAsDbValueStrings
()
{
$platform
=
$this
->
createPlatform
();
$this
->
assertEquals
(
1
,
$platform
->
convertBoolToDbValue
(
true
));
$this
->
assertEquals
(
0
,
$platform
->
convertBoolToDbValue
(
false
));
}
/**
* @group DBAL-630
*/
public
function
testConvertBooleanAsDbValueIntegers
()
{
$platform
=
$this
->
createPlatform
();
$platform
->
setUseBooleanTrueFalseStrings
(
false
);
$this
->
assertEquals
(
1
,
$platform
->
convertBoolToDbValue
(
true
));
$this
->
assertEquals
(
0
,
$platform
->
convertBoolToDbValue
(
false
));
}
public
function
testConvertFromBoolean
()
...
...
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