? diff ? location.pgsql ? database/zipcodes.pgsql Index: location.module =================================================================== RCS file: /cvs/drupal/contributions/modules/location/location.module,v retrieving revision 1.42 diff -u -r1.42 location.module --- location.module 30 Sep 2005 23:11:08 -0000 1.42 +++ location.module 9 Nov 2005 19:25:53 -0000 @@ -111,11 +111,11 @@ if (count($postal_codes)) { $query_fragment = "'". implode(array_keys($postal_codes), ',') ."'"; - $sql = "SELECT n.nid, a.postal_code, a.city, a.province, a.country, n.title, n.teaser, n.type, n.created, n.nid, u.name, FIND_IN_SET(CONCAT(country, postal_code), ". $query_fragment .") AS search_rank FROM {location} a INNER JOIN {node} n ON a.oid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE a.type = 'node' AND FIND_IN_SET(CONCAT(a.country, a.postal_code), ". $query_fragment .") > 0 ORDER BY search_rank ASC, created DESC"; + $sql = "SELECT n.nid, a.postal_code, a.city, a.province, a.country, n.title, n.teaser, n.type, n.created, n.nid, u.name, FIND_IN_SET(CONCAT(country, postal_code), ". $query_fragment .") AS search_rank FROM {location} a INNER JOIN {node} n ON a.lid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE a.type = 'node' AND FIND_IN_SET(CONCAT(a.country, a.postal_code), ". $query_fragment .") > 0 ORDER BY search_rank ASC, created DESC"; - $count_sql = "SELECT COUNT(*) FROM {location} a INNER JOIN {node} n ON a.oid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE a.type = 'node' AND FIND_IN_SET(CONCAT(a.country, a.postal_code), ". $query_fragment .") > 0"; + $count_sql = "SELECT COUNT(*) FROM {location} a INNER JOIN {node} n ON a.lid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE a.type = 'node' AND FIND_IN_SET(CONCAT(a.country, a.postal_code), ". $query_fragment .") > 0"; - $count_display_sql = "SELECT COUNT(*) as result_count FROM {location} a INNER JOIN {node} n ON a.oid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE FIND_IN_SET(CONCAT(a.country, a.postal_code), ". $query_fragment .") > 0"; + $count_display_sql = "SELECT COUNT(*) as result_count FROM {location} a INNER JOIN {node} n ON a.lid = n.nid INNER JOIN {users} u ON n.uid = u.uid WHERE FIND_IN_SET(CONCAT(a.country, a.postal_code), ". $query_fragment .") > 0"; $res = pager_query($sql, 15, 0, $count_sql); @@ -435,7 +435,7 @@ // If the lat/lon was determined from geocoding, then we will want to update the lat/lon using postal codes. // If the lat/lon was user-submitted, then we don't want to allow the current editor to change the lat/lon if ($node->nid) { - $result = db_query("SELECT * FROM {location} WHERE type = 'node' AND oid = %d", $node->nid); + $result = db_query("SELECT * FROM {location} WHERE type = 'node' AND lid = %d", $node->nid); if ($location = db_fetch_object($result)) { if ($location->source != LOCATION_LATLON_USER_SUBMITTED) { if ($data = location_get_postalcode_data($node->location)) { @@ -488,7 +488,7 @@ break; case 'load': - $res = db_query("SELECT * FROM {location} WHERE type = 'node' AND oid = %d", $node->nid); + $res = db_query("SELECT * FROM {location} WHERE type = 'node' AND lid = %d", $node->nid); $location = array(); if ($node_location = db_fetch_object($res)) { //$location = object2array($node_location); @@ -627,7 +627,7 @@ } if ($op == 'load' && $user_setting != LOCATION_USER_DONT_COLLECT) { - $res = db_query("SELECT * FROM {location} WHERE type = 'user' AND oid = %d", $user->uid); + $res = db_query("SELECT * FROM {location} WHERE type = 'user' AND lid = %d", $user->uid); if ($location = db_fetch_object($res)) { $user->location = object2array($location); } @@ -688,8 +688,8 @@ $field = ($type == 'node' ? 'nid': 'uid'); if (isset($posted_location) && count($posted_location)) { if (isset($posted_location['lat']) && isset($posted_location['lon'])) { - db_query("DELETE FROM {location} WHERE type = '%s' AND oid = %d", $type, $user_or_node->$field); - db_query("INSERT INTO {location} (type, oid, name, street, additional, city, province, postal_code, country, latitude, longitude, source) VALUES ('%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', %d)", + db_query("DELETE FROM {location} WHERE type = '%s' AND lid = %d", $type, $user_or_node->$field); + db_query("INSERT INTO {location} (type, lid, name, street, additional, city, province, postal_code, country, latitude, longitude, source) VALUES ('%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', %d)", $type, $user_or_node->$field, (!isset($posted_location['name']) || is_null($posted_location['name'])) ? '' : $posted_location['name'], @@ -705,8 +705,8 @@ ); } else { - db_query("DELETE FROM {location} WHERE type = '%s' AND oid = %d", $type, $user_or_node->$field); - db_query("INSERT INTO {location} (type, oid, name, street, additional, city, province, postal_code, country, source) VALUES ('%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + db_query("DELETE FROM {location} WHERE type = '%s' AND lid = %d", $type, $user_or_node->$field); + db_query("INSERT INTO {location} (type, lid, name, street, additional, city, province, postal_code, country, source) VALUES ('%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $type, $user_or_node->$field, (!isset($posted_location['name']) || is_null($posted_location['name'])) ? '' : $posted_location['name'], Index: location.mysql =================================================================== RCS file: /cvs/drupal/contributions/modules/location/location.mysql,v retrieving revision 1.5 diff -u -r1.5 location.mysql --- location.mysql 18 Aug 2005 02:59:32 -0000 1.5 +++ location.mysql 9 Nov 2005 19:25:53 -0000 @@ -1,5 +1,5 @@ CREATE TABLE location ( - oid int(10) unsigned NOT NULL default '0', + lid int(10) unsigned NOT NULL default '0', type varchar(6) NOT NULL default '', name varchar(255) default NULL, street varchar(255) default NULL, @@ -11,6 +11,6 @@ latitude decimal(10,6) default NULL, longitude decimal(10,6) default NULL, source tinyint(4) default '0', - PRIMARY KEY (type,oid) + PRIMARY KEY (type,lid) ) TYPE=MyISAM; Index: location_upgrade.php =================================================================== RCS file: /cvs/drupal/contributions/modules/location/location_upgrade.php,v retrieving revision 1.4 diff -u -r1.4 location_upgrade.php --- location_upgrade.php 21 Sep 2005 00:54:08 -0000 1.4 +++ location_upgrade.php 9 Nov 2005 19:25:53 -0000 @@ -24,7 +24,8 @@ $sql_updates = array(0 => '', 1 => 'Mid 4.6 upgrade -- Merge location_user and location_node tables into location', 2 => "Mid 4.6 upgrade II -- Rename column 'exact' to 'source'", - 3 => "Correction to zipcode data" + 3 => "Correction to zipcode data", + 4 => "Mid 4.6 upgrade III -- Rename column 'oid' to 'lid'" ); if (!ini_get("safe_mode")) { @@ -160,4 +161,19 @@ db_query("UPDATE {zipcodes} SET city = 'North Plainfield' WHERE country = 'us' AND zip = '07060'"); } +function location_update_4() { + db_query("ALTER TABLE {location_node} ADD type varchar(6) NOT NULL DEFAULT ''"); + db_query("UPDATE {location_node} SET type = 'node'"); + db_query("ALTER TABLE {location_node} DROP PRIMARY KEY"); + db_query("ALTER TABLE {location_node} CHANGE nid oid int(10) unsigned NOT NULL default '0'"); + db_query("ALTER TABLE {location_node} ADD PRIMARY KEY (type, oid)"); + + $result = db_query("SELECT * FROM {location_user}"); + while ($row = db_fetch_object($result)) { + db_query("INSERT INTO {location_node} (oid, name, street, additional, city, province, postal_code, country, latitude, longitude, exact, type) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', %d, 'user')", $row->uid, $row->name, $row->street, $row->additional, $row->city, $row->province, $row->postal_code, $row->country, $row->latitude, $row->longitude, $row->exact, $row->type); + } + db_query("RENAME TABLE {location_node} TO {location}"); + db_query("ALTER TABLE {location_node} rename oid to lid"); +} + ?> --- /dev/null Wed Nov 9 13:26:03 2005 +++ zipcodes.pgsql Wed Nov 9 13:24:53 2005 @@ -0,0 +1,15 @@ +-- +-- Table structure for table zipcodes +-- + +CREATE TABLE zipcodes ( + zip varchar(16) NOT NULL default '0', + city varchar(30) NOT NULL default '', + state varchar(30) NOT NULL default '', + latitude decimal NOT NULL default '0.000000', + longitude decimal NOT NULL default '0.000000', + timezone smallint NOT NULL default '0', + dst smallint NOT NULL default '0', + country varchar(2) default '', + PRIMARY KEY (zip) +); --- /dev/null Wed Nov 9 13:26:14 2005 +++ location.pgsql Wed Nov 9 13:24:47 2005 @@ -0,0 +1,16 @@ +CREATE TABLE location ( + lid integer NOT NULL default '0', + type varchar(6) NOT NULL default '', + name varchar(255) default NULL, + street varchar(255) default NULL, + additional varchar(255) default NULL, + city varchar(255) default NULL, + province varchar(16) default NULL, + postal_code varchar(16) default NULL, + country varchar(2) default NULL, + latitude decimal default NULL, + longitude decimal default NULL, + source smallint default '0', + PRIMARY KEY (lid) +); +