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
d1267280
Commit
d1267280
authored
Oct 29, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #632 from tiagobrito/master
Add test to verify null cast in boolean type
parents
a67db17b
e2b11774
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
2 deletions
+97
-2
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+6
-2
DBAL630Test.php
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php
+89
-0
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+2
-0
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
d1267280
...
...
@@ -748,7 +748,7 @@ class PostgreSqlPlatform extends AbstractPlatform
private
function
convertSingleBooleanValue
(
$value
,
$callback
)
{
if
(
null
===
$value
)
{
return
$callback
(
false
);
return
$callback
(
null
);
}
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
...
...
@@ -812,6 +812,10 @@ class PostgreSqlPlatform extends AbstractPlatform
return
$this
->
doConvertBooleans
(
$item
,
function
(
$boolean
)
{
if
(
null
===
$boolean
)
{
return
'NULL'
;
}
return
true
===
$boolean
?
'true'
:
'false'
;
}
);
...
...
@@ -829,7 +833,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return
$this
->
doConvertBooleans
(
$item
,
function
(
$boolean
)
{
return
(
int
)
$boolean
;
return
null
===
$boolean
?
null
:
(
int
)
$boolean
;
}
);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php
View file @
d1267280
...
...
@@ -24,6 +24,7 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
try
{
$this
->
_conn
->
exec
(
'CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'
);
$this
->
_conn
->
exec
(
'CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'
);
}
catch
(
DBALException
$e
)
{
}
$this
->
running
=
true
;
...
...
@@ -88,4 +89,92 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertFalse
(
$row
[
'bool_col'
]);
}
/**
* @dataProvider booleanTypeConversionWithoutPdoTypeProvider
*/
public
function
testBooleanConversionNullParamEmulatedPrepares
(
$statementValue
,
$databaseConvertedValue
)
{
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
ATTR_EMULATE_PREPARES
,
true
);
// PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated in php 5.6. PDO::ATTR_EMULATE_PREPARES should
// be used instead. so should only it be set when it is supported.
if
(
PHP_VERSION_ID
<
50600
)
{
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT
,
true
);
}
$platform
=
$this
->
_conn
->
getDatabasePlatform
();
$stmt
=
$this
->
_conn
->
prepare
(
'INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'
);
$stmt
->
bindValue
(
1
,
$platform
->
convertBooleansToDatabaseValue
(
$statementValue
));
$stmt
->
execute
();
$id
=
$this
->
_conn
->
lastInsertId
(
'dbal630_allow_nulls_id_seq'
);
$this
->
assertNotEmpty
(
$id
);
$row
=
$this
->
_conn
->
fetchAssoc
(
'SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?'
,
array
(
$id
));
$this
->
assertSame
(
$databaseConvertedValue
,
$row
[
'bool_col'
]);
}
/**
* @dataProvider booleanTypeConversionUsingBooleanTypeProvider
*/
public
function
testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInBindValue
(
$statementValue
,
$databaseConvertedValue
)
{
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
ATTR_EMULATE_PREPARES
,
true
);
// PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT is deprecated in php 5.6. PDO::ATTR_EMULATE_PREPARES should
// be used instead. so should only it be set when it is supported.
if
(
PHP_VERSION_ID
<
50600
)
{
$this
->
_conn
->
getWrappedConnection
()
->
setAttribute
(
PDO
::
PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT
,
true
);
}
$platform
=
$this
->
_conn
->
getDatabasePlatform
();
$stmt
=
$this
->
_conn
->
prepare
(
'INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'
);
$stmt
->
bindValue
(
1
,
$platform
->
convertBooleansToDatabaseValue
(
$statementValue
),
PDO
::
PARAM_BOOL
);
$stmt
->
execute
();
$id
=
$this
->
_conn
->
lastInsertId
(
'dbal630_allow_nulls_id_seq'
);
$this
->
assertNotEmpty
(
$id
);
$row
=
$this
->
_conn
->
fetchAssoc
(
'SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?'
,
array
(
$id
));
$this
->
assertSame
(
$databaseConvertedValue
,
$row
[
'bool_col'
]);
}
/**
* Boolean conversion mapping provider
* @return array
*/
public
function
booleanTypeConversionUsingBooleanTypeProvider
()
{
return
array
(
// statement value, database converted value result
array
(
true
,
true
),
array
(
false
,
false
),
array
(
null
,
false
)
);
}
/**
* Boolean conversion mapping provider
* @return array
*/
public
function
booleanTypeConversionWithoutPdoTypeProvider
()
{
return
array
(
// statement value, database converted value result
array
(
true
,
true
),
array
(
false
,
false
),
array
(
null
,
null
)
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
d1267280
...
...
@@ -602,6 +602,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
array
(
'no'
,
'false'
,
0
,
false
),
array
(
'off'
,
'false'
,
0
,
false
),
array
(
'0'
,
'false'
,
0
,
false
),
array
(
null
,
'NULL'
,
null
,
null
)
);
}
...
...
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