Problem/Motivation
There is an exception in PollCreateTestCase (testPollCreate) when running this test on PostgreSQL database.
The issue is that we cannot pass empty string as key to db_merge() because this function does db_select() first and then only db_insert()/db_update(). MySQL is not affected because it is not such strict for data types.
Problematic parts:
testPollCreate()
$vote_count = '2000';
$node->choice[] = array(
'chid' => '',
'chtext' => $new_option,
'chvotes' => (int) $vote_count,
'weight' => 1000,
);
node_save($node);
poll_update()
// Poll choices with empty titles signifies removal. We remove all votes to
// the removed options, so people who voted on them can vote again.
foreach ($node->choice as $key => $choice) {
if (!empty($choice['chtext'])) {
db_merge('poll_choice')
->key(array('chid' => $choice['chid']))
->fields(array(
'chtext' => $choice['chtext'],
'chvotes' => (int) $choice['chvotes'],
'weight' => $choice['weight'],
))
->insertFields(array(
'nid' => $node->nid,
'chtext' => $choice['chtext'],
'chvotes' => (int) $choice['chvotes'],
'weight' => $choice['weight'],
))
->execute();
}
else {
db_delete('poll_vote')
->condition('nid', $node->nid)
->condition('chid', $key)
->execute();
db_delete('poll_choice')
->condition('nid', $node->nid)
->condition('chid', $choice['chid'])
->execute();
}
}
In db_merge() this code will throw an exception:
PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: ""
LINE 4: WHERE ( (chid = '') )
^: SELECT 1 AS expression
FROM
{poll_choice} poll_choice
WHERE ( (chid = :db_condition_placeholder_0) ); Array
(
[:db_condition_placeholder_0] =>
)
in poll_update() (line 597 of /var/www/html/modules/poll/poll.module).
Steps to reproduce
Run Poll tests for Drupal 7.x-dev in PostgreSQL.
Proposed resolution
Replace empty string with NULL.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
poker10 commentedComment #4
mcdruid commentedThanks!