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
#22 2119993-update-error-22.patch961 bytespodarok
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]
#16 location-update-hook-country-table-bug-2119993-16.patch386 bytesjp.stacey
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]
#10 Update error on 7.x-3.0-2119993-8.patch425 byteshelonaut
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 ]

Comments

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). ...

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).

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);
  }
}
?>

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

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.

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"

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 ?

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.

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

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?

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.

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?

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

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.

StatusFileSize
new386 bytes
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]

Sorry, now attached

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

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

Issue tags:+upgrade path

taggind
looks like we needs here hook_update workaround for #18

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

Assigned:Unassigned» podarok
Priority:Normal» Critical
StatusFileSize
new961 bytes
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]

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

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.

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.

Need to add

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

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