Re: Keeping Mears in Database
Brought to you by:
iridium
|
From: Klaus D. <kla...@gm...> - 2003-04-06 21:38:35
|
On Sun, 06 Apr 2003 17:58:09 +0200
Martin Geisler <gim...@gi...> wrote:
>
> But as Klaus notes, then it shouldn't be that difficult for the SQL
> based backends: just fetch the newest METAR for a given station per
> default and then always insert new METARs instead of replacing the one
> ones.
Martin,
as I mentioned before, inserting gets duplicate keys, I don't know
exactly why and how. Anyways, what I did so far:
Not to interfere with the flow logic of the program I look at what would
happen if I try to save teh metars in an own history table.
I created a new table (metars_history) with the colums req_time, icao,
metar, metar_time (time of request, icao, metar, time metar was
created). req_time and icao are set to UNIQUE.
I put the following statement into defaults-dist.php:
$this->properties['db_metars_hist'] = 'metars_history';
I inserted a new function to pw_db_mysql.php:
function insert_metar_history($icao, $metar, $timestamp) {
$this->query(sprintf('INSERT INTO %s SET icao = "%s", ' .
'metar = "%s", metar_time = FROM_UNIXTIME(%d),
req_time = NOW()',
$this->properties['db_metars_hist'], $icao,
addslashes($metar), intval($timestamp)));
}
I added two lines in data_retrieval.php:
/* We then cache the METAR in our database */
if ($new_station) {
$this->debug('get_metar_from_web(): Inserting new METAR for
<code>' .
$this->get_location() . '</code>');
$this->db->insert_metar($icao, $metar, $timestamp);
---> $this->db->insert_metar_history($icao, $metar, $timestamp);
} else {
$this->debug('get_metar_from_web(): Updating METAR for <code>' .
$this->get_location() . '</code>');
$this->db->update_metar($icao, $metar, $timestamp);
--> $this->db->insert_metar_history($icao, $metar, $timestamp);
}
Unfortunately, the insert doesn' happen. Is it easy with this concept to get the history table populated?
Thanks and best regards,
Klaus
|