libdballe  5.18
cursor.h
Go to the documentation of this file.
00001 /*
00002  * db/cursor - manage select queries
00003  *
00004  * Copyright (C) 2005--2010  ARPA-SIM <urpsim@smr.arpa.emr.it>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018  *
00019  * Author: Enrico Zini <enrico@enricozini.com>
00020  */
00021 
00028 #ifndef DBA_DB_CURSOR_H
00029 #define DBA_DB_CURSOR_H
00030 
00031 #include <dballe/db/odbcworkarounds.h>
00032 #include <wreport/varinfo.h>
00033 #include <sqltypes.h>
00034 #include <vector>
00035 
00036 namespace dballe {
00037 struct DB;
00038 struct Record;
00039 
00040 namespace db {
00041 struct Statement;
00042 
00047 typedef std::vector<wreport::Varcode> AttrList;
00048 
00053 struct Cursor
00054 {
00056     DB& db;
00058     db::Statement* stm;
00059 
00061     unsigned int wanted;
00062 
00064     unsigned int modifiers;
00065 
00068     unsigned int from_wanted;
00069 
00073     DBALLE_SQL_C_SINT_TYPE  out_lat;
00074     DBALLE_SQL_C_SINT_TYPE  out_lon;
00075     char    out_ident[64];      SQLLEN out_ident_ind;
00076     DBALLE_SQL_C_SINT_TYPE  out_ltype1;
00077     DBALLE_SQL_C_SINT_TYPE  out_l1;
00078     DBALLE_SQL_C_SINT_TYPE  out_ltype2;
00079     DBALLE_SQL_C_SINT_TYPE  out_l2;
00080     DBALLE_SQL_C_SINT_TYPE  out_pind;
00081     DBALLE_SQL_C_SINT_TYPE  out_p1;
00082     DBALLE_SQL_C_SINT_TYPE  out_p2;
00083     wreport::Varcode        out_varcode;
00084     SQL_TIMESTAMP_STRUCT    out_datetime;
00085     char    out_value[255];
00086     DBALLE_SQL_C_SINT_TYPE  out_rep_cod;
00087     DBALLE_SQL_C_SINT_TYPE  out_ana_id;
00088     DBALLE_SQL_C_SINT_TYPE  out_context_id;
00089     DBALLE_SQL_C_SINT_TYPE  out_priority;
00093     DBALLE_SQL_C_SINT_TYPE count;
00094 
00095     Cursor(DB& db);
00096     ~Cursor();
00097 
00113     int query(const Record& query, unsigned int wanted, unsigned int modifiers);
00114 
00122     int remaining() const;
00123 
00130     bool next();
00131 
00133     void discard_rest();
00134 
00141     void to_record(Record& rec);
00142 
00146     unsigned query_attrs(const AttrList& qcs, Record& attrs);
00147 
00148 protected:
00150     void reset();
00151 
00153     void add_station_info(Record& rec);
00154 
00164     int getcount(const Record& query, unsigned int wanted, unsigned int modifiers);
00165 };
00166 
00167 } // namespace db
00168 } // namespace dballe
00169 
00170 /* vim:set ts=4 sw=4: */
00171 #endif