libdballe  6.8
v5/cursor.h
Go to the documentation of this file.
1 /*
2  * db/cursor - manage select queries
3  *
4  * Copyright (C) 2005--2013 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 
28 #ifndef DBA_DB_V5_CURSOR_H
29 #define DBA_DB_V5_CURSOR_H
30 
32 #include <dballe/db/db.h>
33 #include <wreport/varinfo.h>
34 #include <sqltypes.h>
35 #include <vector>
36 
37 namespace dballe {
38 struct Record;
39 
40 namespace db {
41 struct Statement;
42 
43 namespace v5 {
44 struct DB;
45 
50 struct Cursor : public dballe::db::Cursor
51 {
56 
58  unsigned int wanted;
59 
61  unsigned int modifiers;
62 
65  unsigned int from_wanted;
66 
69 
73  DBALLE_SQL_C_SINT_TYPE out_lat;
74  DBALLE_SQL_C_SINT_TYPE out_lon;
75  char out_ident[64]; SQLLEN out_ident_ind;
76  DBALLE_SQL_C_SINT_TYPE out_ltype1;
77  DBALLE_SQL_C_SINT_TYPE out_l1;
78  DBALLE_SQL_C_SINT_TYPE out_ltype2;
79  DBALLE_SQL_C_SINT_TYPE out_l2;
80  DBALLE_SQL_C_SINT_TYPE out_pind;
81  DBALLE_SQL_C_SINT_TYPE out_p1;
82  DBALLE_SQL_C_SINT_TYPE out_p2;
83  wreport::Varcode out_varcode;
84  SQL_TIMESTAMP_STRUCT out_datetime;
85  char out_value[255];
86  DBALLE_SQL_C_SINT_TYPE out_rep_cod;
87  DBALLE_SQL_C_SINT_TYPE out_ana_id;
88  DBALLE_SQL_C_SINT_TYPE out_context_id;
89  DBALLE_SQL_C_SINT_TYPE out_priority;
93  DBALLE_SQL_C_SINT_TYPE count;
94 
95  Cursor(v5::DB& db);
96  ~Cursor();
97 
98  virtual dballe::DB& get_db() const;
99 
115  int query(const Record& query, unsigned int wanted, unsigned int modifiers);
116 
117  // See DB::query_date_extremes
118  void query_datetime_extremes(const Record& query, Record& result);
119 
127  int remaining() const;
128 
135  bool next();
136 
138  void discard_rest();
139 
146  void to_record(Record& rec);
147 
148  virtual int get_station_id() const;
149  virtual double get_lat() const;
150  virtual double get_lon() const;
151  virtual const char* get_ident(const char* def=0) const;
152  virtual const char* get_rep_memo(const char* def=0) const;
153  virtual Level get_level() const;
154  virtual Trange get_trange() const;
155  virtual void get_datetime(int (&dt)[6]) const;
156  virtual wreport::Varcode get_varcode() const;
157  virtual wreport::Var get_var() const;
158  virtual int attr_reference_id() const;
159 
163  unsigned query_attrs(const AttrList& qcs, Record& attrs);
164  virtual void attr_insert(const Record& attrs);
165  virtual void attr_remove(const AttrList& qcs);
166 
167 protected:
169  void reset();
170 
172  void add_station_info(Record& rec);
173 
183  int getcount(const Record& query, unsigned int wanted, unsigned int modifiers);
184 };
185 
186 } // namespace v5
187 } // namespace db
188 } // namespace dballe
189 
190 /* vim:set ts=4 sw=4: */
191 #endif
unsigned int wanted
What values are wanted from the query.
Definition: v5/cursor.h:58
virtual void attr_insert(const Record &attrs)
Insert/overwrite new attributes for the current variable.
DB-ALLe database connection.
Definition: v5/db.h:83
DBALLE_SQL_C_SINT_TYPE out_pind
Query results.
Definition: v5/cursor.h:80
virtual dballe::DB & get_db() const
Get the database that created this cursor.
Definition: db.h:77
Definition: defs.h:113
The ODBC specification is imperfect with regards to integer sizes on 64bit platforms, and different ODBC drivers are currently interpreting it differently.
void add_station_info(Record &rec)
Query extra station info and add it to rec.
void to_record(Record &rec)
Fill in a record with the contents of a dba_db_cursor.
SQL_TIMESTAMP_STRUCT out_datetime
Query results.
Definition: v5/cursor.h:84
virtual Level get_level() const
Get the level.
unsigned int from_wanted
What is in the FROM part of the query, used to know what output fields are bound. ...
Definition: v5/cursor.h:65
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
DBALLE_SQL_C_SINT_TYPE out_ltype1
Query results.
Definition: v5/cursor.h:76
v5::DB & db
Database to operate on.
Definition: v5/cursor.h:53
int query(const Record &query, unsigned int wanted, unsigned int modifiers)
Create and execute a database query.
DBALLE_SQL_C_SINT_TYPE out_context_id
Query results.
Definition: v5/cursor.h:88
Structure used to build and execute a query, and to iterate through the results.
Definition: v5/cursor.h:50
virtual wreport::Var get_var() const
Get the variable.
Definition: defs.h:54
virtual int attr_reference_id() const
Return an integer value that can be used to refer to the current variable for attribute access...
Functions used to connect to DB-All.e and insert, query and delete data.
unsigned query_attrs(const AttrList &qcs, Record &attrs)
Query attributes for the current variable.
char out_ident[64]
Query results.
Definition: v5/cursor.h:75
int getcount(const Record &query, unsigned int wanted, unsigned int modifiers)
Return the number of results for a query.
virtual void get_datetime(int(&dt)[6]) const
Get the datetime.
void discard_rest()
Discard the results that have not been read yet.
virtual int get_station_id() const
Get the station identifier.
virtual void attr_remove(const AttrList &qcs)
Delete attributes for the current variable.
virtual const char * get_ident(const char *def=0) const
Get the station identifier, or NULL if missing.
char out_value[255]
Query results.
Definition: v5/cursor.h:85
bool query_station_vars
True if we are querying station variables.
Definition: v5/cursor.h:68
void reset()
Reset the cursor at the beginning of a query.
DBALLE_SQL_C_SINT_TYPE out_l2
Query results.
Definition: v5/cursor.h:79
virtual const char * get_rep_memo(const char *def=0) const
Get the report name.
DBALLE_SQL_C_SINT_TYPE out_lon
Query results.
Definition: v5/cursor.h:74
bool next()
Get a new item from the results of a query.
ODBC statement.
Definition: internals.h:220
DBALLE_SQL_C_SINT_TYPE out_ltype2
Query results.
Definition: v5/cursor.h:78
DBALLE_SQL_C_SINT_TYPE out_p2
Query results.
Definition: v5/cursor.h:82
Definition: db.h:181
virtual Trange get_trange() const
Get the level.
virtual double get_lon() const
Get the station longitude.
wreport::Varcode out_varcode
Query results.
Definition: v5/cursor.h:83
db::Statement * stm
ODBC statement to use for the query.
Definition: v5/cursor.h:55
virtual double get_lat() const
Get the station latitude.
int remaining() const
Get the number of rows still to be fetched.
virtual wreport::Varcode get_varcode() const
Get the variable code.
SQLLEN out_ident_ind
Query results.
Definition: v5/cursor.h:75
DBALLE_SQL_C_SINT_TYPE out_ana_id
Query results.
Definition: v5/cursor.h:87
unsigned int modifiers
Modifier flags to enable special query behaviours.
Definition: v5/cursor.h:61
DBALLE_SQL_C_SINT_TYPE out_l1
Query results.
Definition: v5/cursor.h:77
DBALLE_SQL_C_SINT_TYPE count
Number of results still to be fetched.
Definition: v5/cursor.h:93
DBALLE_SQL_C_SINT_TYPE out_rep_cod
Query results.
Definition: v5/cursor.h:86
DBALLE_SQL_C_SINT_TYPE out_priority
Query results.
Definition: v5/cursor.h:89
DBALLE_SQL_C_SINT_TYPE out_p1
Query results.
Definition: v5/cursor.h:81
DBALLE_SQL_C_SINT_TYPE out_lat
Query results.
Definition: v5/cursor.h:73