Long story short, PHP 5.2.6 pdo_pgsql is buggy with BLOB INSERT/UPDATE. Both NULL and empty string are saved as NULL when pass into PostgreSQL, and so programming logic may break.
It is now fixed in latest PHP CVS, both 5.2.x and 5.3.x. All packages newer than snapshot php5.2-200810130030.tar.gz. is safe from this issue. Please refer to PHP bug report for more information.
As Drupal 7.x is now revamped with DBTNG and using PDO as the only default support database driver, this is a critical issue for its PostgreSQL support status. Patch is submitted and pending for review. Please refer to Drupal bug report for more information.
How to check if my PHP is safe from this bug?
You can follow the bug reproduction guideline and its latest version of code snippet. Check your result and see if all logical comparison of original data and fetched value are return as TRUE.
What can I do with this bug?
If you are a Drupal 7.x core developer which focusing on PostgreSQL support status, please download PHP snapshot newer than php5.2-200810130030.tar.gz manually, and give a hand for the commit of related Drupal bug report. If you need some help for the manual PHP installation, please refer to my HOWTO for more information.
If you are normal Drupal user which will use PostgreSQL in coming future, please be patient and wait for the release of PHP 5.2.7 (it is now 5.2.7RC2). You may also keep your eyes on the update status of the Drupal bug report, and help the promote of using PHP 5.2.7 as minimal support version for Drupal 7.x public release.
Background of this founding
Since I am focusing on promote a wider use of BLOB among Drupal 7.x core (the reason should belongs to another story), in order to increase its cross database compatibility, this hidden pdo_pgsql bug block my way. When remap some fields from TEXT to BLOB, e.g. {node_revisions}.body and {node_revisions}.teaser, {aggregator_item}.description, {locales_source}.source and so on, Apache will crash with no reason.
After an indeed study of this issues, I try to communicate with PostgreSQL guy though IRC #postgresql, cooperate with with PHP developers, contribute for bug reproduction code snippet, feedback and keep followup with their update, for almost half a month. Felipe from PHP give a great hand for this issue.
As PostgreSQL is more or less similar as Oracle, they share some common programming logic working with PHP PDO drivers, now my path is clean and so I can keep focus on developer Oracle driver for Drupal 7.x again.
Technical background
For normal TEXT/BLOB handling, we may INSERT/UPDATE 3 general tye of values into database:
- Normal string value.
- Empty string value (In case of PHP, we may label it as
'') - Null (In case of PHP, we may label it as
NULL).
The 1st and 2nd is very for understanding, they are just in simple text format. The 3rd type is a bit different: it means that field is now filling up with NONE of value, therefore it is NOTHING. Therefore NULL is complete different from '': when we are using is_null() or $value === NULL checking in PHP, they will provide different response.
According to this PHP pdo and pdo_pgsql bug, both NULL and '' will pass into database and save as NULL. pdo_pgsql didn't figure out their different. As a result, when we are trying to migrate some existing TEXT field as BLOB, existing logical checking will return unexpected feedback and so become buggy.
Special thanks
- Felipe from PHP: You are the hero of this bug fix! Without your quick response we can't get it done within a week :-)
- Crell from Drupal: Thanks for giving me a clear guideline, for figure out and focus of this issue.
Also to all people who give advice for this issues, from both IRC #drupal and #postgresql. I can't list out everyone but I would like to express my pleasure for working with you :-D


















Post new comment