Line data Source code
1 : /****************************************************************************** 2 : * $Id$ 3 : * 4 : * Project: GeoPackage Translator 5 : * Purpose: Utility header for OGR GeoPackage driver. 6 : * Author: Paul Ramsey, pramsey@boundlessgeo.com 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2013, Paul Ramsey <pramsey@boundlessgeo.com> 10 : * 11 : * Permission is hereby granted, free of charge, to any person obtaining a 12 : * copy of this software and associated documentation files (the "Software"), 13 : * to deal in the Software without restriction, including without limitation 14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 : * and/or sell copies of the Software, and to permit persons to whom the 16 : * Software is furnished to do so, subject to the following conditions: 17 : * 18 : * The above copyright notice and this permission notice shall be included 19 : * in all copies or substantial portions of the Software. 20 : * 21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 : * DEALINGS IN THE SOFTWARE. 28 : ****************************************************************************/ 29 : 30 : #ifndef OGR_SQLITEUTILITY_H_INCLUDED 31 : #define OGR_SQLITEUTILITY_H_INCLUDED 32 : 33 : #include "ogr_core.h" 34 : #include "cpl_string.h" 35 : #include "sqlite3.h" 36 : 37 : #include <set> 38 : #include <string> 39 : #include <memory> 40 : #include <vector> 41 : 42 : class SQLResult 43 : { 44 : public: 45 : SQLResult(char **result, int nRow, int nCol); 46 : ~SQLResult(); 47 : 48 50242 : int RowCount() const 49 : { 50 50242 : return nRowCount; 51 : } 52 : 53 755 : int ColCount() const 54 : { 55 755 : return nColCount; 56 : } 57 : 58 : void LimitRowCount(int nLimit); 59 : 60 : const char *GetValue(int iColumnNum, int iRowNum) const; 61 : int GetValueAsInteger(int iColNum, int iRowNum) const; 62 : double GetValueAsDouble(int iColNum, int iRowNum) const; 63 : 64 : private: 65 : char **papszResult = nullptr; 66 : int nRowCount = 0; 67 : int nColCount = 0; 68 : 69 : CPL_DISALLOW_COPY_ASSIGN(SQLResult) 70 : }; 71 : 72 : OGRErr SQLCommand(sqlite3 *poDb, const char *pszSQL); 73 : int SQLGetInteger(sqlite3 *poDb, const char *pszSQL, OGRErr *err); 74 : GIntBig SQLGetInteger64(sqlite3 *poDb, const char *pszSQL, OGRErr *err); 75 : 76 : std::unique_ptr<SQLResult> SQLQuery(sqlite3 *poDb, const char *pszSQL); 77 : 78 : /* To escape literals. The returned string doesn't contain the surrounding 79 : * single quotes */ 80 : CPLString SQLEscapeLiteral(const char *pszLiteral); 81 : 82 : /* To escape table or field names. The returned string doesn't contain the 83 : * surrounding double quotes */ 84 : CPLString SQLEscapeName(const char *pszName); 85 : 86 : /* Remove leading ' or " and unescape in that case. Or return string unmodified 87 : */ 88 : CPLString SQLUnescape(const char *pszVal); 89 : 90 : char **SQLTokenize(const char *pszSQL); 91 : 92 : struct SQLSqliteMasterContent 93 : { 94 : std::string osSQL{}; 95 : std::string osType{}; 96 : std::string osTableName{}; 97 : }; 98 : 99 : std::set<std::string> SQLGetUniqueFieldUCConstraints( 100 : sqlite3 *poDb, const char *pszTableName, 101 : const std::vector<SQLSqliteMasterContent> &sqliteMasterContent = 102 : std::vector<SQLSqliteMasterContent>()); 103 : 104 : bool OGRSQLiteRTreeRequiresTrustedSchemaOn(); 105 : 106 : bool OGRSQLiteIsSpatialFunctionReturningGeometry(const char *pszName); 107 : 108 : #endif // OGR_SQLITEUTILITY_H_INCLUDED