1 /****************************************************************************** 2 * $Id: ogrsqliteutility.h 455bf3c255ee78dc70116ca2e2b1a37aaecd0799 2020-05-30 17:43:05 +0200 Even Rouault $ 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 40 typedef struct 41 { 42 char** papszResult; 43 int nRowCount; 44 int nColCount; 45 char *pszErrMsg; 46 int rc; 47 } SQLResult; 48 49 50 OGRErr SQLCommand(sqlite3 *poDb, const char * pszSQL); 51 int SQLGetInteger(sqlite3 * poDb, const char * pszSQL, OGRErr *err); 52 GIntBig SQLGetInteger64(sqlite3 * poDb, const char * pszSQL, OGRErr *err); 53 54 OGRErr SQLResultInit(SQLResult * poResult); 55 OGRErr SQLQuery(sqlite3 *poDb, const char * pszSQL, SQLResult * poResult); 56 const char* SQLResultGetValue(const SQLResult * poResult, int iColumnNum, int iRowNum); 57 int SQLResultGetValueAsInteger(const SQLResult * poResult, int iColNum, int iRowNum); 58 OGRErr SQLResultFree(SQLResult * poResult); 59 60 int SQLiteFieldFromOGR(OGRFieldType eType); 61 62 /* To escape literals. The returned string doesn't contain the surrounding single quotes */ 63 CPLString SQLEscapeLiteral( const char *pszLiteral ); 64 65 /* To escape table or field names. The returned string doesn't contain the surrounding double quotes */ 66 CPLString SQLEscapeName( const char* pszName ); 67 68 /* Remove leading ' or " and unescape in that case. Or return string unmodified */ 69 CPLString SQLUnescape(const char* pszVal); 70 71 char** SQLTokenize( const char* pszSQL ); 72 73 std::set<std::string> SQLGetUniqueFieldUCConstraints(sqlite3* poDb, 74 const char* pszTableName); 75 #endif // OGR_SQLITEUTILITY_H_INCLUDED 76