SQLVisitor.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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 Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/dataaccess/query/SQLVisitor.h
22 
23  \brief A visitor for building an SQL statement from a given Query hierarchy.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_SQLVISITOR_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_SQLVISITOR_H
28 
29 // TerraLib
30 #include "Distinct.h"
31 #include "Fields.h"
32 #include "From.h"
33 #include "GroupBy.h"
34 #include "OrderBy.h"
35 #include "QueryVisitor.h"
36 
37 // STL
38 #include <string>
39 
40 // Boost
41 #include <boost/noncopyable.hpp>
42 
43 namespace te
44 {
45  namespace da
46  {
47 // Forward declarations
48  class SQLDialect;
49 
50  /*!
51  \class SQLVisitor
52 
53  \brief A visitor for building an SQL statement from a given Query hierarchy.
54 
55  Each driver must implement a SQL dialect in order help
56  this class to translate the query object to its specific dialect.
57  */
58  class TEDATAACCESSEXPORT SQLVisitor : public QueryVisitor, public boost::noncopyable
59  {
60  public:
61 
62  //using QueryVisitor::visit;
63 
64  /*! \brief Default constructor. */
65  SQLVisitor(const SQLDialect& dialect, std::string& sql) : m_dialect(dialect), m_sql(sql) {}
66 
67  /*! \brief Virtual destructor. */
68  virtual ~SQLVisitor() {}
69 
70  virtual void visit(const Expression& visited);
71  virtual void visit(const DataSetName& visited);
72  virtual void visit(const FromItem& visited);
73  virtual void visit(const Function& visited);
74  virtual void visit(const Insert& visited);
75  virtual void visit(const Join& visited);
76  virtual void visit(const JoinCondition& visited);
77  virtual void visit(const JoinConditionOn& visited);
78  virtual void visit(const JoinConditionUsing& visited);
79  virtual void visit(const Literal& visited);
80  virtual void visit(const LiteralBool& visited);
81  virtual void visit(const LiteralByteArray& visited);
82  virtual void visit(const LiteralDateTime& visited);
83  virtual void visit(const LiteralDouble& visited);
84  virtual void visit(const LiteralEnvelope& visited);
85  virtual void visit(const LiteralGeom& visited);
86  virtual void visit(const LiteralInt16& visited);
87  virtual void visit(const LiteralInt32& visited);
88  virtual void visit(const LiteralInt64& visited);
89  virtual void visit(const LiteralString& visited);
90  virtual void visit(const PropertyName& visited);
91  virtual void visit(const Query& visited);
92  virtual void visit(const Select& visited);
93  virtual void visit(const SelectExpression& visited);
94  virtual void visit(const SubSelect& visited);
95  virtual void visit(const In& visited);
96 
97 
98 // these methods are not true visitors... but let's keep the idea!
99  virtual void visitDistinct(const Distinct& visited);
100  virtual void visit(const Fields& visited);
101  virtual void visit(const From& visited);
102  virtual void visit(const GroupBy& visited);
103  virtual void visit(const OrderBy& visited);
104 
105  protected:
106 
107  const SQLDialect& m_dialect; //!< The function catalog to use when translating the query.
108  std::string& m_sql; //!< The buffer string where the query will be outputed.
109 
110  };
111 
112  } // end namespace da
113 } // end namespace te
114 
115 
116 #endif // __TERRALIB_DATAACCESS_INTERNAL_SQLVISITOR_H
117 
boost::ptr_vector< GroupByItem > GroupBy
A class that can be used to model a GROUP BY clause.
Definition: GroupBy.h:37
te::da::SQLDialect * dialect
Definition: WFSDialect.h:1
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
boost::ptr_vector< Expression > Distinct
A class that models a Distinct clause on a query.
Definition: Distinct.h:37
virtual ~SQLVisitor()
Virtual destructor.
Definition: SQLVisitor.h:68
A class that models the name of any property of an object.
Definition: PropertyName.h:50
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
A class that models a Distinct clause on a query.
This class models a bool Literal value.
Definition: LiteralBool.h:43
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause.
Definition: OrderBy.h:37
A visitor interface for the Query hierarchy.
The Insert object can add the return of a select object.
Definition: Insert.h:50
This is an abstract class that models a query expression.
Definition: Expression.h:47
A class that models a literal for Date and Time values.
A visitor interface for the Query hierarchy.
Definition: QueryVisitor.h:47
This class models a literal value.
Definition: Literal.h:53
URI C++ Library.
A class that models a literal for ByteArray values.
A condition to be used in a Join clause.
Definition: JoinCondition.h:44
std::string & m_sql
The buffer string where the query will be outputed.
Definition: SQLVisitor.h:108
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
A class that models a Function expression.
Definition: Function.h:47
A Join clause combines two FromItems.
Definition: Join.h:50
A class that models a literal for double values.
Definition: LiteralDouble.h:43
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
A class that can be used to model a GROUP BY clause.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
A Select can be used as a source of information in another query.
JoinConditionUsing class can be used to model a USING clause in a Join.
A class that can be used to model an ORDER BY clause.
A class that models a literal for Envelope values.
It models the FROM clause for a query.
A visitor for building an SQL statement from a given Query hierarchy.
Definition: SQLVisitor.h:58
The Fields class can be used to model a set of expressions that form the output items of a SELECT...
A class that represents the IN operator.
Definition: In.h:52
JoinConditionOn is a boolean expression and it specifies which items in a join are considered to matc...
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
A Select can be used as a source of information in another query.
Definition: SubSelect.h:49
SQLVisitor(const SQLDialect &dialect, std::string &sql)
Default constructor.
Definition: SQLVisitor.h:65
A Query is independent from the data source language/dialect.
Definition: Query.h:46
A class that models a literal for Geometry values.
Definition: LiteralGeom.h:46
This class models a string Literal value.
Definition: LiteralString.h:46
const SQLDialect & m_dialect
The function catalog to use when translating the query.
Definition: SQLVisitor.h:107