When I ran update after installing Location 7.x-3.0 this afternoon it called for the following update:

location module

7302 - Adds the Country code to name table "location_country". It is created from the included array country array.

However, when I ran that, I got the error message:

location module
Update #7302

Failed: DatabaseSchemaObjectExistsException: Table location_country already exists. in DatabaseSchema->createTable() (line 657 of /home/northbro/public_html/includes/database/schema.inc).

----
I'm running the site on Drupal 7.23.
Also updated Gmap module this afternoon, but it didn't require any database update.
---
Have not had time to determine performance impact, if any, of the update failure.

Thanks.

Bill

Files: 
CommentFileSizeAuthor
#42 location-error_creating_table_update_7302-1054616-42.patch626 bytestinker
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch location-error_creating_table_update_7302-1054616-42.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Neograph734’s picture

I ran into a similar issue, but that had a different cause. I went wrong on updating 'Bahama's'. The quote breaks the sql query and there is a half location_country table.

After running the update again I got the table already exists message. Did you run the update twice?

---

The fix is to alter the location.install file. Scroll all the way down and alter the line that performs the query. It's something like query("$sql", "$sql2"); Change it into query("$sql", addslashes($sql2))

UPDATE: You'll have to go into the database and remove the location_country table manually. Then run update again.

After that I ran into #2119967: [Needs steps to reproduce] Notice: Undefined offset: 1 in location_cck_tokens() (line 622 of location_cck.module). ...

mediameriquat’s picture

It's definitely a quote problem. In my case, "Côte d'Ivoire" caused the failure. Here's the error message:

Failed: PDOException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Ivoire')' at line 1: INSERT INTO {location_country} (code, name) VALUES ('ci', 'Côte d'Ivoire'); Array ( ) in location_update_7302() (line 1328 in /path/modules/location/location.install).

I tried removing the location_country table manually, ran the update many times but it didn't work. The quick fix to the location.install module didn't work either (parse error).

Neograph734’s picture

Oops, my bad. I've sent you the wrong line. Here is the whole function and this should work.

<?php
/**
 * Adds the Country code to name table "location_country".  It is created from the included array country array.
 */
function location_update_7302() {
 
//Create the new table
 
$schema = location_schema() ;
 
db_create_table('location_country', $schema['location_country']);

 
//Fill it.
 
$sql = 'INSERT INTO {location_country} (code, name) VALUES ';
 
$sql2 = '';
 
$countries = location_get_iso3166_list();
  foreach(
$countries as $code => $name){
   
$variables = array();

   
$variables[] = $code;
   
$variables[] = $name;
   
$sql2 = "('$code', '" . addslashes($name) . "')"; // Actually it is only this line that needs to be changes.
   
db_query($sql . $sql2);
  }
}
?>
podarok’s picture

Version:7.x-3.0» 7.x-3.x-dev
Status:Active» Patch (to be ported)

good to see here a patch in gir diff format http://drupal.org/patch

Neograph734’s picture

I would not consider this a patch, more a quick fix. One could also use the quotes in different order:

<?php
$sql2
= '("'.$code.'", "'.$name.'")'; // This prevents sanitizing the slash on display.
?>

I know too little of this module to provide a good solution.

kreatIL’s picture

The database update runs into this error:
"Fatal error: Call to undefined function location_get_iso3166_list() in (path)/sites/all/modules/location/location.install on line 1321"

bendev’s picture

I tried #3 and #5 without succeess.

Do you need to do antyhing else than replace the function in location.install and rerun drush updb ?

helonaut’s picture

I've changed location.install and added the following line: $name = str_replace("'","\'",$name);

<?php
/**
* Adds the Country code to name table "location_country".  It is created from the included array country array.
*/
function location_update_7302() {
 
//Create the new table
 
$schema = location_schema() ;
 
db_create_table('location_country', $schema['location_country']);

 
//Fill it.
 
$sql = 'INSERT INTO {location_country} (code, name) VALUES ';
 
$sql2 = '';
 
$countries = location_get_iso3166_list();
  foreach(
$countries as $code => $name){
   
$variables = array();
   
$name = str_replace("'","\'",$name);
   
$variables[] = $code;
   
$variables[] = $name;
   
$sql2 = "('$code', '$name')";
   
db_query($sql . $sql2);
  }
}
?>

I deleted the table location_country manually before running this update again. Maybe this should be automated... Anyway this fix worked for me though.

podarok’s picture

please, upload patch in git diff format http://drupal.org/patch

helonaut’s picture

StatusFileSize
new425 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch Update error on 7.x-3.0-2119993-8_0.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I'm sorry, first time using GIT.
I've attache a patch to this post... Could you verify if it's OK, please?

podarok’s picture

Status:Patch (to be ported)» Needs review

bot

Status:Needs review» Needs work

The last submitted patch, Update error on 7.x-3.0-2119993-8.patch, failed testing.

helonaut’s picture

I don't know why it failed, if I apply the patch it just works... I'm sorry, could someone help me with this patch-making and check what I did wrong please?

podarok’s picture

You should upload patch against latest 7.x-3.x-dev version for succesfull applying

jp.stacey’s picture

Status:Needs work» Needs review

The patch format looks fine and applies fine on a local checkout. The only thing I can think of that might be confusing the bot is the whitespaces in the filename.

Re-rolled and uploaded.

jp.stacey’s picture

StatusFileSize
new386 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch location-update-hook-country-table-bug-2119993-16.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Sorry, now attached

Didier Misson’s picture

Hello,
I apply the patch :

root : .../sites/all/modules/location# patch -p1 < location-update-hook-country-table-bug-2119993-16.patch
patching file location.install

but update.php always give me an error :

The following updates returned messages
location module
Update #7302

    Failed: DatabaseSchemaObjectExistsException : La table <em class="placeholder">location_country</em> existe déjà. dans DatabaseSchema->createTable() (ligne 657 dans /home/noumea/www/commerce.pirogue.me/includes/database/schema.inc).

Didier

kreatIL’s picture

Didier: as Neograph734 stated in #1 above, you'll have to manually remove the location_country table in the database at first.

podarok’s picture

Issue tags:+upgrade path

taggind
looks like we needs here hook_update workaround for #18

helonaut’s picture

Thank you for your help @ #15 jp.stacey !

podarok’s picture

podarok’s picture

Assigned:Unassigned» podarok
Priority:Normal» Critical
StatusFileSize
new961 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 2119993-update-error-22.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

here is a fixed upgrade path with #16 injected and no more needed removal location_country table

podarok’s picture

Status:Needs review» Fixed

#22 commited pushed ti 7.x-3.x-dev
tagged 7.x-3.1 release
Thanks all for help!!!

Status:Fixed» Closed (fixed)

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

tomb’s picture

Issue summary:View changes

Can you confirm that the patch in #22 was committed correctly?
I'm not seeing it in the latest 7.x-3.x-dev.

yecarrillo’s picture

Need to add

<?php
drupal_load
('module', 'location');
?>

after function name to run properly. This is an issue with drupal 6 => 7 migration.

andrewfn’s picture

Thanks podarok!
It would have saved me a lot of time if this patch had been committed!

andrewfn’s picture

Status:Closed (fixed)» Reviewed & tested by the community
wildlife’s picture

I'm updating a site from Drupal 6 to Drupal 7. The location module upgrade is experiencing this failed database update. It is leaving the update as failed and now it is trying to run it every time I run the update script. It is failing each time.

When I run the update script, this is what appears:

location module
Update #7302
Failed: DatabaseSchemaObjectExistsException: Table location_country already exists. in DatabaseSchema->createTable() (line 657 of [path]/includes/database/schema.inc).

When I look in the Recent Log Messages, this is what appears:

DatabaseSchemaObjectExistsException: Table location_country already exists. in DatabaseSchema->createTable() (line 657 of [path]/includes/database/schema.inc).

I've tried installing the latest dev version of the module and it hasn't changed anything.

Please advise on how to get this database update completed so it isn't present and failing every time I run the update script.

Neograph734’s picture

You'll have to delete the table manually first in order to attempt the update again, the patch that was supposed to fix that has not been pushed to the development build (I guess). Then apply the patch locally.

podarok’s picture

22: 2119993-update-error-22.patch queued for re-testing.

Status:Reviewed & tested by the community» Needs work

The last submitted patch, 22: 2119993-update-error-22.patch, failed testing.

wildlife’s picture

Deleting the table manually from the database worked. Thanks a bunch!

kerrycurtain’s picture

Ditto! Thanks.

The last submitted patch, 16: location-update-hook-country-table-bug-2119993-16.patch, failed testing.

tinker’s picture

StatusFileSize
new976 bytes
FAILED: [[SimpleTest]]: [MySQL] Drupal installation failed.
[ View ]

Comment #2119993-23: Error creating table in update 7302 says patch from #2119993-22: Error creating table in update 7302 was committed but db_create_table() is still in 7.x-3.x-dev and 7.x-3.4. I have updated patch from #22 which does not need str_replace() on single quote since db_insert() handles it.

tinker’s picture

Title:Update error on 7.x-3.0» Error creating table in update 7302
Status:Needs work» Needs review

Rename to better describe the problem.

Status:Needs review» Needs work

The last submitted patch, 37: location-error-creating-table-update-7302-2119993-37.patch, failed testing.

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 37: location-error-creating-table-update-7302-2119993-37.patch, failed testing.

tinker’s picture

StatusFileSize
new626 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch location-error_creating_table_update_7302-1054616-42.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Let's try that again with simple GIT patch.

podarok’s picture

Status:Needs work» Needs review
podarok’s picture

Status:Needs review» Fixed

Thanks #42 commited

  • podarok committed e61c0d5 on 7.x-3.x authored by tinker
    Issue #2119993 by tinker, podarok, helonaut, jp.stacey: Error creating...

Status:Fixed» Needs work

The last submitted patch, 42: location-error_creating_table_update_7302-1054616-42.patch, failed testing.

tinker’s picture

Status:Needs work» Closed (fixed)

Thx @podarok, One less thing to remeber when upgrading sites. Marked fixed again since code was commited and drupal bot got it wrong.