libdballe  7.7
db/sqlite/station.h
Go to the documentation of this file.
1 /*
2  * db/station - station table management
3  *
4  * Copyright (C) 2005--2015 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBALLE_DB_SQLITE_STATION_H
23 #define DBALLE_DB_SQLITE_STATION_H
24 
31 #include <dballe/db/sql/station.h>
32 #include <functional>
33 #include <memory>
34 
35 namespace wreport {
36 struct Var;
37 }
38 
39 namespace dballe {
40 namespace db {
41 struct SQLiteConnection;
42 struct SQLiteStatement;
43 
44 namespace sqlite {
45 
50 {
51 protected:
56 
58  SQLiteStatement* sfstm = nullptr;
60  SQLiteStatement* smstm = nullptr;
62  SQLiteStatement* istm = nullptr;
63 
65  bool maybe_get_id(int lat, int lon, const char* ident, int* id);
66 
68  void read_station_vars(SQLiteStatement& stm, std::function<void(std::unique_ptr<wreport::Var>)> dest);
69 
70 public:
73  SQLiteStationBase(const SQLiteStationBase&) = delete;
74  SQLiteStationBase(const SQLiteStationBase&&) = delete;
75  SQLiteStationBase& operator=(const SQLiteStationBase&) = delete;
76 
85  int get_id(int lat, int lon, const char* ident=nullptr) override;
86 
95  int obtain_id(int lat, int lon, const char* ident=nullptr, bool* inserted=NULL) override;
96 
97  void get_station_vars(int id_station, int id_report, std::function<void(std::unique_ptr<wreport::Var>)> dest) override;
98  void add_station_vars(int id_station, Record& rec) override;
99 
103  void dump(FILE* out) override;
104 };
105 
107 {
108 public:
110 };
111 
112 }
113 
114 }
115 }
116 #endif
SQLiteStatement * smstm
Precompiled select mobile station query.
Definition: db/sqlite/station.h:60
void add_station_vars(int id_station, Record &rec) override
Add all station variables (without attributes) to rec.
SQLiteStatement * sfstm
Precompiled select fixed station query.
Definition: db/sqlite/station.h:58
void get_station_vars(int id_station, int id_report, std::function< void(std::unique_ptr< wreport::Var >)> dest) override
Export station variables.
SQLiteStatement * istm
Precompiled insert query.
Definition: db/sqlite/station.h:62
Definition: db/sqlite/station.h:106
SQLite statement.
Definition: sqlite/internals.h:124
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
Database connection.
Definition: sqlite/internals.h:56
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
Precompiled queries to manipulate the station table.
Definition: db/sqlite/station.h:49
Station table management used by the db module.
void dump(FILE *out) override
Dump the entire contents of the table to an output stream.
Definition: db/sql/station.h:46
Definition: conversion.h:6
int obtain_id(int lat, int lon, const char *ident=nullptr, bool *inserted=NULL) override
Get the station ID given latitude, longitude and mobile identifier.
SQLiteConnection & conn
DB connection.
Definition: db/sqlite/station.h:55
bool maybe_get_id(int lat, int lon, const char *ident, int *id)
Lookup the ID of a station, returning true if it was found, false if not.
int get_id(int lat, int lon, const char *ident=nullptr) override
Get the station ID given latitude, longitude and mobile identifier.
void read_station_vars(SQLiteStatement &stm, std::function< void(std::unique_ptr< wreport::Var >)> dest)
Run stm, read its output and generate variables to send to dest.