Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv31732

Modified Files:
        db_dba.php db_mysql.php 
Log Message:
These two database-backends can now be configured with the configurator.


Index: db_dba.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_dba.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- db_dba.php  2001/04/27 19:14:17     1.5
+++ db_dba.php  2001/05/19 16:17:53     1.6
@@ -59,23 +59,23 @@
       $this->is_connected = $this->link_id =
        dba_open($this->properties['db_path'] . '/' .
                 $this->properties['db_metars'],
-                'w',
+                'c',
                 $this->properties['db_handler']);
       $this->link_stations_id = 
        dba_open($this->properties['db_path'] . '/' .
                 $this->properties['db_stations'],
-                'r',
+                'c',
                 $this->properties['db_handler']);
     } else {
       $this->is_connected = $this->link_id =
        dba_popen($this->properties['db_path'] . '/' .
                  $this->properties['db_metars'],
-                 'w',
+                 'c',
                  $this->properties['db_handler']);
       $this->link_stations_id = 
        dba_popen($this->properties['db_path'] . '/' .
                  $this->properties['db_stations'],
-                 'r',
+                 'c',
                  $this->properties['db_handler']);
     }
     return $this->is_connected;
@@ -143,7 +143,7 @@
   }
 
   /**
-   * Translated an ICAO into a station name
+   * Translates an ICAO into a station name
    *
    * The boring ICAO (e.g. EKYT) is translated into something like 'Aalborg, Denmark'.
    *
@@ -156,6 +156,19 @@
       return dba_fetch($station, $this->link_stations_id);
     } else {
       return $station;
+    }
+  }
+
+  function create_tables() {
+    /* The databases are created when we connect */
+    return $this->connect();
+  }
+
+  function insert_station($icao, $name, $country) {
+    if (dba_exists($icao, $this->link_stations_id)) {
+      return dba_replace($icao, "$name, $country", $this->link_stations_id);
+    } else {
+      return dba_insert($icao, "$name, $country", $this->link_stations_id);
     }
   }
 }

Index: db_mysql.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/db_mysql.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- db_mysql.php        2001/04/26 13:11:00     1.4
+++ db_mysql.php        2001/05/19 16:17:53     1.5
@@ -175,6 +175,61 @@
     return $this->fetch_row();
   }
 
+  function create_tables() {
+    if ($this->connect()) {
+      /* First we make a table for the METARs */
+      $this->query('DROP TABLE IF EXISTS ' . $this->properties['db_metars']);
+      $this->query('CREATE TABLE ' . $this->properties['db_metars'] . '(
+   metar varchar(255) NOT NULL,
+   timestamp timestamp(14),
+   station varchar(4) NOT NULL,
+   PRIMARY KEY (station),
+   UNIQUE station (station)
+)');
+
+      /* Then we make a table for the stations. */
+      $this->query('DROP TABLE IF EXISTS ' . $this->properties['db_stations']);
+      $this->query('CREATE TABLE ' . $this->properties['db_stations'] . '(
+   icao varchar(4) NOT NULL,
+   name varchar(255) NOT NULL,
+   country varchar(128) NOT NULL,
+   PRIMARY KEY (icao),
+   UNIQUE icao (icao),
+   KEY country (country)
+)');
+
+      return true; // Succes!
+    } else {
+      return false; // Failure!
+    }
+  }
+
+  /**
+   * Translates an ICAO into a station name
+   *
+   * The boring ICAO (e.g. EKYT) is translated into something like 'Aalborg, Denmark'.
+   *
+   * @param   string  The ICAO one want's to translate.
+   * @return  string  The full name of the station, including country.
+   * @access  public
+   */
+  function lookup_station($station) {
+    $this->query('SELECT name, country FROM ' . $this->properties['db_stations'] .
+                "WHERE icao = '$station'");
+    if ($this->num_rows()) {
+      $row = $this->fetch_row();
+      return "$row[0], $row[1]";
+    } else {
+      return $station;
+    }
+  }
+
+  function insert_station($icao, $name, $country) {
+    $sql = 'INSERT INTO ' . $this->properties['db_stations'] .
+      " VALUES('$icao', '$name', '$country')";
+    return $this->query($sql);
+  }
+  
 }
 
 ?>


_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins

Reply via email to