Hi --
While attempting to enable the protected node module on an existing site, I was encountering the following error:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'protected_node_is_protected' at row 1: INSERT INTO {protected_nodes} (protected_node_is_protected, protected_node_passwd, protected_node_show_title, nid, protected_node_hint) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 2771 [:db_insert_placeholder_4] => ) in _protected_node_save() (line 748 of /home/poetryinvoice.com/www/trunk/sites/all/modules/protected_node/protected_node.module).
From that error, I can see that the default value being set for protected_node_is_protected in protected_node_load is 'FALSE'.
So, when it comes time to do the insert, FALSE is converted to the php string value of '' (empty string), which causes mysql to have a fit.
I've fixed this issue on my side by changing the default for protected_node_is_protected to 0, rather that FALSE.
I don't think this should cause any side effects anywhere (I think it would only cause problems if there was a protected_node_is_protected === FALSE condition somewhere... which there does not appear to be).
static $default_fields = array(
'protected_node_is_protected' => 0,
'protected_node_passwd' => '',
'protected_node_passwd_changed' => 0,
'protected_node_show_title' => 0,
'protected_node_hint' => '',
);
Alternatively, converting the protected_node_is_protected parameter to an integer before passing it to PDO should work too, I think:
$nid = db_insert('protected_nodes')
->fields(array(
'protected_node_is_protected' => intval($node->protected_node_is_protected),
'protected_node_passwd' => $node->protected_node_passwd,
'protected_node_show_title' => $node->protected_node_show_title,
'nid' => $node->nid,
'protected_node_hint' => isset($node->protected_node_hint) ? $node->protected_node_hint : '',
))
->execute();
Not sure why I'm the only one seeing this issue. I guess it only comes up in certain cases (when adding to an existing site?).
thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | mysqlpdo_protected_node_load-1757742-2.patch | 501 bytes | anou |
Comments
Comment #1
jackpines.info commentedJust adding a comment to state that you aren't alone in this. I believe you have the solution and that the reason you and I see it is due to not having Protected Node installed before creating content. Thus, modifying the content, in my case by promoting/demoting the content, requires an updating of the record in the database but now with a default value indicating the node is not protected. The rest of what you said addresses why the default value of FALSE is inappropriate. However, the easiest solution is to cast to INT using intval(). It also may be the most appropriate solution but I don't know PHP or MySQL well enough to comment further.
Comment #2
anouAnd here's a patch base on drinkingcoffee's suggestion (changing FALSE into 0).
Comment #3
artis commentedI can confirm that this patch fixes the issue.
Comment #4
quicksketchConfirmed again. Thanks for the patch @anou. This fixes the bulk edit screen in Node Gallery module, as well as Views Bulk Operations. Sans patch, this module throws errors in most of our editorial workflows.
Comment #5
izus commentedConfirmed again again :) the patch in #2 is fixing the issue.
Thanks
Comment #6
izus commentedmerged #2 in 7.x-1.x branch
Thanks all !