libdballe  5.18
cursor.h
Go to the documentation of this file.
1 /*
2  * db/cursor - manage select queries
3  *
4  * Copyright (C) 2005--2010 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_CURSOR_H
29 #define DBA_DB_CURSOR_H
30 
32 #include <wreport/varinfo.h>
33 #include <sqltypes.h>
34 #include <vector>
35 
36 namespace dballe {
37 struct DB;
38 struct Record;
39 
40 namespace db {
41 struct Statement;
42 
47 typedef std::vector<wreport::Varcode> AttrList;
48 
53 struct Cursor
54 {
56  DB& db;
59 
61  unsigned int wanted;
62 
64  unsigned int modifiers;
65 
68  unsigned int from_wanted;
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(DB& db);
96  ~Cursor();
97 
113  int query(const Record& query, unsigned int wanted, unsigned int modifiers);
114 
122  int remaining() const;
123 
130  bool next();
131 
133  void discard_rest();
134 
141  void to_record(Record& rec);
142 
146  unsigned query_attrs(const AttrList& qcs, Record& attrs);
147 
148 protected:
150  void reset();
151 
153  void add_station_info(Record& rec);
154 
164  int getcount(const Record& query, unsigned int wanted, unsigned int modifiers);
165 };
166 
167 } // namespace db
168 } // namespace dballe
169 
170 /* vim:set ts=4 sw=4: */
171 #endif