IODA Bundle
SelectIterator.cc
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 #include "eckit/sql/SQLParser.h"
12 #include "eckit/sql/SQLSelectFactory.h"
13 #include "eckit/sql/SQLSelect.h"
14 
15 #include "odc/core/MetaData.h"
16 #include "odc/Select.h"
17 #include "odc/SelectIterator.h"
19 
20 
21 using namespace eckit;
22 
23 namespace odc {
24 
25 //----------------------------------------------------------------------------------------------------------------------
26 
27 SelectIterator::SelectIterator(const std::string& select, eckit::sql::SQLSession& s, sql::SQLSelectOutput& output) :
28  select_(select),
29  output_(output),
30  session_(s),
31  noMore_(false),
32  refCount_(0) {
33 
34  parse();
35 }
36 
38 
39 
41 
42  eckit::sql::SQLParser p;
43  p.parseString(session_, select_);
44  eckit::sql::SQLStatement& stmt (session_.statement());
45 
46  // n.b. non-owning
47  selectStmt_ = dynamic_cast<eckit::sql::SQLSelect*>(&stmt);
48  if (! selectStmt_)
49  throw UserError(std::string("Expected SELECT, got: ") + select_);
50 
51  selectStmt_->prepareExecute();
52 }
53 
54 
56  bool ret;
57  if (noMore_) return false;
58  if (!(ret = selectStmt_->processOneRow())) {
59  selectStmt_->postExecute();
60  noMore_ = true;
61  }
62  return ret;
63 }
64 
65 
66 void SelectIterator::setOutputRowBuffer(double* data, size_t count) {
68 }
69 
70 
71 //----------------------------------------------------------------------------------------------------------------------
72 
73 } // namespace odc
static void count(void *counter, const double *data, size_t n)
Definition: UnitTests.cc:531
sql::SQLSelectOutput & output_
void setOutputRowBuffer(double *data, size_t count=0)
Set an output buffer for retrieving the next row(s)
const double * data() const
eckit::sql::SQLSession & session_
eckit::sql::SQLSelect * selectStmt_
void resetBuffer(double *out, size_t count)
Definition: ColumnInfo.h:23