The taxonomy 'Reset to alphabetical fails in postgresql because postgres doesn't use table aliases for UPDATE statements.

Patch attached.

Comments

halcyonCorsair’s picture

Status: Active » Needs review

Set status to patch -> code needs review.

damien tournoud’s picture

Title: Reset to alphabetical fails in Postgresql » PostgreSQL surge #10: quick fix for D6 backport: UPDATE queries should not use aliases
Version: 6.x-dev » 7.x-dev

This will need to be fixed in HEAD first (D7-dev), then backported. Also promoted to the PostgreSQL surge (see #337146: Remove PostgreSQL driver from core for more context).

Status: Needs review » Needs work

The last submitted patch failed testing.

damien tournoud’s picture

Status: Needs work » Needs review

In Drupal 7, we still have those:

./modules/system/system.install: db_query('UPDATE {term_node} t SET vid = (SELECT vid FROM {node} n WHERE t.nid = n.nid)');
./modules/system/system.install: $ret[] = update_sql("UPDATE {poll_votes} v SET chid = (SELECT chid FROM {poll_choices} c WHERE v.chorder = c.chorder AND v.nid = c.nid)");
./modules/taxonomy/taxonomy.admin.inc: db_query('UPDATE {term_data} t SET weight = 0 WHERE vid = :vid', array(':vid' => $form_state['values']['vid']));

Let's fix them and move that issue quickly to D6.

jhedstrom’s picture

StatusFileSize
new2.58 KB

Patch attached that removes the aliases in the 3 queries mentioned in #4.

Not all tests pass (due to other issues), but the number of fails doesn't change pre/post patch...we'll see how the testbot likes this.

CalebD’s picture

Looks like there is an extra curly brace in the query: {poll_choices}}.chorder

+ $ret[] = update_sql("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} WHERE {poll_vodes}.chorder = {poll_choices}}.chorder AND {poll_votes}.nid = {poll_choices}.nid)");

jhedstrom’s picture

StatusFileSize
new2.58 KB

Extra curly brace removed. Thanks.

damien tournoud’s picture

-  db_query('UPDATE {term_node} t SET vid = (SELECT vid FROM {node} n WHERE t.nid = n.nid)');
+  db_query('UPDATE {term_node} SET vid = (SELECT vid FROM {node} WHERE {term_node}.nid = {node}.nid)');
   return $ret;
 }

I'm pretty sure we can keep the alias on {node}.

-    $ret[] = update_sql("UPDATE {poll_votes} v SET chid = (SELECT chid FROM {poll_choices} c WHERE v.chorder = c.chorder AND v.nid = c.nid)");
+    $ret[] = update_sql("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} WHERE {poll_vodes}.chorder = {poll_choices}.chorder AND {poll_votes}.nid = {poll_choices}.nid)");

{poll_vodes}? Also please keep the alias on {poll_choices}.

damien tournoud’s picture

Status: Needs review » Needs work
jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB

vodes...oops.

Fixes attached.

damien tournoud’s picture

Status: Needs review » Reviewed & tested by the community

Perfect. Many thanks Jonathan.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

dave reid’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

Moving to 6.x to be ported.

c960657’s picture

It looks like the patch in #348448: Always report E_STRICT errors was accidentially committed together with the fix for this issue:
http://drupal.org/cvs?commit=159769

The patch in #348448 still applies using patch -R.

damien tournoud’s picture

Title: PostgreSQL surge #10: quick fix for D6 backport: UPDATE queries should not use aliases » PostgreSQL surge #10: UPDATE queries should not use aliases

We are now working on D6. There are potentially more queries to convert, it's not a simple backport.

damien tournoud’s picture

In fact, I only see two of them:

./modules/system/system.install: db_query('UPDATE {term_node} t SET vid = (SELECT vid FROM {node} n WHERE t.nid = n.nid)');
./modules/taxonomy/taxonomy.admin.inc: db_query('UPDATE {term_data} t SET weight = 0 WHERE vid = %d', $form_state['values']['vid']);

damien tournoud’s picture

Title: PostgreSQL surge #10: UPDATE queries should not use aliases » UPDATE queries should not use aliases
Issue tags: +PostgreSQL Surge
andypost’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.12 KB
UPDATE \{\w\} \w SET

only one place

c960657’s picture

Status: Needs review » Reviewed & tested by the community

I couldn't find more than that single occurrence either.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Looks good, thanks, committed.

Status: Fixed » Closed (fixed)
Issue tags: -PostgreSQL Surge

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