-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test to verify null cast in boolean type #632
Conversation
@@ -786,6 +786,9 @@ public function convertBooleans($item) | |||
return $this->doConvertBooleans( | |||
$item, | |||
function ($boolean) { | |||
if (is_null($boolean)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use null === $bpolean
to check for null values, for consistency with the Doctrine coding standards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof Thanks for the feedback. It's done ;)
@Ocramius Can you give me feedback on this? Is this good to merge? |
@@ -786,6 +786,9 @@ public function convertBooleans($item) | |||
return $this->doConvertBooleans( | |||
$item, | |||
function ($boolean) { | |||
if (null === $boolean) { | |||
return 'NULL'; | |||
} | |||
return true === $boolean ? 'true' : 'false'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty newline before this line
Looks sane |
Add new line after an IF statement to be consistent with the coding standard
Hmmm when I use No matter what, I would really like to have a functional test for this in |
Update from master
@deeky666 I think that it works because in your test you have pre-setted the bindValue type as PDO::PARAM_BOOL $stmt->bindValue(1, $platform->convertBooleansToDatabaseValue(null), PDO::PARAM_BOOL); But I think that doctrine call bindValue without the type setted and it is figured out later, depending on the value type. |
Add functional test to check null conversion with boolean type. This test required NULL to be allowed in the table column.
Update from master repository
|
||
public function testBooleanConversionNullParamEmulatedPrepares() | ||
{ | ||
$this->_conn->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but I think you have to move the table creation statement to the setUp()
method to avoid errors if the table already exists (like if you run the test suite a second time).
Okay I think I get what you mean. But the question I am asking myself is how do you need to convert the boolean value if you do not omit the binding type. In Like: $conn->insert('mytable', array('bool_column' => null), array('bool_column' => \PDO::PARAM_BOOL)); |
Add unit test to check boolean conversion with and without PDO boolean type
Update from master repository
@deeky666 I think that these new tests should be enough to show want happen when the bindValue is used with and without PDO type. However I am having problems with PHP 5.6. |
|
||
$row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id)); | ||
|
||
$this->assertEquals($databaseConvertedValue, $row['bool_col']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to use assertSame()
here to enable type equality assertion.
// statement value, database converted value result | ||
array(true, true), | ||
array(false, false), | ||
array(null, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this assumption is wrong and is exactly the issue I was talking about. Why should I expect to get false
if I have a NULL
value in the database? There is no distinction between NULL
and false
anymore. Is this maybe even a PDO issue of some kind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren't getting from the database, we are inserting into the database.
I'm just using the PDO default behavior. If we tell the PDO that the value is a boolean (PDO::PARAM_BOOL
), isn't supposed that the NULL
is converted to false? Why can't we rely on that assumption?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because "NULL" is neither "true" or "false".
Update from main repository
Update from master repository
Update from master repository
Update from main repository
Any progress on this? Currently |
Yes i tried. I'm using DBAL over Doctrine orm, really don't understand problem's layer. ORM, DBAL, PDO or PostgreSQLPlatform? I think problem only affects NULLABLE bool fields. I want to summarize my experience: $conn = $this->getServiceLocator()->get('doctrine.connection.orm_default');
$p = $conn->getDatabasePlatform();
$conn->exec('CREATE TABLE test_bool (id SERIAL, bool_col BOOLEAN NULL);');
$stmt = $conn->prepare('INSERT INTO test_bool (bool_col) VALUES (?)');
$stmt->bindValue(1, SEE_SNIPPET)
$stmt->execute();
// UBTFS : UseBooleanTrueFalseStrings
// PREPARE : ATTR_EMULATE_PREPARES
|
@edigu Your snippet looks good to me. Did you run it against which PHP version? |
PHP 5.6.1 |
I've confirmed, this PR was failing in PHP 5.6.0 due a bug in that version, this is now fixed in PHP 5.6.1 and 5.6.2 |
@TiagoBrito I am about to merge this. Still not sure why PDO_PGSQL converts |
@deeky666 I actually think that using emulated prepares and
In this case, the PDO::PARAM_BOOL is used to guarantee that the NOT NULL restriction isn't violated. if we call bindValue directly without using
|
Add test to verify null cast in boolean type
Okay merging then. Thank you all for your investigation. |
wtf it is failing again in master oO Is there some sort of randomness going on here? |
@deeky666 I've run it yesterday a few times and didn't notice anything random. |
@TiagoBrito but obviously it is failing again in Travis. I have no idea what's going on here... |
Add unit test to check boolean conversion with and without PDO boolean type
Hey, I noticed this PR failed on Travis. And I could successfully reproduce the failure on my local machine. Maybe I could help you sorting this thing out. My versions:
And the failing test:
Would you have any hints where to investigate ? |
Oh, forgot to mention an extract from
Would you have any suggestions as to how to dig further ? I had quick look but did not find anything useful... |
See #625 |
thanks for letting me know :) |
…value Add unit test to check boolean conversion with and without PDO boolean type
This test verify how null values are casted to boolean values in PostgresPlatform.
NULL values are wrongly casted when flag useBooleanTrueFalseStrings is
true
, This issue can be related to #625