Fix column names, add index on event_id to the mysql driver also.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 12 Dec 2009 18:47:04 +0000 (13:47 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 12 Dec 2009 19:06:07 +0000 (14:06 -0500)
Bug: 8768

kronolith/lib/Geo/Mysql.php
kronolith/scripts/upgrades/2009-12-11_fix_column_names.mysql.sql [new file with mode: 0644]
kronolith/scripts/upgrades/2009-12-11_fix_column_names.sql [new file with mode: 0644]

index 8a8c8f9..5548e93 100644 (file)
@@ -34,9 +34,9 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql
         }
         /* INSERT or UPDATE */
         if ($count) {
-            $sql = "UPDATE kronolith_events_geo SET coordinates = GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")') WHERE event_id = '" . $event_id . "'";
+            $sql = "UPDATE kronolith_events_geo SET event_coordinates = GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")') WHERE event_id = '" . $event_id . "'";
         } else {
-            $sql = "INSERT into kronolith_events_geo (event_id, coordinates) VALUES('" . $event_id . "', GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")'))";
+            $sql = "INSERT into kronolith_events_geo (event_id, event_coordinates) VALUES('" . $event_id . "', GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")'))";
         }
         $result = $this->_write_db->query($sql);
         if ($result instanceof PEAR_Error) {
@@ -53,7 +53,7 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql
      */
     public function getLocation($event_id)
     {
-        $sql = "SELECT x(coordinates) as lat, y(coordinates) as lon FROM kronolith_events_geo WHERE event_id = '" . $event_id . "'";
+        $sql = "SELECT x(event_coordinates) as lat, y(event_coordinates) as lon FROM kronolith_events_geo WHERE event_id = '" . $event_id . "'";
         $result = $this->_db->getRow($sql, null, DB_FETCHMODE_ASSOC);
         if ($result instanceof PEAR_Error) {
             throw new Horde_Exception($result->getMessage());
@@ -84,8 +84,8 @@ class Kronolith_Geo_Mysql extends Kronolith_Geo_Sql
 
         // ... if this works it will be a miracle ;)
         $sql = "SELECT event_id, "
-               . "GLength(LINESTRINGFromWKB(LineString(coordinates, GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")')))) * " . $factor . " as distance, "
-               . "x(coordinates) as lat, y(coordinates) as lon FROM kronolith_events_geo HAVING distance < " . $radius . " ORDER BY distance ASC LIMIT " . $limit;
+               . "GLength(LINESTRINGFromWKB(LineString(event_coordinates, GeomFromText('POINT(" . $point['lat'] . " " . $point['lon'] . ")')))) * " . $factor . " as distance, "
+               . "x(event_coordinates) as lat, y(event_coordinates) as lon FROM kronolith_events_geo HAVING distance < " . $radius . " ORDER BY distance ASC LIMIT " . $limit;
 
         $results = $this->_db->getAssoc($sql, false, null, DB_FETCHMODE_ASSOC);
         if ($results instanceof PEAR_Error) {
diff --git a/kronolith/scripts/upgrades/2009-12-11_fix_column_names.mysql.sql b/kronolith/scripts/upgrades/2009-12-11_fix_column_names.mysql.sql
new file mode 100644 (file)
index 0000000..6c8ba20
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE kronolith_events_geo CHANGE coordinates event_coordinates POINT NOT NULL;
+CREATE INDEX kronolith_events_geo_idx ON kronolith_events_geo (event_id);
\ No newline at end of file
diff --git a/kronolith/scripts/upgrades/2009-12-11_fix_column_names.sql b/kronolith/scripts/upgrades/2009-12-11_fix_column_names.sql
new file mode 100644 (file)
index 0000000..d03b595
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE kronolith_events_geo CHANGE lat event_lat VARCHAR(32) NOT NULL;
+ALTER TABLE kronolith_events_geo CHANGE lon event_lon VARCHAR(32) NOT NULL;