Allo
Can anyone help a Drupal newbie understand how the database abstraction layer works, and why I'm having a problem?
My problem: I'm using the location module with the Gmap module, so folks can locate themselves on a google map. This works fine for nodes, but not for users, which gives the error:
user warning: Duplicate entry '0' for key 1 query: INSERT INTO location (eid, type, latitude, longitude, source) VALUES (5, 'user', 52.95112016368184, -1.141204833984375, 1) in c:\program files\easyphp1-8\www\ukcohouse\drupal-5.1\includes\database.mysql.inc on line 172.
I've found the code in gmap_location.module that's doing this (I think!) but there are a number of things going on that I don't get. The code I think is trying to insert the table into {location}:
db_query("INSERT INTO {location} (eid, type, latitude, longitude, source) VALUES (%d, '%s', '%f', '%f', '%d')",
$object->eid, $type, $object->gmap_location_latitude,$object->gmap_location_longitude, 1);
Before I can start trying to fix this, I need to understand it, and I'm a bit flummoxed!
I'm finding the database abstraction API confusing: I hope someone can help out there. How does Drupal use the modifiers? Are they having the concurrent variables passed to them? Are they simply in the order that follows, e.g. %d = $object->eid, '$s' = $type, etc?
If so, I think the table needs a unique ID, which I believe is the 'lid' field. This doesn't seem to be added in the query above. Is there a setting through PHPmyAdmin that would make this column auto-increment? Or should I use something like LAST_INSERT_ID( )?
Any help would be enormously appreciated: the rest of the site's working wonderfully. (This is my first Drupal site, having used Joomla before: Drupal, it must be said, is soooo much better...)
Dan