Utils.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/sqlite/Utils.h
22 
23  \brief Utility functions for the TerraLib SQLite Data Access driver.
24 */
25 
26 #ifndef __TERRALIB_SQLITE_INTERNAL_UTILS_H
27 #define __TERRALIB_SQLITE_INTERNAL_UTILS_H
28 
29 // TerraLib
30 #include "../dataaccess/Enums.h"
31 #include "../geometry/Enums.h"
32 
33 // STL
34 #include <iosfwd>
35 #include <map>
36 
37 extern "C"
38 {
39  struct sqlite3;
40  typedef struct sqlite3 sqlite3;
41 
42  struct sqlite3_stmt;
43  typedef struct sqlite3_stmt sqlite3_stmt;
44 }
45 
46 namespace te
47 {
48  namespace da
49  {
50  class DataSet;
51  class DataSource;
52  class DataSetType;
53  }
54 
55  namespace dt
56  {
57  class Property;
58  }
59 
60  namespace gm
61  {
62  class Envelope;
63  }
64 
65  namespace sqlite
66  {
67  int GetConnectionFlags(const std::map<std::string, std::string>& connInfo);
68 
69  bool Exists(const std::map<std::string, std::string>& dbInfo);
70 
71  void ExecuteScript(sqlite3* db, const char* fileName);
72 
73  void PerformCommands(sqlite3* db, std::istream& istr);
74 
75  void PerformCommands(sqlite3* db, const char* sql);
76 
77  std::streamsize ReadLine(std::istream& istr, char** pbuff, std::size_t& buffsize);
78 
79  bool IsAllWhitespace(const char* sqlLine);
80 
81  bool IsCommandTerminator(const char* sqlLine);
82 
83  bool ContainsSemicolon(const char* sql, std::size_t nbytes);
84 
85  bool IsComplete(char** sql, size_t len, std::size_t& buffsize);
86 
87  void GetHiddenTables(const te::da::DataSource* ds, std::vector<std::string>& tables);
88 
90 
92  const std::string& colName,
93  const std::string& colType,
94  bool required,
95  std::string* defaultValue = 0);
96 
97  int Convert2TerraLibCategory(const std::string& category);
98 
99  std::string GetRtreeFilter(const te::gm::Envelope* e, const te::gm::SpatialRelation r);
100 
101  std::string GetBindableSpatialRelation(const std::string& colName, const te::gm::SpatialRelation r);
102 
103  void Convert2SpatiaLiteGeom(const te::gm::GeomType t, std::string& geomType, std::string& dimension);
104 
105  std::string GetSQLType(const te::dt::Property* p);
106 
107  te::da::FKActionType GetAction(const std::string& action);
108 
109  std::string Convert2SQLCreate(const te::dt::Property* p);
110 
111  std::string GetSQLBindValues(const te::da::DataSet* dataset);
112 
113  } // end namespace sqlite
114 } // end namespace te
115 
116 #endif // __TERRALIB_SQLITE_INTERNAL_UTILS_H
std::string GetRtreeFilter(const te::gm::Envelope *e, const te::gm::SpatialRelation r)
void Convert2SpatiaLiteGeom(const te::gm::GeomType t, std::string &geomType, std::string &dimension)
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
struct sqlite3 sqlite3
A class that models the description of a dataset.
Definition: DataSetType.h:72
FKActionType
Type of action performed on the foreign key data.
Definition: Enums.h:93
void GetHiddenTables(const te::da::DataSource *ds, std::vector< std::string > &tables)
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:127
std::string Convert2SQLCreate(const te::dt::Property *p)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
te::da::DataSetType * Convert2TerraLib(sqlite3_stmt *pStmt)
It models a property definition.
Definition: Property.h:59
bool IsCommandTerminator(const char *sqlLine)
bool IsComplete(char **sql, size_t len, std::size_t &buffsize)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
URI C++ Library.
bool IsAllWhitespace(const char *sqlLine)
std::string GetSQLType(const te::dt::Property *p)
void PerformCommands(sqlite3 *db, std::istream &istr)
std::string GetBindableSpatialRelation(const std::string &colName, const te::gm::SpatialRelation r)
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
std::streamsize ReadLine(std::istream &istr, char **pbuff, std::size_t &buffsize)
void ExecuteScript(sqlite3 *db, const char *fileName)
struct sqlite3_stmt sqlite3_stmt
Definition: FwDataSet.h:35
std::string GetSQLBindValues(const te::da::DataSet *dataset)
bool ContainsSemicolon(const char *sql, std::size_t nbytes)
bool Exists(const std::map< std::string, std::string > &dbInfo)
te::da::FKActionType GetAction(const std::string &action)
int Convert2TerraLibCategory(const std::string &category)
int GetConnectionFlags(const std::map< std::string, std::string > &connInfo)