Comments

hswong3i’s picture

This issue is strict forward and simple, +1. BTW, it is duplicated with http://drupal.org/node/199101.
Tested with MySQL and PostgreSQL, pass.

obsidiandesign’s picture

StatusFileSize
new912 bytes

Rerolled against latest head. Applies & works correctly with both MySQL and PostgreSQL. Simpletests run successfully for poll module. +1

hswong3i’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1002 bytes

Patch reroll via CVS HEAD, test with MySQL and PostgreSQL.

damien tournoud’s picture

Status: Reviewed & tested by the community » Needs work

Please rewrite this one to use proper placeholders.

hswong3i’s picture

Status: Needs work » Needs review

@Damien: Sorry that I can't find any placeholders used within this issue. May you give a kindly review again?

damien tournoud’s picture

Status: Needs review » Needs work

There are no placeholders, that's precisely the issue.

hswong3i’s picture

Status: Needs work » Needs review

This issue is about the syntax cleanup of != with <> based on ANSI standard, but not legacy placeholder update... Am I correct?

damien tournoud’s picture

Title: Patch poll.module to comply with ANSI standards » Patch poll.module to comply with ANSI and DB:TNG standards
Status: Needs review » Needs work

Ok, not it's both.

hswong3i’s picture

Assigned: Unassigned » hswong3i
Category: bug » task
Status: Needs work » Needs review
StatusFileSize
new1.14 KB

So in this way? Update both db_query(), fetchField() and db_update().

Tested with MySQL, cron run correctly where outdated post inactive correctly, too.

lilou’s picture

hswong3i’s picture

Sorry that I am so fool and not really understand the needs of this issue: the original goal is about != => <> conversion, but now seems talking about TNG DB standard. I need some clear instruction about the requirement of change, and may someone give me a hand?

c960657’s picture

Status: Needs review » Needs work

Patch no longer applies to HEAD.

dave reid’s picture

Title: Patch poll.module to comply with ANSI and DB:TNG standards » DBTNG poll.module
Status: Needs work » Needs review
StatusFileSize
new10.07 KB

Here's a patch to bring the entire poll module in line with DBTNG and includes the ANSI != fix as well. Passed all poll tests 100%.

Crell’s picture

Subscribing, need to review this...

Status: Needs review » Needs work

The last submitted patch failed testing.

Crell’s picture

Status: Needs work » Needs review

Probably the recent bot bug...

Status: Needs review » Needs work

The last submitted patch failed testing.

dave reid’s picture

Status: Needs work » Needs review

That exception is for dblog.test. All the poll tests passed and this should be good.

dave reid’s picture

Ok so I need to figure out how to do the following without errors:

  db_update('poll_choices')
    ->fields(array())
    ->expression('chvotes', 'chvotes + 1')
    ->condition('chid', $node->vote)
    ->execute();

  db_update('poll_choices')
    ->fields(array())
    ->expression('chvotes', 'chvotes - 1')
    ->condition('chid', $node->vote)
    ->execute();

  $condition = db_and()->condition('nid', $node->nid);
  if ($user->uid) {
    $condition->condition('uid', $user->uid);
  }
  else {
    $condition->condition('hostname', ip_address());
  }
  db_delete('poll_votes')
    ->condition($condition)
    ->execute();
dave reid’s picture

Status: Needs review » Needs work

Forgot to set as code needs work.

Crell’s picture

Uh. fields() with an empty array? Does not compute. What are you trying to do there?

dave reid’s picture

It is replacing: db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE chid = %d", $node->vote)

Crell’s picture

Just leave off fields() entirely then. If that doesn't work, that's a bug in DBTNG.

db_update('poll_choices')
  ->expression('chvotes', 'chvotes + 1')
  ->condition('chid', $node->vote)
  ->execute();
dave reid’s picture

Without the fields() I get:
* Warning: Invalid argument supplied for foreach() in UpdateQuery->execute() (line 916 of /home/davereid/Projects/drupal-head/includes/database/query.inc).
* Warning: Invalid argument supplied for foreach() in UpdateQuery->__toString() (line 939 of /home/davereid/Projects/drupal-head/includes/database/query.inc).

For some reason the db_and() isn't working correctly: when that code is called I get:
Fatal error: Call to undefined function db_and() in /home/davereid/Projects/drupal-head/modules/poll/poll.module on line 871

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new10.55 KB

I got everything working. To get the update query working, just had to set the UpdateQuery class variable to a default array: "protected $fields = array();"

Status: Needs review » Needs work

The last submitted patch failed testing.

dave reid’s picture

Postponed until #343620: db_update() fails on expression-only SQL gets in to fix the UpdateQuery in DBTNG.

dave reid’s picture

Status: Needs work » Postponed
dave reid’s picture

Assigned: hswong3i » dave reid
Status: Postponed » Needs review
StatusFileSize
new11.38 KB

Now that #343620: db_update() fails on expression-only SQL is in, I figured my way around the multiple-node-load changes, and I was got bit by the table name changes, revised DBTNG patch ready for review. Passes all tests.

Status: Needs review » Needs work

The last submitted patch failed testing.

dave reid’s picture

I'm simply puzzled as to why changes to poll.module are causing exceptions in dblog.module.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new11.13 KB

Found the issue... there was an error in the poll_cron, since dblog invokes cron on all modules...

catch’s picture

This all looks good - although why explicitly use fetchObject() instead of fetch()?

dave reid’s picture

I thought I read somewhere that it is preferred to use fetchObject() and over fetch() since it is easier for anyone else to understand what type of data the results will be. I cannot find anything right now to back me up, so it very well might have been my own theory,

catch’s picture

It's probably more self-documenting that way. We should decide on a standard and stick to it either way.

Crell’s picture

We've informally decided on fetchObject() and fetchAssoc() for cases when you need to specify it directly. I need to update the docs to reflect that better. fetch() should be used when you need some other fetch mode than those two easy ones.

Status: Needs review » Needs work

The last submitted patch failed testing.

dave reid’s picture

Adding tags.

csevb10’s picture

Assigned: dave reid » csevb10

Re-assigning for work at Drupalcon DC Code-Sprint.

dave reid’s picture

Cool. :) Most of your work is already done in #32, but just needs a quick update.

csevb10’s picture

StatusFileSize
new13.84 KB

The biggest pain in this seems to be related to the PagerDefault queries. I've replaced all of the pager queries and db_rewrite_sql queries, and everything passes the provided simpletests. Time to get someone else's eyes on this thing.

csevb10’s picture

Status: Needs work » Needs review

Whoops, changing status.

Status: Needs review » Needs work

The last submitted patch failed testing.

csevb10’s picture

Status: Needs work » Needs review
StatusFileSize
new13.92 KB

Re-rolling from the root directory.

chx’s picture

Status: Needs review » Reviewed & tested by the community

The bot likes it, I read the code and I like that too. So... go :)

dave reid’s picture

Status: Reviewed & tested by the community » Needs work

Please check trailing whitespace in the patch.

+    $select->fields('n', array('nid'))      <--- whitespace
...
+      ->addTag('node_access');
+      <--- whitespace
...
-    return $block;
+    }    <--- whitespace
...
etc

p.runtime != :runtime should be changed to p.runtime <> :runtime for ANSI compatibility.

csevb10’s picture

Status: Needs work » Needs review
StatusFileSize
new13.77 KB

Re-rolled with those fixes. Nice catch on the whitespace.

csevb10’s picture

StatusFileSize
new13.82 KB

Cleaning up an issue with poll_cron.

dave reid’s picture

Actually for poll_cron, instead of

  $queried_polls = db_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < :request_time AND p.active = :active AND p.runtime <> :runtime', array(':request_time' => REQUEST_TIME, ':active' => 1, ':runtime' => 0));
  foreach ($queried_polls as $poll) {
    db_update('poll')
      ->fields(array('active' => 0))
      ->condition('nid', $poll->nid)
      ->execute();
  }

Let's do:

$nids = db_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < :request_time AND p.active = :active AND p.runtime <> :runtime', array(':request_time' => REQUEST_TIME, ':active' => 1, ':runtime' => 0))->fetchCol();
db_update('poll')
  ->fields(array('active' => 0))
  ->condition('nid', $nids, 'IN')
  ->execute();
csevb10’s picture

StatusFileSize
new13.81 KB

Theoretically, I could see that leading to a rather cumbersome update clause. Practically, I don't really see that happening, though, so I went ahead and changed it. The only addition I made other than that was to protect against returning no results.

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

Crell’s picture

One advantage of the new syntax is that we don't care how cumbersome a long list of ints in an IN clause is, because it's handled for us automatically. :-) The change from #49 reduces the task to only 2 queries ever, which is great.

Thanks everyone!

csevb10’s picture

Good to know. Thanks for the info, and all the help at the sprint.
REALLY liking the new DB layer. :-)

Status: Fixed » Closed (fixed)
Issue tags: -DBTNG Conversion, -dc2009 code sprint

Automatically closed -- issue fixed for 2 weeks with no activity.