Problem

Update of the metatag module to 7.x-1.0-beta5 (from beta4) generates on a PSQL database following error:

Update #7007
Failed: PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "m" LINE 1: DELETE m ^: DELETE m FROM {metatag} m LEFT OUTER JOIN {node} n ON m.entity_id=n.nid WHERE m.entity_type='node' AND n.nid IS NULL; Array ( ) in metatag_update_7007() (Zeile 325 von /var/www/(…)/sites/all/modules/metatag/metatag.install).

Drupal 7.21, PSQL 8.4.16, Apache/2.2.14 (Ubuntu)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

:-\

The purpose of this query is to join the {metatag} and {node} tables together and delete anything in {metatag} that doesn't have a matching record in {node}. I don't have PostgreSQL installed, if you have any ideas on how to handle this query I'd love to hear it. Thanks.

twistor’s picture

Would something like this work? It is frowned upon to do DELETE queries with db_query(). I haven't tested this at all.

<?php
$subquery = db_select('metatag', 'm')
  ->fields('m', array('entity_id'))
  ->condition('m.entity_type', 'node')
  ->leftJoin('node', 'n', 'm.entity_id=n.nid')
  ->isNull('n.nid');

$result = db_delete('metatag');
  ->condition('entity_type', 'node');
  ->condition('entity_id', $subquery)
  ->execute();
traveller’s picture

Sorry, I'm not able to test it now. For one website I just uninstalled the module and installed it again (as I didn't lose any data in the process), but I wouldn't like to do it for another bigger installation, without being forced to reconfigure the metadata again.

wiifm’s picture

Also getting the error on PostgreSQL 9.1.8, my SQL skills are not good enough to fix this though.

DamienMcKenna’s picture

Jibus’s picture

I encouter the same problem

jim.applebee’s picture

Traveller - were you able to resolve this issue with reinstalling the meta tags module? Is it currently working?

twistor’s picture

Status: Active » Needs review
FileSize
2.44 KB

I don't have Postgres lying around to test this on, but here's a patch.

Status: Needs review » Needs work

The last submitted patch, metatag-sql-syntax-error-1953724-8.patch, failed testing.

twistor’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
Status: Needs work » Needs review

Apply to dev.

twistor’s picture

Jibus’s picture

Tested the patch, when updating the db, i got this error message :

Fatal error: Call to a member function isNull() on a non-object in /usr/local/www/sites/all/modules/metatag/metatag.install on line 324

twistor’s picture

Oy, this should fix that.

Jibus’s picture

Thanks for you help Twistor !

- Tested patch #13,
- Applied patch metatag.install cleanly

Update #7007 result with this error

Failed: PDOException : SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "SELECT" LINE 2: WHERE (entity_type = 'node') AND (entity_id = SELECT m.enti... ^: DELETE FROM {metatag} WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id = SELECT m.entity_id AS entity_id FROM {metatag} m LEFT OUTER JOIN {node} n ON m.entity_id=n.nid WHERE (m.entity_type = :db_condition_placeholder_1) AND (n.nid IS NULL ) ) ; Array ( [:db_condition_placeholder_0] => node [:db_condition_placeholder_1] => node ) dans metatag_update_7007() (ligne 329 dans /usr/local/www/sites/all/modules/metatag/metatag.install).

DamienMcKenna’s picture

FileSize
3.07 KB

I think this is the correct approach - build a separate list of entity IDs using a SELECT statement, then delete those values. Obviously, please test this on a *copy* of your site, just in case =)

Jibus’s picture

Thanks for your time :)

Patch applied cleanly (3 lines add whitespace errors)

Now it's the #7008 update which fails :

Update #7008
Failed: PDOException : SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "m" LINE 1: DELETE m FROM metatag m WHERE m.data IS NULL or m.data = '' ... ^: DELETE m FROM {metatag} m WHERE m.data IS NULL or m.data = '' OR m.data = :empty; Array ( [:empty] => a:0:{} ) dans metatag_update_7008() (ligne 388 dans /usr/local/www/sites/all/modules/metatag/metatag.install).

Probably the same error ?

DamienMcKenna’s picture

Try these patches, they remove the 'm' from after 'delete'.

twistor’s picture

Yeah, that's where I was going. You can't DELETE from the same table that you SELECT from. The 2 queries is annoying though.

The only alternative I can come up with would be to use different db_query()'s based on the driver. :(

DamienMcKenna’s picture

FileSize
3.67 KB

@twistor: It's not that much of a big deal, I'm going to test the patch on MySQL too and then will commit the changes so it's in the next release.

twistor’s picture

+++ b/metatag.installundefined
@@ -317,36 +317,66 @@ function metatag_update_7006() {
 function metatag_update_7007() {
-  $result = db_query("DELETE m
+  $nodes = db_query("SELECT entity_id

m.entity_id

@DamienMcKenn I know. I'm just anal.

DamienMcKenna’s picture

FileSize
3.67 KB

@twistor: That's perfectly reasonable - there's only one "entity_id" field, thus no chance of confusion as to which one is being referenced, but it's best to specify the table anyway.

twistor’s picture

Ahh, well. Seeing as how I've been zero help on this issue, I will shut up now :)

DamienMcKenna’s picture

@twistor: There's no need for self-deprecation, you've helped. You can even help a little more - does the patch in #21 work for you? :)

wiifm’s picture

Status: Needs review » Needs work
FileSize
3.62 KB

@DamienMcKenna your patch at #21 did not apply using drush make, so I have re-made it (hopefully this is a little better now).

Update hooks 7007 and 7008 work now, but not 7009

» drush updb
The following updates are pending:

metatag module : 
  7005 -   Removing wrong metatag watchdog entries that break the adminreportsdblog  page. 
  7006 -   Remove {metatag} records that were added by old versions of the module for  entities that don't actually support meta tags. A more complete version of  this will be added later on after it's (hopefully) guaranteed that all  modules have updated to the correct API usage. 
  7007 -   Remove {metatag} records for objects that have been deleted; older versions  of Metatag may have failed to purge these. 
  7008 -   Remove any empty records that may be hanging around from old releases. 
  7009 -   Fix {metatag} records for taxonomy terms. 
  7010 -   Fix {metatag} records for users. 
  7011 -   Fix {metatag} records for nodes. 
  7012 -   Remove duplicate {metatag} records for non-core entities. 
  7013 -   Fix the {metatag} language value for all non-core entity records. This might  take a while, depending on how much data needs to be converted. 
  7014 -   Fix {metatag} records that may have been corrupted by #1871020. 

Do you wish to run all pending updates? (y/n): y
Performed update: metatag_update_7005                                                                                                                               [ok]
Performed update: metatag_update_7006                                                                                                                               [ok]
Performed update: metatag_update_7007                                                                                                                               [ok]
Performed update: metatag_update_7008                                                                                                                               [ok]
SQLSTATE[42703]: Undefined column: 7 ERROR:  column "the_count" does not exist                                                                                      [error]
LINE 6:     HAVING the_count > 1
                   ^
Performed update: metatag_update_7009                                                                                                                               [ok]
Finished performing updates.

Getting closer

twistor’s picture

Status: Needs work » Needs review

haha, it works on MySQL.

wiifm’s picture

Status: Needs review » Needs work

Please do not change the status, this issue clearly still needs work as the latest "stable" release does not work on PostgreSQL. I am aware the module maintainer uses MySQL ;)

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
4 KB

@wiifm: Does this one work?

DamienMcKenna’s picture

Title: Update to 7.x-1.0-beta5 on a Postgresql database genarates PDOException » PostgreSQL compatibility

Simplifying the title.

DamienMcKenna’s picture

Issue tags: +PostgreSQL

Tagging.

twistor’s picture

@wiifm, that was a cross-post. Although, I'm not sure what a stable release has to do with anything.

wiifm’s picture

Status: Needs review » Needs work

@DamienMcKenna bumped to --dev, and then drush make will apply your patch, now it gets passed 7009 and stuck on 7014:

drush updb
The following updates are pending:

metatag module : 
  7009 -   Fix {metatag} records for taxonomy terms. 
  7010 -   Fix {metatag} records for users. 
  7011 -   Fix {metatag} records for nodes. 
  7012 -   Remove duplicate {metatag} records for non-core entities. 
  7013 -   Fix the {metatag} language value for all non-core entity records. This might  take a while, depending on how much data needs to be converted. 
  7014 -   Fix {metatag} records that may have been corrupted by #1871020. 

Do you wish to run all pending updates? (y/n): y
Performed update: metatag_update_7009                                                                                                                               [ok]
No duplicate taxonomy_term records were found (this is a good thing).                                                                                               [status]
Performed update: metatag_update_7010                                                                                                                               [ok]
No duplicate user records were found (this is a good thing).                                                                                                        [status]
Performed update: metatag_update_7011                                                                                                                               [ok]
Entity Translation is enabled, so node meta tags will not be updated, to avoid accidental dataloss.                                                                 [status]
Performed update: metatag_update_7012                                                                                                                               [ok]
Entity Translation is enabled, duplicate meta tags will not be removed for custom entities, to avoid accidental dataloss.                                           [status]
Performed update: metatag_update_7013                                                                                                                               [ok]
Entity Translation is enabled, meta tags will not be updated for custom entities, to avoid accidental dataloss.                                                     [status]
SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "`"                                                                                                [error]
LINE 4:        m.`data`::text LIKE 'a:1:{s:0:"";a:%:{s:%;a:%:{%;}}}'
                 ^
Performed update: metatag_update_7014                                                                                                                               [ok]
Finished performing updates.
DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
4.4 KB

This should resolve update 7014.

wiifm’s picture

Status: Needs review » Reviewed & tested by the community

Can confirm this does resolved any exceptions

» drush updb
The following updates are pending:

metatag module : 
  7005 -   Removing wrong metatag watchdog entries that break the adminreportsdblog  page. 
  7006 -   Remove {metatag} records that were added by old versions of the module for  entities that don't actually support meta tags. A more complete version of  this will be added later on after it's (hopefully) guaranteed that all  modules have updated to the correct API usage. 
  7007 -   Remove {metatag} records for objects that have been deleted; older versions  of Metatag may have failed to purge these. 
  7008 -   Remove any empty records that may be hanging around from old releases. 
  7009 -   Fix {metatag} records for taxonomy terms. 
  7010 -   Fix {metatag} records for users. 
  7011 -   Fix {metatag} records for nodes. 
  7012 -   Remove duplicate {metatag} records for non-core entities. 
  7013 -   Fix the {metatag} language value for all non-core entity records. This might  take a while, depending on how much data needs to be converted. 
  7014 -   Fix {metatag} records that may have been corrupted by #1871020. 

Do you wish to run all pending updates? (y/n): y
Performed update: metatag_update_7005                                                                                                                               [ok]
Performed update: metatag_update_7006                                                                                                                               [ok]
Performed update: metatag_update_7007                                                                                                                               [ok]
Performed update: metatag_update_7008                                                                                                                               [ok]
Performed update: metatag_update_7009                                                                                                                               [ok]
No duplicate taxonomy_term records were found (this is a good thing).                                                                                               [status]
Performed update: metatag_update_7010                                                                                                                               [ok]
No duplicate user records were found (this is a good thing).                                                                                                        [status]
Performed update: metatag_update_7011                                                                                                                               [ok]
Entity Translation is enabled, so node meta tags will not be updated, to avoid accidental dataloss.                                                                 [status]
Performed update: metatag_update_7012                                                                                                                               [ok]
Entity Translation is enabled, duplicate meta tags will not be removed for custom entities, to avoid accidental dataloss.                                           [status]
Performed update: metatag_update_7013                                                                                                                               [ok]
Entity Translation is enabled, meta tags will not be updated for custom entities, to avoid accidental dataloss.                                                     [status]
Performed update: metatag_update_7014                                                                                                                               [ok]
No corrupt records to fix, this is good news :-)                                                                                                                    [status]
Finished performing updates.

Happy to RTBC this for now as it is a giant leap over what is currently on --dev.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed

Thank you all for the help debugging this, I've committed the fix and will be releasing beta6 very soon.

Jibus’s picture

Status: Fixed » Needs work

Tested the 7.x-1.x-dev 2013-Apr-05 release.

I have this error :

Update #7011
Failed: PDOException : SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "INNER" LINE 1: UPDATE metatag AS m INNER JOIN node n ON m.entity_id=n.nid A... ^: UPDATE {metatag} AS m INNER JOIN {node} n ON m.entity_id=n.nid AND m.entity_type='node' SET m.language = n.language; Array ( ) dans metatag_update_7011() (ligne 440 dans /usr/local/www/sites/all/modules/metatag/metatag.install).

joshf’s picture

Here's a patch for the error described in #35, which I also got.

DamienMcKenna’s picture

Status: Needs work » Needs review

@joshf: Thanks for helping. That query really works? That's some strange SQL :-) We need to test it on MySQL before committing it, just in case.

joshf’s picture

@ DamienMcKenna Thanks for the module!

Yeah, see http://www.nexusdb.com/forums/showthread.php?t=16473#4 it looks like neither one of these are actually SQL compliant. I have doubts about sqlite's ability to parse this, as well. I'll test that when I can and maybe come up with a less efficient but more cross-compatible two-query fix.

DamienMcKenna’s picture

FileSize
987 bytes

This should resolve the problem with metatag_update_7011().

DamienMcKenna’s picture

Status: Needs review » Needs work

Ack, #39 won't work, it needs to run a loop via batch_api otherwise it'll time out - that's what I was hoping to avoid with the more advanced query.

DamienMcKenna’s picture

FileSize
4.81 KB

Lets try this - it loops over 20 records at a time and only updates records that have a different language.

DamienMcKenna’s picture

Status: Needs work » Needs review
DamienMcKenna’s picture

FileSize
5.58 KB

I tested #41 with MySQL and found a problem with the DELETE statement in update 7008, so this fixes that.

DamienMcKenna’s picture

FileSize
5.54 KB

A small improvement to metatag_update_7011.

Jibus’s picture

A big thanks for your work :)

- Tested patch #44,
- Applied patch metatag.install cleanly

No duplicate node records were found (this is a good thing).
There were no other records to fix.
No corrupt records to fix, this is good news :-)

The following updates returned messages

metatag module

Update #7011
No nodes need the Metatag language values fixed.
Update #7013
No meta tag records need updating.

Thanks !

DamienMcKenna’s picture

Status: Needs review » Fixed

Excellent. Committed!

jlnknz’s picture

Just a note to let you know that the patched metatag.install file also fixes updates with an sqlite database.

The error occuring on update #7007 was the following:

Failed: PDOException : SQLSTATE[HY000]: General error: 1 near "m": syntax error: DELETE m FROM {metatag} m LEFT OUTER JOIN {node} n ON m.entity_id=n.nid WHERE m.entity_type='node' AND n.nid IS NULL; Array ( ) dans metatag_update_7007() (ligne 325 dans /path/sites/all/modules/metatag/metatag.install).
DamienMcKenna’s picture

@clrdd: Good to know, thanks :)

lookas’s picture

A had similar problem with PostgreSQL, and i've used DBTNG Migrator. I've just migrated PQSQL to MySQL and all updatest are done ok.
So I probably wont get back to PostgreSQL.

dfurman’s picture

Is there an aggregate path or release scheduled? I'm experiencing all described problems with the updates.

Jibus’s picture

You can use the latest dev version

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.