IODA Bundle
Select.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// @author Piotr Kuchta
12 /// @author
13 /// @date April 2010
14 
15 #ifndef odc_Select_H
16 #define odc_Select_H
17 
18 #ifdef SWIGPYTHON
19 #include <Python.h>
20 #endif
21 
22 #include "odc/IteratorProxy.h"
23 #include "odc/SelectIterator.h"
24 #include "eckit/sql/SQLSession.h"
25 
26 namespace eckit { class PathName; }
27 namespace eckit { class DataHandle; }
28 
29 namespace odc {
30 
31 //----------------------------------------------------------------------------------------------------------------------
32 
33 class Select
34 {
35 public:
37  typedef iterator::Row row;
38 
39  Select(const std::string& selectStatement="", bool manageOwnBuffer=true);
40  Select(const std::string& selectStatement, eckit::DataHandle& dh, bool manageOwnBuffer=true);
41  Select(const std::string& selectStatement, const std::string& path, bool manageOwnBuffer=true);
42 
43  // This only exists to disambiguate const char* --> std::string rather than to bool.
44  Select(const std::string& selectStatement, const char* path, bool manageOwnBuffer=true);
45 
46  virtual ~Select();
47 
48 #ifdef SWIGPYTHON
50 #endif
51 
52  eckit::sql::SQLDatabase& database();
53 
54  iterator begin();
55  const iterator end();
56 
57  SelectIterator* createSelectIterator(const std::string&);
58 
59 private:
60 
61 
62  friend class odc::IteratorProxy<odc::SelectIterator, odc::Select, const double>;
63 
64  std::unique_ptr<eckit::DataHandle> ownDH_;
65 
66 // std::istream* istream_;
67 
68  std::string selectStatement_;
69  std::string delimiter_;
70 
71  eckit::sql::SQLSession session_;
72 
73  // This is horrible, but the TextReader, and any stream based iteraton, can only
74  // iterate once, so we MUST NOT create two iterators if begin() is called twice.
75  bool initted_;
77 };
78 
79 //----------------------------------------------------------------------------------------------------------------------
80 
81 } // namespace odc
82 
83 #endif
eckit::sql::SQLDatabase & database()
Definition: Select.cc:64
std::string delimiter_
Definition: Select.h:69
const iterator end()
Definition: Select.cc:77
bool initted_
Definition: Select.h:75
std::string selectStatement_
Definition: Select.h:68
iterator it_
Definition: Select.h:76
std::unique_ptr< eckit::DataHandle > ownDH_
Definition: Select.h:64
Select(const std::string &selectStatement="", bool manageOwnBuffer=true)
Definition: Select.cc:32
virtual ~Select()
Definition: Select.cc:62
eckit::sql::SQLSession session_
Definition: Select.h:71
iterator begin()
Definition: Select.cc:81
IteratorProxy< SelectIterator, Select, const double > iterator
Definition: Select.h:36
SelectIterator * createSelectIterator(const std::string &)
Definition: Select.cc:69
iterator::Row row
Definition: Select.h:37
Definition: ColumnInfo.h:23