| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Project: GeoPackage Translator |
| 4 | * Purpose: Implements OGRGeoPackageTableLayer class |
| 5 | * Author: Paul Ramsey <[email protected]> |
| 6 | * |
| 7 | ****************************************************************************** |
| 8 | * Copyright (c) 2013, Paul Ramsey <[email protected]> |
| 9 | * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys.com> |
| 10 | * |
| 11 | * SPDX-License-Identifier: MIT |
| 12 | ****************************************************************************/ |
| 13 | |
| 14 | #include "ogr_geopackage.h"cxx . . $ `<file>/ogr/ogrsf_frmts/gpkg/ogr_geopackage.h`/ |
| 15 | #include "ogrgeopackageutility.h"cxx . . $ `<file>/ogr/ogrsf_frmts/gpkg/ogrgeopackageutility.h`/ |
| 16 | #include "ogrlayerarrow.h"cxx . . $ `<file>/ogr/ogrsf_frmts/generic/ogrlayerarrow.h`/ |
| 17 | #include "ogrsqliteutility.h"cxx . . $ `<file>/ogr/ogrsf_frmts/sqlite/ogrsqliteutility.h`/ |
| 18 | #include "cpl_md5.h"cxx . . $ `<file>/port/cpl_md5.h`/ |
| 19 | #include "cpl_multiproc.h"cxx . . $ `<file>/port/cpl_multiproc.h`/ // CPLSleep() |
| 20 | #include "cpl_time.h"cxx . . $ `<file>/port/cpl_time.h`/ |
| 21 | #include "ogr_p.h"cxx . . $ `<file>/ogr/ogr_p.h`/ |
| 22 | #include "sqlite_rtree_bulk_load/wrapper.h"cxx . . $ `<file>/ogr/ogrsf_frmts/sqlite/sqlite_rtree_bulk_load/wrapper.h`/ |
| 23 | #include "gdal_priv_templates.hpp"cxx . . $ `<file>/gcore/gdal_priv_templates.hpp`/ |
| 24 | |
| 25 | #include <algorithm> |
| 26 | #include <cassert> |
| 27 | #include <cerrno> |
| 28 | #include <cinttypes> |
| 29 | #include <climits> |
| 30 | #include <cmath> |
| 31 | #include <limits> |
| 32 | #include <mutex> |
| 33 | |
| 34 | #undef SQLITE_STATICcxx . . $ `<external>/2400532043262193228/sqlite3.h:6429:9`! |
| 35 | #define SQLITE_STATICcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:35:9`! static_cast<sqlite3_destructor_type>(nullptr) |
| 36 | #undef SQLITE_TRANSIENTcxx . . $ `ogr/ogrsf_frmts/sqlite/ogrsqlitebase.h:25:9`! |
| 37 | #define SQLITE_TRANSIENTcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:37:9`! reinterpret_cast<sqlite3_destructor_type>(-1) |
| 38 | |
| 39 | static const char UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY.[] = |
| 40 | "%s : unsupported operation on a read-only datasource."; |
| 41 | |
| 42 | //---------------------------------------------------------------------- |
| 43 | // SaveExtent() |
| 44 | // |
| 45 | // Write the current contents of the layer envelope down to the |
| 46 | // gpkg_contents metadata table. |
| 47 | // |
| 48 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SaveExtentcxx . . $ OGRGeoPackageTableLayer#SaveExtent(b126dc7c1de90089).() |
| 49 | { |
| 50 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() || !m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. || !m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.) |
| 51 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 52 | |
| 53 | sqlite3 *poDb = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 54 | |
| 55 | if (!poDb) |
| 56 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 57 | |
| 58 | char *pszSQL = |
| 59 | sqlite3_mprintf("UPDATE gpkg_contents SET " |
| 60 | "min_x = %.17g, min_y = %.17g, " |
| 61 | "max_x = %.17g, max_y = %.17g " |
| 62 | "WHERE lower(table_name) = lower('%q') AND " |
| 63 | "Lower(data_type) = 'features'", |
| 64 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinX, m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinY, m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxX, |
| 65 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxY, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 66 | |
| 67 | OGRErr err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(poDb, pszSQL); |
| 68 | sqlite3_free(pszSQL); |
| 69 | m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. = false; |
| 70 | |
| 71 | return err; |
| 72 | } |
| 73 | |
| 74 | //---------------------------------------------------------------------- |
| 75 | // SaveTimestamp() |
| 76 | // |
| 77 | // Update the last_change column of the gpkg_contents metadata table. |
| 78 | // |
| 79 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SaveTimestampcxx . . $ OGRGeoPackageTableLayer#SaveTimestamp(b126dc7c1de90089).() |
| 80 | { |
| 81 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() || !m_bContentChangedcxx . . $ OGRGeoPackageTableLayer#m_bContentChanged.) |
| 82 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 83 | |
| 84 | m_bContentChangedcxx . . $ OGRGeoPackageTableLayer#m_bContentChanged. = false; |
| 85 | |
| 86 | OGRErr err = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->UpdateGpkgContentsLastChangecxx . . $ GDALGeoPackageDataset#UpdateGpkgContentsLastChange(5c4306d8553b3696).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 87 | |
| 88 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 89 | if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. && err == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents. && |
| 90 | !m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled. && m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. >= 0) |
| 91 | { |
| 92 | CPLString osFeatureCount; |
| 93 | osFeatureCount.Printf(CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.); |
| 94 | char *pszSQL = sqlite3_mprintf("UPDATE gpkg_ogr_contents SET " |
| 95 | "feature_count = %s " |
| 96 | "WHERE lower(table_name) = lower('%q')", |
| 97 | osFeatureCount.c_str(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 98 | err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 99 | sqlite3_free(pszSQL); |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | return err; |
| 104 | } |
| 105 | |
| 106 | //---------------------------------------------------------------------- |
| 107 | // UpdateExtent() |
| 108 | // |
| 109 | // Expand the layer envelope if necessary to reflect the bounds |
| 110 | // of new features being added to the layer. |
| 111 | // |
| 112 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::UpdateExtentcxx . . $ OGRGeoPackageTableLayer#UpdateExtent(6720dbbe3ac92137).(const OGREnvelope *poExtent) |
| 113 | { |
| 114 | if (!m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.) |
| 115 | { |
| 116 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. = stdcxx . . $ std/::make_unique<OGREnvelope>(*poExtent); |
| 117 | } |
| 118 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->Merge(*poExtent); |
| 119 | m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. = true; |
| 120 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 121 | } |
| 122 | |
| 123 | //---------------------------------------------------------------------- |
| 124 | // BuildColumns() |
| 125 | // |
| 126 | // Save a list of columns (fid, geometry, attributes) suitable |
| 127 | // for use in a SELECT query that retrieves all fields. |
| 128 | // |
| 129 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::BuildColumnscxx . . $ OGRGeoPackageTableLayer#BuildColumns(b126dc7c1de90089).() |
| 130 | { |
| 131 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 132 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 133 | |
| 134 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 135 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 136 | |
| 137 | m_anFieldOrdinalscxx . . $ OGRGeoPackageLayer#m_anFieldOrdinals..resize(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).()); |
| 138 | int iCurCol = 0; |
| 139 | |
| 140 | /* Always start with a primary key */ |
| 141 | CPLString soColumns; |
| 142 | if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. || m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr) |
| 143 | { |
| 144 | soColumns += "m."; |
| 145 | soColumns += m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. |
| 146 | ? "\"" + SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.) + "\"" |
| 147 | : "_rowid_"; |
| 148 | m_iFIDColcxx . . $ OGRGeoPackageLayer#m_iFIDCol. = iCurCol; |
| 149 | iCurCol++; |
| 150 | } |
| 151 | |
| 152 | /* Add a geometry column if there is one (just one) */ |
| 153 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 154 | { |
| 155 | const auto poFieldDefn = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0); |
| 156 | if (poFieldDefn->IsIgnoredcxx . . $ OGRGeomFieldDefn#IsIgnored(455f465bc33b4cdf).()) |
| 157 | { |
| 158 | m_iGeomColcxx . . $ OGRGeoPackageLayer#m_iGeomCol. = -1; |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | if (!soColumns.empty()) |
| 163 | soColumns += ", "; |
| 164 | soColumns += "m.\""; |
| 165 | soColumns += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 166 | soColumns += "\""; |
| 167 | m_iGeomColcxx . . $ OGRGeoPackageLayer#m_iGeomCol. = iCurCol; |
| 168 | iCurCol++; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /* Add all the attribute columns */ |
| 173 | for (int i = 0; i < m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); i++) |
| 174 | { |
| 175 | const auto poFieldDefn = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(i); |
| 176 | if (poFieldDefn->IsIgnoredcxx . . $ OGRFieldDefn#IsIgnored(455f465bc33b4cdf).()) |
| 177 | { |
| 178 | m_anFieldOrdinalscxx . . $ OGRGeoPackageLayer#m_anFieldOrdinals.[i] = -1; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | if (!soColumns.empty()) |
| 183 | soColumns += ", "; |
| 184 | soColumns += "m.\""; |
| 185 | soColumns += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 186 | soColumns += "\""; |
| 187 | m_anFieldOrdinalscxx . . $ OGRGeoPackageLayer#m_anFieldOrdinals.[i] = iCurCol; |
| 188 | iCurCol++; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if (soColumns.empty()) |
| 193 | { |
| 194 | // Can happen if ignoring all fields on a view... |
| 195 | soColumns = "NULL"; |
| 196 | } |
| 197 | m_soColumnscxx . . $ OGRGeoPackageTableLayer#m_soColumns. = stdcxx . . $ std/::move(soColumns); |
| 198 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 199 | } |
| 200 | |
| 201 | //---------------------------------------------------------------------- |
| 202 | // IsGeomFieldSet() |
| 203 | // |
| 204 | // Utility method to determine if there is a non-Null geometry |
| 205 | // in an OGRGeometry. |
| 206 | // |
| 207 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::IsGeomFieldSetcxx . . $ OGRGeoPackageTableLayer#IsGeomFieldSet(9d38d33a35b5766a).(OGRFeaturecxx . . $ OGRFeature# *poFeature) |
| 208 | { |
| 209 | return poFeature->GetDefnRefcxx . . $ OGRFeature#GetDefnRef(448b209f43d15bcc).()->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() && |
| 210 | poFeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(0); |
| 211 | } |
| 212 | |
| 213 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FeatureBindParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindParameters(9088abe2cac88272).( |
| 214 | OGRFeaturecxx . . $ OGRFeature# *poFeature, sqlite3_stmt *poStmt, int *pnColCount, bool bAddFID, |
| 215 | bool bBindUnsetFields, int nUpdatedFieldsCount, |
| 216 | const int *panUpdatedFieldsIdx, int nUpdatedGeomFieldsCount, |
| 217 | const int * /*panUpdatedGeomFieldsIdx*/) |
| 218 | { |
| 219 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *poFeatureDefn = poFeature->GetDefnRefcxx . . $ OGRFeature#GetDefnRef(448b209f43d15bcc).(); |
| 220 | |
| 221 | int nColCount = 1; |
| 222 | if (bAddFID) |
| 223 | { |
| 224 | int err = sqlite3_bind_int64(poStmt, nColCount++, poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()); |
| 225 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 226 | { |
| 227 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 228 | "sqlite3_bind_int64() failed"); |
| 229 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Bind data values to the statement, here bind the blob for geometry. |
| 234 | // We bind only if there's a geometry column (poFeatureDefn->GetGeomFieldCount() > 0) |
| 235 | // and if we are: |
| 236 | // - either in CreateFeature/SetFeature mode: nUpdatedGeomFieldsCount < 0 |
| 237 | // - or in UpdateFeature mode with nUpdatedGeomFieldsCount == 1, which |
| 238 | // implicitly involves that panUpdatedGeomFieldsIdx[0] == 0, so we don't |
| 239 | // need to test this condition. |
| 240 | if ((nUpdatedGeomFieldsCount < 0 || nUpdatedGeomFieldsCount == 1) && |
| 241 | poFeatureDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 242 | { |
| 243 | // Non-NULL geometry. |
| 244 | OGRGeometrycxx . . $ OGRGeometry# *poGeom = poFeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(0); |
| 245 | if (poGeom) |
| 246 | { |
| 247 | size_t szWkb = 0; |
| 248 | GBytecxx . . $ GByte# *pabyWkb = GPkgGeometryFromOGRcxx . . $ GPkgGeometryFromOGR(2845ec60e18222c7).(poGeom, m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs., |
| 249 | &m_sBinaryPrecisioncxx . . $ OGRGeoPackageTableLayer#m_sBinaryPrecision., &szWkb); |
| 250 | if (!pabyWkb) |
| 251 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 252 | int err = sqlite3_bind_blob(poStmt, nColCount++, pabyWkb, |
| 253 | static_cast<int>(szWkb), CPLFreecxx . . $ `port/cpl_conv.h:97:9`!); |
| 254 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 255 | { |
| 256 | if (err == SQLITE_TOOBIGcxx . . $ `<external>/2400532043262193228/sqlite3.h:468:9`!) |
| 257 | { |
| 258 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 259 | "sqlite3_bind_blob() failed: too big"); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 264 | "sqlite3_bind_blob() failed"); |
| 265 | } |
| 266 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 267 | } |
| 268 | CreateGeometryExtensionIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateGeometryExtensionIfNecessary(e63478674a9dea31).(poGeom); |
| 269 | } |
| 270 | /* NULL geometry */ |
| 271 | else |
| 272 | { |
| 273 | int err = sqlite3_bind_null(poStmt, nColCount++); |
| 274 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 275 | { |
| 276 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 277 | "sqlite3_bind_null() failed"); |
| 278 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /* Bind the attributes using appropriate SQLite data types */ |
| 284 | const int nFieldCount = poFeatureDefn->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); |
| 285 | |
| 286 | size_t nInsertionBufferPos = 0; |
| 287 | if (m_osInsertionBuffercxx . . $ OGRGeoPackageTableLayer#m_osInsertionBuffer..empty()) |
| 288 | m_osInsertionBuffercxx . . $ OGRGeoPackageTableLayer#m_osInsertionBuffer..resize(OGR_SIZEOF_ISO8601_DATETIME_BUFFERcxx . . $ `ogr/ogr_p.h:117:9`! * |
| 289 | nFieldCount); |
| 290 | |
| 291 | for (int idx = 0; |
| 292 | idx < (nUpdatedFieldsCount < 0 ? nFieldCount : nUpdatedFieldsCount); |
| 293 | idx++) |
| 294 | { |
| 295 | const int iField = |
| 296 | nUpdatedFieldsCount < 0 ? idx : panUpdatedFieldsIdx[idx]; |
| 297 | assertcxx . . $ `<external>/4398592474888995393/assert.h:137:11`!(iField >= 0); |
| 298 | const auto &oFieldDefn = poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(iField); |
| 299 | if (iField == m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. || oFieldDefn->IsGeneratedcxx . . $ OGRFieldDefn#IsGenerated(50ce9a9e25b4a850).()) |
| 300 | continue; |
| 301 | if (!poFeature->IsFieldSetUnsafecxx . . $ OGRFeature#IsFieldSetUnsafe(4a668f6de69bf818).(iField)) |
| 302 | { |
| 303 | if (bBindUnsetFields) |
| 304 | { |
| 305 | int err = sqlite3_bind_null(poStmt, nColCount++); |
| 306 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 307 | { |
| 308 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 309 | "sqlite3_bind_null() failed"); |
| 310 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 311 | } |
| 312 | } |
| 313 | continue; |
| 314 | } |
| 315 | |
| 316 | const OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = |
| 317 | poFeatureDefn->GetFieldDefnUnsafecxx . . $ OGRFeatureDefn#GetFieldDefnUnsafe(53a8093e6b73def).(iField); |
| 318 | int err = SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!; |
| 319 | |
| 320 | if (!poFeature->IsFieldNullUnsafecxx . . $ OGRFeature#IsFieldNullUnsafe(4a668f6de69bf818).(iField)) |
| 321 | { |
| 322 | const auto eType = poFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).(); |
| 323 | switch (eType) |
| 324 | { |
| 325 | case OFTInteger: |
| 326 | { |
| 327 | err = sqlite3_bind_int( |
| 328 | poStmt, nColCount++, |
| 329 | poFeature->GetFieldAsIntegerUnsafecxx . . $ OGRFeature#GetFieldAsIntegerUnsafe(7ccb52b1bfe01045).(iField)); |
| 330 | break; |
| 331 | } |
| 332 | case OFTInteger64: |
| 333 | { |
| 334 | err = sqlite3_bind_int64( |
| 335 | poStmt, nColCount++, |
| 336 | poFeature->GetFieldAsInteger64Unsafecxx . . $ OGRFeature#GetFieldAsInteger64Unsafe(f3f16611d465c84c).(iField)); |
| 337 | break; |
| 338 | } |
| 339 | case OFTReal: |
| 340 | { |
| 341 | err = sqlite3_bind_double( |
| 342 | poStmt, nColCount++, |
| 343 | poFeature->GetFieldAsDoubleUnsafecxx . . $ OGRFeature#GetFieldAsDoubleUnsafe(8bbae5fb2e9ef7ac).(iField)); |
| 344 | break; |
| 345 | } |
| 346 | case OFTBinary: |
| 347 | { |
| 348 | int szBlob = 0; |
| 349 | GBytecxx . . $ GByte# *pabyBlob = |
| 350 | poFeature->GetFieldAsBinarycxx . . $ OGRFeature#GetFieldAsBinary(2f4cb8e96649e904).(iField, &szBlob); |
| 351 | err = sqlite3_bind_blob(poStmt, nColCount++, pabyBlob, |
| 352 | szBlob, SQLITE_STATICcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:35:9`!); |
| 353 | break; |
| 354 | } |
| 355 | default: |
| 356 | { |
| 357 | const char *pszVal = ""; |
| 358 | CPL_IGNORE_RET_VAL(pszVal); // Make CSA happy |
| 359 | int nValLengthBytes = -1; |
| 360 | sqlite3_destructor_type destructorType = SQLITE_TRANSIENTcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:37:9`!; |
| 361 | if (eType == OFTDate) |
| 362 | { |
| 363 | destructorType = SQLITE_STATICcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:35:9`!; |
| 364 | const auto psFieldRaw = |
| 365 | poFeature->GetRawFieldRefcxx . . $ OGRFeature#GetRawFieldRef(4f12117e0ec8b5e4).(iField); |
| 366 | char *pszValEdit = |
| 367 | &m_osInsertionBuffercxx . . $ OGRGeoPackageTableLayer#m_osInsertionBuffer.[nInsertionBufferPos]; |
| 368 | pszVal = pszValEdit; |
| 369 | if (psFieldRaw->Date.Year < 0 || |
| 370 | psFieldRaw->Date.Year >= 10000) |
| 371 | { |
| 372 | CPLError( |
| 373 | CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 374 | "OGRGetISO8601DateTime(): year %d unsupported ", |
| 375 | psFieldRaw->Date.Year); |
| 376 | nValLengthBytes = 0; |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | int nYear = psFieldRaw->Date.Year; |
| 381 | pszValEdit[3] = (nYear % 10) + '0'; |
| 382 | nYear /= 10; |
| 383 | pszValEdit[2] = (nYear % 10) + '0'; |
| 384 | nYear /= 10; |
| 385 | pszValEdit[1] = (nYear % 10) + '0'; |
| 386 | nYear /= 10; |
| 387 | pszValEdit[0] = |
| 388 | static_cast<char>(nYear /*% 10*/ + '0'); |
| 389 | pszValEdit[4] = '-'; |
| 390 | pszValEdit[5] = |
| 391 | ((psFieldRaw->Date.Month / 10) % 10) + '0'; |
| 392 | pszValEdit[6] = (psFieldRaw->Date.Month % 10) + '0'; |
| 393 | pszValEdit[7] = '-'; |
| 394 | pszValEdit[8] = |
| 395 | ((psFieldRaw->Date.Day / 10) % 10) + '0'; |
| 396 | pszValEdit[9] = (psFieldRaw->Date.Day % 10) + '0'; |
| 397 | nValLengthBytes = 10; |
| 398 | nInsertionBufferPos += 10; |
| 399 | } |
| 400 | } |
| 401 | else if (eType == OFTDateTime) |
| 402 | { |
| 403 | destructorType = SQLITE_STATICcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:35:9`!; |
| 404 | const auto psFieldRaw = |
| 405 | poFeature->GetRawFieldRefcxx . . $ OGRFeature#GetRawFieldRef(4f12117e0ec8b5e4).(iField); |
| 406 | char *pszValEdit = |
| 407 | &m_osInsertionBuffercxx . . $ OGRGeoPackageTableLayer#m_osInsertionBuffer.[nInsertionBufferPos]; |
| 408 | pszVal = pszValEdit; |
| 409 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bDateTimeWithTZcxx . . $ GDALGeoPackageDataset#m_bDateTimeWithTZ. || |
| 410 | psFieldRaw->Date.TZFlag == 100) |
| 411 | { |
| 412 | nValLengthBytes = OGRGetISO8601DateTimecxx . . $ OGRGetISO8601DateTime(5a5ecae3249419d2).( |
| 413 | psFieldRaw, m_sDateTimeFormatcxx . . $ OGRGeoPackageTableLayer#m_sDateTimeFormat., pszValEdit); |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | OGRField sField(*psFieldRaw); |
| 418 | if (sField.Date.TZFlag == 0 || |
| 419 | sField.Date.TZFlag == 1) |
| 420 | { |
| 421 | sField.Date.TZFlag = 100; |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | struct tmcxx . . $ tm# brokendowntime; |
| 426 | brokendowntime.tm_yearcxx . . $ tm#tm_year. = |
| 427 | sField.Date.Year - 1900; |
| 428 | brokendowntime.tm_moncxx . . $ tm#tm_mon. = sField.Date.Month - 1; |
| 429 | brokendowntime.tm_mdaycxx . . $ tm#tm_mday. = sField.Date.Day; |
| 430 | brokendowntime.tm_hourcxx . . $ tm#tm_hour. = sField.Date.Hour; |
| 431 | brokendowntime.tm_mincxx . . $ tm#tm_min. = sField.Date.Minute; |
| 432 | brokendowntime.tm_seccxx . . $ tm#tm_sec. = 0; |
| 433 | GIntBigcxx . . $ GIntBig# nDT = |
| 434 | CPLYMDHMSToUnixTimecxx . . $ CPLYMDHMSToUnixTime(c2c1c9b2168a19ef).(&brokendowntime); |
| 435 | const int TZOffset = |
| 436 | stdcxx . . $ std/::abs(sField.Date.TZFlag - 100) * 15; |
| 437 | nDT -= TZOffset * 60; |
| 438 | CPLUnixTimeToYMDHMScxx . . $ CPLUnixTimeToYMDHMS(748f025bea3f4c3e).(nDT, &brokendowntime); |
| 439 | sField.Date.Year = static_cast<GInt16cxx . . $ GInt16#>( |
| 440 | brokendowntime.tm_yearcxx . . $ tm#tm_year. + 1900); |
| 441 | sField.Date.Month = static_cast<GBytecxx . . $ GByte#>( |
| 442 | brokendowntime.tm_moncxx . . $ tm#tm_mon. + 1); |
| 443 | sField.Date.Day = |
| 444 | static_cast<GBytecxx . . $ GByte#>(brokendowntime.tm_mdaycxx . . $ tm#tm_mday.); |
| 445 | sField.Date.Hour = |
| 446 | static_cast<GBytecxx . . $ GByte#>(brokendowntime.tm_hourcxx . . $ tm#tm_hour.); |
| 447 | sField.Date.Minute = |
| 448 | static_cast<GBytecxx . . $ GByte#>(brokendowntime.tm_mincxx . . $ tm#tm_min.); |
| 449 | sField.Date.TZFlag = 100; |
| 450 | } |
| 451 | |
| 452 | nValLengthBytes = OGRGetISO8601DateTimecxx . . $ OGRGetISO8601DateTime(5a5ecae3249419d2).( |
| 453 | &sField, m_sDateTimeFormatcxx . . $ OGRGeoPackageTableLayer#m_sDateTimeFormat., pszValEdit); |
| 454 | } |
| 455 | nInsertionBufferPos += nValLengthBytes; |
| 456 | } |
| 457 | else if (eType == OFTString) |
| 458 | { |
| 459 | pszVal = poFeature->GetFieldAsStringUnsafecxx . . $ OGRFeature#GetFieldAsStringUnsafe(afbf07f2bc1a9437).(iField); |
| 460 | if (poFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).() > 0) |
| 461 | { |
| 462 | if (!CPLIsUTF8(pszVal, -1)) |
| 463 | { |
| 464 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 465 | "Value of field '%s' is not a valid " |
| 466 | "UTF-8 string.%s", |
| 467 | poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(iField) |
| 468 | ->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 469 | m_bTruncateFieldscxx . . $ OGRGeoPackageTableLayer#m_bTruncateFields. |
| 470 | ? " Value will be laundered." |
| 471 | : ""); |
| 472 | if (m_bTruncateFieldscxx . . $ OGRGeoPackageTableLayer#m_bTruncateFields.) |
| 473 | { |
| 474 | pszVal = CPLForceToASCII(pszVal, -1, '_'); |
| 475 | destructorType = CPLFreecxx . . $ `port/cpl_conv.h:97:9`!; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (CPLStrlenUTF8Ex(pszVal) > |
| 480 | static_cast<size_t>(poFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).())) |
| 481 | { |
| 482 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 483 | "Value of field '%s' has %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:110:10`! |
| 484 | " characters, " |
| 485 | "whereas maximum allowed is %d.%s", |
| 486 | poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(iField) |
| 487 | ->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 488 | static_cast<uint64_tcxx . . $ uint64_t#>( |
| 489 | CPLStrlenUTF8Ex(pszVal)), |
| 490 | poFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).(), |
| 491 | m_bTruncateFieldscxx . . $ OGRGeoPackageTableLayer#m_bTruncateFields. |
| 492 | ? " Value will be truncated." |
| 493 | : ""); |
| 494 | if (m_bTruncateFieldscxx . . $ OGRGeoPackageTableLayer#m_bTruncateFields.) |
| 495 | { |
| 496 | size_t countUTF8Chars = 0; |
| 497 | nValLengthBytes = 0; |
| 498 | while (pszVal[nValLengthBytes]) |
| 499 | { |
| 500 | if ((pszVal[nValLengthBytes] & 0xc0) != |
| 501 | 0x80) |
| 502 | { |
| 503 | // Stop at the start of the |
| 504 | // character just beyond the maximum |
| 505 | // accepted |
| 506 | if (countUTF8Chars == |
| 507 | static_cast<size_t>( |
| 508 | poFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).())) |
| 509 | { |
| 510 | break; |
| 511 | } |
| 512 | countUTF8Chars++; |
| 513 | } |
| 514 | nValLengthBytes++; |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | else |
| 520 | { |
| 521 | destructorType = SQLITE_STATICcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:35:9`!; |
| 522 | } |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | pszVal = poFeature->GetFieldAsStringcxx . . $ OGRFeature#GetFieldAsString(afbf07f2bc1a9437).(iField); |
| 527 | } |
| 528 | |
| 529 | err = sqlite3_bind_text(poStmt, nColCount++, pszVal, |
| 530 | nValLengthBytes, destructorType); |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | else |
| 536 | { |
| 537 | err = sqlite3_bind_null(poStmt, nColCount++); |
| 538 | } |
| 539 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 540 | { |
| 541 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 542 | "sqlite3_bind_() for column %s failed: %s", |
| 543 | poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 544 | sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).())); |
| 545 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (pnColCount != nullptr) |
| 550 | *pnColCount = nColCount; |
| 551 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 552 | } |
| 553 | |
| 554 | //---------------------------------------------------------------------- |
| 555 | // FeatureBindUpdateParameters() |
| 556 | // |
| 557 | // Selectively bind the values of an OGRFeature to a prepared |
| 558 | // statement, prior to execution. Carefully binds exactly the |
| 559 | // same parameters that have been set up by FeatureGenerateUpdateSQL() |
| 560 | // as bindable. |
| 561 | // |
| 562 | OGRErr |
| 563 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FeatureBindUpdateParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindUpdateParameters(280a200759cc63a1).(OGRFeaturecxx . . $ OGRFeature# *poFeature, |
| 564 | sqlite3_stmt *poStmt) |
| 565 | { |
| 566 | |
| 567 | int nColCount = 0; |
| 568 | const OGRErr err = FeatureBindParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindParameters(9088abe2cac88272).( |
| 569 | poFeature, poStmt, &nColCount, false, false, -1, nullptr, -1, nullptr); |
| 570 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 571 | return err; |
| 572 | |
| 573 | // Bind the FID to the "WHERE" clause. |
| 574 | const int sqlite_err = |
| 575 | sqlite3_bind_int64(poStmt, nColCount, poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()); |
| 576 | if (sqlite_err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 577 | { |
| 578 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 579 | "failed to bind FID '" CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! "' to statement: %s", |
| 580 | poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).(), sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).())); |
| 581 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 582 | } |
| 583 | |
| 584 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 585 | } |
| 586 | |
| 587 | //---------------------------------------------------------------------- |
| 588 | // FeatureBindInsertParameters() |
| 589 | // |
| 590 | // Selectively bind the values of an OGRFeature to a prepared |
| 591 | // statement, prior to execution. Carefully binds exactly the |
| 592 | // same parameters that have been set up by FeatureGenerateInsertSQL() |
| 593 | // as bindable. |
| 594 | // |
| 595 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FeatureBindInsertParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindInsertParameters(17e8baf1e071a650).( |
| 596 | OGRFeaturecxx . . $ OGRFeature# *poFeature, sqlite3_stmt *poStmt, bool bAddFID, |
| 597 | bool bBindUnsetFields) |
| 598 | { |
| 599 | return FeatureBindParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindParameters(9088abe2cac88272).(poFeature, poStmt, nullptr, bAddFID, |
| 600 | bBindUnsetFields, -1, nullptr, -1, nullptr); |
| 601 | } |
| 602 | |
| 603 | //---------------------------------------------------------------------- |
| 604 | // FeatureGenerateInsertSQL() |
| 605 | // |
| 606 | // Build a SQL INSERT statement that references all the columns in |
| 607 | // the OGRFeatureDefn, then prepare it for repeated use in a prepared |
| 608 | // statement. All statements start off with geometry (if it exists) |
| 609 | // then reference each column in the order it appears in the OGRFeatureDefn. |
| 610 | // FeatureBindParameters operates on the expectation of this |
| 611 | // column ordering. |
| 612 | // |
| 613 | CPLString OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FeatureGenerateInsertSQLcxx . . $ OGRGeoPackageTableLayer#FeatureGenerateInsertSQL(778ee83e2d2e6b80).( |
| 614 | OGRFeaturecxx . . $ OGRFeature# *poFeature, bool bAddFID, bool bBindUnsetFields, bool bUpsert, |
| 615 | const stdcxx . . $ std/::string &osUpsertUniqueColumnName) |
| 616 | { |
| 617 | bool bNeedComma = false; |
| 618 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *poFeatureDefn = poFeature->GetDefnRefcxx . . $ OGRFeature#GetDefnRef(448b209f43d15bcc).(); |
| 619 | |
| 620 | if (poFeatureDefn->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).() == |
| 621 | ((m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0) ? 1 : 0) && |
| 622 | poFeatureDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 0 && !bAddFID) |
| 623 | return CPLSPrintf("INSERT INTO \"%s\" DEFAULT VALUES", |
| 624 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str()); |
| 625 | |
| 626 | /* Set up our SQL string basics */ |
| 627 | CPLString osSQLFront("INSERT"); |
| 628 | if (bUpsert && osUpsertUniqueColumnName.empty()) |
| 629 | osSQLFront += " OR REPLACE"; |
| 630 | osSQLFront += |
| 631 | CPLSPrintf(" INTO \"%s\" ( ", SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str()); |
| 632 | |
| 633 | CPLString osSQLBack; |
| 634 | osSQLBack = ") VALUES ("; |
| 635 | |
| 636 | CPLString osSQLColumn; |
| 637 | |
| 638 | if (bAddFID) |
| 639 | { |
| 640 | osSQLColumn.Printf("\"%s\"", SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).()).c_str()); |
| 641 | osSQLFront += osSQLColumn; |
| 642 | osSQLBack += "?"; |
| 643 | bNeedComma = true; |
| 644 | } |
| 645 | |
| 646 | if (poFeatureDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 647 | { |
| 648 | if (bNeedComma) |
| 649 | { |
| 650 | osSQLFront += ", "; |
| 651 | osSQLBack += ", "; |
| 652 | } |
| 653 | |
| 654 | osSQLColumn.Printf( |
| 655 | "\"%s\"", |
| 656 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 657 | .c_str()); |
| 658 | osSQLFront += osSQLColumn; |
| 659 | osSQLBack += "?"; |
| 660 | bNeedComma = true; |
| 661 | } |
| 662 | |
| 663 | /* Add attribute column names (except FID) to the SQL */ |
| 664 | for (int i = 0; i < poFeatureDefn->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); i++) |
| 665 | { |
| 666 | const auto &oFieldDefn = poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(i); |
| 667 | if (i == m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. || oFieldDefn->IsGeneratedcxx . . $ OGRFieldDefn#IsGenerated(50ce9a9e25b4a850).()) |
| 668 | continue; |
| 669 | if (!bBindUnsetFields && !poFeature->IsFieldSetcxx . . $ OGRFeature#IsFieldSet(7ccb52b1bfe01045).(i)) |
| 670 | continue; |
| 671 | |
| 672 | if (!bNeedComma) |
| 673 | { |
| 674 | bNeedComma = true; |
| 675 | } |
| 676 | else |
| 677 | { |
| 678 | osSQLFront += ", "; |
| 679 | osSQLBack += ", "; |
| 680 | } |
| 681 | |
| 682 | osSQLColumn.Printf( |
| 683 | "\"%s\"", |
| 684 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(i)->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 685 | .c_str()); |
| 686 | osSQLFront += osSQLColumn; |
| 687 | osSQLBack += "?"; |
| 688 | } |
| 689 | |
| 690 | osSQLBack += ")"; |
| 691 | |
| 692 | if (!bNeedComma) |
| 693 | return CPLSPrintf("INSERT INTO \"%s\" DEFAULT VALUES", |
| 694 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str()); |
| 695 | |
| 696 | if (bUpsert && !osUpsertUniqueColumnName.empty()) |
| 697 | { |
| 698 | osSQLBack += " ON CONFLICT "; |
| 699 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! < 3035000L |
| 700 | osSQLBack += "(\""; |
| 701 | osSQLBack += SQLEscapeName(osUpsertUniqueColumnName.c_str()); |
| 702 | osSQLBack += "\") "; |
| 703 | #endif |
| 704 | osSQLBack += "DO UPDATE SET "; |
| 705 | bNeedComma = false; |
| 706 | if (poFeatureDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 707 | { |
| 708 | osSQLBack += CPLSPrintf( |
| 709 | "\"%s\" = excluded.\"%s\"", |
| 710 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 711 | .c_str(), |
| 712 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 713 | .c_str()); |
| 714 | bNeedComma = true; |
| 715 | } |
| 716 | for (int i = 0; i < poFeatureDefn->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); i++) |
| 717 | { |
| 718 | if (i == m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.) |
| 719 | continue; |
| 720 | if (!bBindUnsetFields && !poFeature->IsFieldSetcxx . . $ OGRFeature#IsFieldSet(7ccb52b1bfe01045).(i)) |
| 721 | continue; |
| 722 | |
| 723 | if (!bNeedComma) |
| 724 | { |
| 725 | bNeedComma = true; |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | osSQLBack += ", "; |
| 730 | } |
| 731 | |
| 732 | osSQLBack += CPLSPrintf( |
| 733 | "\"%s\" = excluded.\"%s\"", |
| 734 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(i)->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 735 | .c_str(), |
| 736 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(i)->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 737 | .c_str()); |
| 738 | } |
| 739 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3035000L |
| 740 | osSQLBack += " RETURNING \""; |
| 741 | osSQLBack += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).()).c_str(); |
| 742 | osSQLBack += "\""; |
| 743 | #endif |
| 744 | } |
| 745 | |
| 746 | return osSQLFront + osSQLBack; |
| 747 | } |
| 748 | |
| 749 | //---------------------------------------------------------------------- |
| 750 | // FeatureGenerateUpdateSQL() |
| 751 | // |
| 752 | // Build a SQL UPDATE statement that references all the columns in |
| 753 | // the OGRFeatureDefn, then prepare it for repeated use in a prepared |
| 754 | // statement. All statements start off with geometry (if it exists) |
| 755 | // then reference each column in the order it appears in the OGRFeatureDefn. |
| 756 | // FeatureBindParameters operates on the expectation of this |
| 757 | // column ordering. |
| 758 | |
| 759 | // |
| 760 | stdcxx . . $ std/::string OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FeatureGenerateUpdateSQLcxx . . $ OGRGeoPackageTableLayer#FeatureGenerateUpdateSQL(8b7d08ed93ae3f3a).( |
| 761 | const OGRFeaturecxx . . $ OGRFeature# *poFeature) const |
| 762 | { |
| 763 | bool bNeedComma = false; |
| 764 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *poFeatureDefn = poFeature->GetDefnRefcxx . . $ OGRFeature#GetDefnRef(448b209f43d15bcc).(); |
| 765 | |
| 766 | /* Set up our SQL string basics */ |
| 767 | stdcxx . . $ std/::string osUpdate("UPDATE \""); |
| 768 | osUpdate += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 769 | osUpdate += "\" SET "; |
| 770 | |
| 771 | if (poFeatureDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() > 0) |
| 772 | { |
| 773 | osUpdate += '"'; |
| 774 | osUpdate += |
| 775 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 776 | osUpdate += "\"=?"; |
| 777 | bNeedComma = true; |
| 778 | } |
| 779 | |
| 780 | /* Add attribute column names (except FID) to the SQL */ |
| 781 | const int nFieldCount = poFeatureDefn->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); |
| 782 | for (int i = 0; i < nFieldCount; i++) |
| 783 | { |
| 784 | const auto &oFieldDefn = poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(i); |
| 785 | if (i == m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. || oFieldDefn->IsGeneratedcxx . . $ OGRFieldDefn#IsGenerated(50ce9a9e25b4a850).()) |
| 786 | continue; |
| 787 | if (!poFeature->IsFieldSetcxx . . $ OGRFeature#IsFieldSet(7ccb52b1bfe01045).(i)) |
| 788 | continue; |
| 789 | if (!bNeedComma) |
| 790 | bNeedComma = true; |
| 791 | else |
| 792 | osUpdate += ", "; |
| 793 | |
| 794 | osUpdate += '"'; |
| 795 | osUpdate += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(i)->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 796 | osUpdate += "\"=?"; |
| 797 | } |
| 798 | if (!bNeedComma) |
| 799 | return CPLString(); |
| 800 | |
| 801 | osUpdate += " WHERE \""; |
| 802 | osUpdate += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 803 | osUpdate += "\" = ?"; |
| 804 | |
| 805 | return osUpdate; |
| 806 | } |
| 807 | |
| 808 | /************************************************************************/ |
| 809 | /* GetLayerDefn() */ |
| 810 | /************************************************************************/ |
| 811 | |
| 812 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).() const |
| 813 | { |
| 814 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 815 | { |
| 816 | m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted. = true; |
| 817 | const_cast<OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *>(this)->ReadTableDefinitioncxx . . $ OGRGeoPackageTableLayer#ReadTableDefinition(b126dc7c1de90089).(); |
| 818 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->Sealcxx . . $ OGRFeatureDefn#Seal(b45ddcbc8423892c).(/* bSealFields = */ true); |
| 819 | } |
| 820 | return m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.; |
| 821 | } |
| 822 | |
| 823 | /************************************************************************/ |
| 824 | /* GetFIDColumn() */ |
| 825 | /************************************************************************/ |
| 826 | |
| 827 | const char *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).() const |
| 828 | { |
| 829 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 830 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 831 | return OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#::GetFIDColumncxx . . $ OGRGeoPackageLayer#GetFIDColumn(a9f41ea0e82d88cf).(); |
| 832 | } |
| 833 | |
| 834 | /************************************************************************/ |
| 835 | /* GetGeomType() */ |
| 836 | /************************************************************************/ |
| 837 | |
| 838 | OGRwkbGeometryType OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).() const |
| 839 | { |
| 840 | return m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomTypecxx . . $ OGRFeatureDefn#GetGeomType(5a40c54c5ff210ce).(); |
| 841 | } |
| 842 | |
| 843 | /************************************************************************/ |
| 844 | /* GetGeometryColumn() */ |
| 845 | /************************************************************************/ |
| 846 | |
| 847 | const char *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).() const |
| 848 | |
| 849 | { |
| 850 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() > 0) |
| 851 | return m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 852 | else |
| 853 | return ""; |
| 854 | } |
| 855 | |
| 856 | //---------------------------------------------------------------------- |
| 857 | // ReadTableDefinition() |
| 858 | // |
| 859 | // Initialization routine. Read all the metadata about a table, |
| 860 | // starting from just the table name. Reads information from GPKG |
| 861 | // metadata tables and from SQLite table metadata. Uses it to |
| 862 | // populate OGRSpatialReference information and OGRFeatureDefn objects, |
| 863 | // among others. |
| 864 | // |
| 865 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ReadTableDefinitioncxx . . $ OGRGeoPackageTableLayer#ReadTableDefinition(b126dc7c1de90089).() |
| 866 | { |
| 867 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IncrementReadTableDefCountercxx . . $ GDALGeoPackageDataset#IncrementReadTableDefCounter(49f6e7a06ebc5aa8).(); |
| 868 | |
| 869 | bool bReadExtent = false; |
| 870 | sqlite3 *poDb = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 871 | OGREnvelope oExtent; |
| 872 | CPLString osGeomColumnName; |
| 873 | CPLString osGeomColsType; |
| 874 | bool bHasZ = false; |
| 875 | bool bHasM = false; |
| 876 | |
| 877 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 878 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 879 | { |
| 880 | CPLString osTrigger1Name( |
| 881 | CPLSPrintf("trigger_insert_feature_count_%s", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.)); |
| 882 | CPLString osTrigger2Name( |
| 883 | CPLSPrintf("trigger_delete_feature_count_%s", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.)); |
| 884 | const stdcxx . . $ std/::mapcxx . . $ std/map#<CPLString, CPLString> &oMap = |
| 885 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetNameTypeMapFromSQliteMastercxx . . $ GDALGeoPackageDataset#GetNameTypeMapFromSQliteMaster(dc17b9a7c39a0ee5).(); |
| 886 | if (cplcxx . . $ cpl/::contains(oMap, osTrigger1Name.toupper()) && |
| 887 | cplcxx . . $ cpl/::contains(oMap, osTrigger2Name.toupper())) |
| 888 | { |
| 889 | m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled. = true; |
| 890 | } |
| 891 | else if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.) |
| 892 | { |
| 893 | CPLDebug("GPKG", |
| 894 | "Insert/delete feature_count triggers " |
| 895 | "missing on %s", |
| 896 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 897 | } |
| 898 | } |
| 899 | #endif |
| 900 | |
| 901 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 902 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 903 | { |
| 904 | char *pszSQL = sqlite3_mprintf("SELECT feature_count " |
| 905 | "FROM gpkg_ogr_contents " |
| 906 | "WHERE table_name = '%q'" |
| 907 | #ifdef WORKAROUND_SQLITE3_BUGS |
| 908 | " OR 0" |
| 909 | #endif |
| 910 | " LIMIT 2", |
| 911 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 912 | auto oResultFeatureCount = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(poDb, pszSQL); |
| 913 | sqlite3_free(pszSQL); |
| 914 | if (oResultFeatureCount && oResultFeatureCount->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 0) |
| 915 | { |
| 916 | pszSQL = sqlite3_mprintf("SELECT feature_count " |
| 917 | "FROM gpkg_ogr_contents " |
| 918 | "WHERE lower(table_name) = lower('%q')" |
| 919 | #ifdef WORKAROUND_SQLITE3_BUGS |
| 920 | " OR 0" |
| 921 | #endif |
| 922 | " LIMIT 2", |
| 923 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 924 | oResultFeatureCount = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(poDb, pszSQL); |
| 925 | sqlite3_free(pszSQL); |
| 926 | } |
| 927 | |
| 928 | if (oResultFeatureCount && oResultFeatureCount->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 1) |
| 929 | { |
| 930 | const char *pszFeatureCount = oResultFeatureCount->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, 0); |
| 931 | if (pszFeatureCount) |
| 932 | { |
| 933 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = |
| 934 | stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).<GIntBigcxx . . $ GIntBig#>(0, CPLAtoGIntBig(pszFeatureCount)); |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | #endif |
| 939 | |
| 940 | bool bHasPreexistingSingleGeomColumn = |
| 941 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 1; |
| 942 | bool bHasMultipleGeomColsInGpkgGeometryColumns = false; |
| 943 | |
| 944 | if (m_bIsInGpkgContentscxx . . $ OGRGeoPackageTableLayer#m_bIsInGpkgContents.) |
| 945 | { |
| 946 | /* Check that the table name is registered in gpkg_contents */ |
| 947 | const stdcxx . . $ std/::mapcxx . . $ std/map#<CPLString, GPKGContentsDesccxx . . $ GPKGContentsDesc#> &oMapContents = |
| 948 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetContentscxx . . $ GDALGeoPackageDataset#GetContents(412e544c5e4d2cd8).(); |
| 949 | const auto oIterContents = |
| 950 | oMapContents.findcxx . . $ std/map#find(7b3585bb5da8f7d).(CPLString(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).toupper()); |
| 951 | if (oIterContents ==cxx . . $ std/`operator==`(a84eb84a7a5e8237). oMapContents.endcxx . . $ std/map#end(b953fec338ad1a3b).()) |
| 952 | { |
| 953 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 954 | "layer '%s' is not registered in gpkg_contents", |
| 955 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 956 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 957 | } |
| 958 | |
| 959 | const GPKGContentsDesccxx . . $ GPKGContentsDesc# &oContents = oIterContents->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second; |
| 960 | |
| 961 | const char *pszIdentifier = oContents.osIdentifiercxx . . $ GPKGContentsDesc#osIdentifier..c_str(); |
| 962 | if (pszIdentifier[0] != 0 && strcmp(pszIdentifier, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.) != 0) |
| 963 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).("IDENTIFIER", pszIdentifier); |
| 964 | const char *pszDescription = oContents.osDescriptioncxx . . $ GPKGContentsDesc#osDescription..c_str(); |
| 965 | if (pszDescription[0]) |
| 966 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).("DESCRIPTION", pszDescription); |
| 967 | |
| 968 | if (m_bIsSpatialcxx . . $ OGRGeoPackageTableLayer#m_bIsSpatial.) |
| 969 | { |
| 970 | /* All the extrema have to be non-NULL for this to make sense */ |
| 971 | if (!oContents.osMinXcxx . . $ GPKGContentsDesc#osMinX..empty() && !oContents.osMinYcxx . . $ GPKGContentsDesc#osMinY..empty() && |
| 972 | !oContents.osMaxXcxx . . $ GPKGContentsDesc#osMaxX..empty() && !oContents.osMaxYcxx . . $ GPKGContentsDesc#osMaxY..empty()) |
| 973 | { |
| 974 | oExtent.MinX = CPLAtof(oContents.osMinXcxx . . $ GPKGContentsDesc#osMinX.); |
| 975 | oExtent.MinY = CPLAtof(oContents.osMinYcxx . . $ GPKGContentsDesc#osMinY.); |
| 976 | oExtent.MaxX = CPLAtof(oContents.osMaxXcxx . . $ GPKGContentsDesc#osMaxX.); |
| 977 | oExtent.MaxY = CPLAtof(oContents.osMaxYcxx . . $ GPKGContentsDesc#osMaxY.); |
| 978 | bReadExtent = oExtent.MinX <= oExtent.MaxX && |
| 979 | oExtent.MinY <= oExtent.MaxY; |
| 980 | } |
| 981 | |
| 982 | /* Check that the table name is registered in gpkg_geometry_columns |
| 983 | */ |
| 984 | char *pszSQL = sqlite3_mprintf("SELECT table_name, column_name, " |
| 985 | "geometry_type_name, srs_id, z, m " |
| 986 | "FROM gpkg_geometry_columns " |
| 987 | "WHERE table_name = '%q'" |
| 988 | #ifdef WORKAROUND_SQLITE3_BUGS |
| 989 | " OR 0" |
| 990 | #endif |
| 991 | " LIMIT 2000", |
| 992 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 993 | |
| 994 | auto oResultGeomCols = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(poDb, pszSQL); |
| 995 | sqlite3_free(pszSQL); |
| 996 | if (oResultGeomCols && oResultGeomCols->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 0) |
| 997 | { |
| 998 | pszSQL = sqlite3_mprintf("SELECT table_name, column_name, " |
| 999 | "geometry_type_name, srs_id, z, m " |
| 1000 | "FROM gpkg_geometry_columns " |
| 1001 | "WHERE lower(table_name) = lower('%q')" |
| 1002 | #ifdef WORKAROUND_SQLITE3_BUGS |
| 1003 | " OR 0" |
| 1004 | #endif |
| 1005 | " LIMIT 2000", |
| 1006 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1007 | |
| 1008 | oResultGeomCols = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(poDb, pszSQL); |
| 1009 | sqlite3_free(pszSQL); |
| 1010 | } |
| 1011 | |
| 1012 | /* gpkg_geometry_columns query has to work */ |
| 1013 | if (!(oResultGeomCols && oResultGeomCols->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() > 0)) |
| 1014 | { |
| 1015 | CPLError( |
| 1016 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1017 | "layer '%s' is not registered in gpkg_geometry_columns", |
| 1018 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1019 | } |
| 1020 | else |
| 1021 | { |
| 1022 | int iRow = -1; |
| 1023 | bHasMultipleGeomColsInGpkgGeometryColumns = |
| 1024 | oResultGeomCols->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() > 1; |
| 1025 | for (int i = 0; i < oResultGeomCols->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); ++i) |
| 1026 | { |
| 1027 | const char *pszGeomColName = |
| 1028 | oResultGeomCols->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, i); |
| 1029 | if (!pszGeomColName) |
| 1030 | continue; |
| 1031 | if (!bHasPreexistingSingleGeomColumn || |
| 1032 | strcmp(pszGeomColName, |
| 1033 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0) |
| 1034 | ->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) == 0) |
| 1035 | { |
| 1036 | iRow = i; |
| 1037 | break; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | if (iRow >= 0) |
| 1042 | { |
| 1043 | const char *pszGeomColName = |
| 1044 | oResultGeomCols->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, iRow); |
| 1045 | if (pszGeomColName != nullptr) |
| 1046 | osGeomColumnName = pszGeomColName; |
| 1047 | const char *pszGeomColsType = |
| 1048 | oResultGeomCols->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, iRow); |
| 1049 | if (pszGeomColsType != nullptr) |
| 1050 | osGeomColsType = pszGeomColsType; |
| 1051 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = oResultGeomCols->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(3, iRow); |
| 1052 | m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. = oResultGeomCols->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(4, iRow); |
| 1053 | m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag. = oResultGeomCols->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(5, iRow); |
| 1054 | if (!(EQUALcxx . . $ `port/cpl_port.h:532:9`!(osGeomColsType, "GEOMETRY") && m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. == 2)) |
| 1055 | { |
| 1056 | bHasZ = CPL_TO_BOOL(m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag.); |
| 1057 | bHasM = CPL_TO_BOOL(m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag.); |
| 1058 | } |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | CPLError( |
| 1063 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1064 | "Cannot find record for layer '%s' and geometry column " |
| 1065 | "'%s' in gpkg_geometry_columns", |
| 1066 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., |
| 1067 | bHasPreexistingSingleGeomColumn |
| 1068 | ? m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).() |
| 1069 | : "unknown"); |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | // set names (in upper case) of fields with unique constraint |
| 1076 | stdcxx . . $ std/::setcxx . . $ std/set#<stdcxx . . $ std/::string> uniqueFieldsUCcxx . . $ std/set#set(49f6e7a06ebc5aa8).; |
| 1077 | if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.) |
| 1078 | { |
| 1079 | // If resolving the layer definition of a substantial number of tables, |
| 1080 | // fetch in a single time the content of the sqlite_master to increase |
| 1081 | // performance |
| 1082 | // Threshold somewhat arbitrary. If changing it, change |
| 1083 | // ogr_gpkg.py::test_ogr_gpkg_unique_many_layers as well |
| 1084 | constexpr int THRESHOLD_GET_SQLITE_MASTER = 10; |
| 1085 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetReadTableDefCountercxx . . $ GDALGeoPackageDataset#GetReadTableDefCounter(455f465bc33b4cdf).() >= THRESHOLD_GET_SQLITE_MASTER) |
| 1086 | { |
| 1087 | uniqueFieldsUC =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). SQLGetUniqueFieldUCConstraintscxx . . $ SQLGetUniqueFieldUCConstraints(38eb42f8a5771700).( |
| 1088 | poDb, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSqliteMasterContentcxx . . $ GDALGeoPackageDataset#GetSqliteMasterContent(7a5d44db14dca028).()); |
| 1089 | } |
| 1090 | else |
| 1091 | { |
| 1092 | uniqueFieldsUC =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). |
| 1093 | SQLGetUniqueFieldUCConstraintscxx . . $ SQLGetUniqueFieldUCConstraints(38eb42f8a5771700).(poDb, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | /* Use the "PRAGMA TABLE_INFO()" call to get table definition */ |
| 1098 | /* #|name|type|notnull|default|pk */ |
| 1099 | /* 0|id|integer|0||1 */ |
| 1100 | /* 1|name|varchar|0||0 */ |
| 1101 | char *pszSQL = sqlite3_mprintf("pragma table_xinfo('%q')", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1102 | auto oResultTable = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(poDb, pszSQL); |
| 1103 | sqlite3_free(pszSQL); |
| 1104 | |
| 1105 | if (!oResultTable || oResultTable->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 0) |
| 1106 | { |
| 1107 | if (oResultTable) |
| 1108 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Cannot find table %s", |
| 1109 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1110 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1111 | } |
| 1112 | |
| 1113 | /* Populate feature definition from table description */ |
| 1114 | |
| 1115 | // First pass to determine if we have a single PKID column |
| 1116 | int nCountPKIDColumns = 0; |
| 1117 | for (int iRecord = 0; iRecord < oResultTable->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); iRecord++) |
| 1118 | { |
| 1119 | int nPKIDIndex = oResultTable->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(5, iRecord); |
| 1120 | if (nPKIDIndex > 0) |
| 1121 | nCountPKIDColumns++; |
| 1122 | } |
| 1123 | if (nCountPKIDColumns > 1) |
| 1124 | { |
| 1125 | CPLDebug("GPKG", |
| 1126 | "For table %s, multiple columns make " |
| 1127 | "the primary key. Ignoring them", |
| 1128 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1129 | } |
| 1130 | |
| 1131 | for (int iRecord = 0; iRecord < oResultTable->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); iRecord++) |
| 1132 | { |
| 1133 | const char *pszName = oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, iRecord); |
| 1134 | stdcxx . . $ std/::string osType = oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, iRecord); |
| 1135 | int bNotNull = oResultTable->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(3, iRecord); |
| 1136 | const char *pszDefault = oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(4, iRecord); |
| 1137 | int nPKIDIndex = oResultTable->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(5, iRecord); |
| 1138 | int nHiddenValue = oResultTable->GetValueAsIntegercxx . . $ SQLResult#GetValueAsInteger(adc74905ab378dc7).(6, iRecord); |
| 1139 | |
| 1140 | OGRFieldSubType eSubType = OFSTNone; |
| 1141 | int nMaxWidth = 0; |
| 1142 | int nType = OFTMaxType + 1; |
| 1143 | |
| 1144 | // SQLite 3.31 has a " GENERATED ALWAYS" suffix in the type column, |
| 1145 | // but more recent versions no longer have it. |
| 1146 | bool bIsGenerated = false; |
| 1147 | constexpr const char *GENERATED_ALWAYS_SUFFIX = " GENERATED ALWAYS"; |
| 1148 | if (osType.size() > strlen(GENERATED_ALWAYS_SUFFIX) && |
| 1149 | CPLString(osType).toupper().compare( |
| 1150 | osType.size() - strlen(GENERATED_ALWAYS_SUFFIX), |
| 1151 | strlen(GENERATED_ALWAYS_SUFFIX), GENERATED_ALWAYS_SUFFIX) == 0) |
| 1152 | { |
| 1153 | bIsGenerated = true; |
| 1154 | osType.resize(osType.size() - strlen(GENERATED_ALWAYS_SUFFIX)); |
| 1155 | } |
| 1156 | constexpr int GENERATED_VIRTUAL = 2; |
| 1157 | constexpr int GENERATED_STORED = 3; |
| 1158 | if (nHiddenValue == GENERATED_VIRTUAL || |
| 1159 | nHiddenValue == GENERATED_STORED) |
| 1160 | { |
| 1161 | bIsGenerated = true; |
| 1162 | } |
| 1163 | |
| 1164 | if (!osType.empty() || m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.) |
| 1165 | { |
| 1166 | nType = GPkgFieldToOGRcxx . . $ GPkgFieldToOGR(3dfe1c5fd92b9f57).(osType.c_str(), eSubType, nMaxWidth); |
| 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | // For a view, if the geometry column is computed, we don't |
| 1171 | // get a type, so trust the one from gpkg_geometry_columns |
| 1172 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(osGeomColumnName, pszName)) |
| 1173 | { |
| 1174 | osType = osGeomColsType; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | /* Not a standard field type... */ |
| 1179 | if (!osType.empty() && !EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszName, "OGC_FID") && |
| 1180 | ((nType > OFTMaxType && !osGeomColsType.empty()) || |
| 1181 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(osGeomColumnName, pszName))) |
| 1182 | { |
| 1183 | /* Maybe it is a geometry type? */ |
| 1184 | OGRwkbGeometryType oGeomType; |
| 1185 | if (nType > OFTMaxType) |
| 1186 | oGeomType = GPkgGeometryTypeToWKBcxx . . $ GPkgGeometryTypeToWKB(1208cc3a4d5c8a3c).(osType.c_str(), bHasZ, bHasM); |
| 1187 | else |
| 1188 | oGeomType = wkbUnknown; |
| 1189 | if (oGeomType != wkbNone) |
| 1190 | { |
| 1191 | if ((bHasPreexistingSingleGeomColumn && |
| 1192 | (!bHasMultipleGeomColsInGpkgGeometryColumns || |
| 1193 | strcmp(pszName, m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0) |
| 1194 | ->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) == 0)) || |
| 1195 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 0) |
| 1196 | { |
| 1197 | OGRwkbGeometryType oGeomTypeGeomCols = |
| 1198 | GPkgGeometryTypeToWKBcxx . . $ GPkgGeometryTypeToWKB(1208cc3a4d5c8a3c).(osGeomColsType.c_str(), bHasZ, |
| 1199 | bHasM); |
| 1200 | /* Enforce consistency between table and metadata */ |
| 1201 | if (wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(oGeomType) == wkbUnknown) |
| 1202 | oGeomType = oGeomTypeGeomCols; |
| 1203 | if (oGeomType != oGeomTypeGeomCols) |
| 1204 | { |
| 1205 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1206 | "geometry column type for layer '%s' in " |
| 1207 | "'%s.%s' (%s) is not " |
| 1208 | "consistent with type in " |
| 1209 | "gpkg_geometry_columns (%s)", |
| 1210 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszName, |
| 1211 | osType.c_str(), osGeomColsType.c_str()); |
| 1212 | } |
| 1213 | |
| 1214 | if (!bHasPreexistingSingleGeomColumn) |
| 1215 | { |
| 1216 | OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# oGeomFieldcxx . . $ OGRGeomFieldDefn#OGRGeomFieldDefn(465d6c96388e9b45).(pszName, oGeomType); |
| 1217 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->AddGeomFieldDefncxx . . $ OGRFeatureDefn#AddGeomFieldDefn(9997450ff2bf2bb5).(&oGeomField); |
| 1218 | } |
| 1219 | bHasPreexistingSingleGeomColumn = false; |
| 1220 | if (bNotNull) |
| 1221 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->SetNullablecxx . . $ OGRGeomFieldDefn#SetNullable(d4f767463ce0a6b3).( |
| 1222 | FALSEcxx . . $ `port/cpl_port.h:1180:9`!); |
| 1223 | |
| 1224 | /* Read the SRS */ |
| 1225 | auto poSRS = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSpatialRefcxx . . $ GDALGeoPackageDataset#GetSpatialRef(fc1cf25e62fcd527).(m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs.); |
| 1226 | if (poSRS) |
| 1227 | { |
| 1228 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).( |
| 1229 | poSRS.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 1230 | } |
| 1231 | } |
| 1232 | else if (!STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!( |
| 1233 | GetName(), |
| 1234 | (std::string(m_pszTableName) + " (").c_str())) |
| 1235 | { |
| 1236 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1237 | "table '%s' has multiple geometry fields. " |
| 1238 | "Ignoring field '%s' for this layer", |
| 1239 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszName); |
| 1240 | } |
| 1241 | } |
| 1242 | else |
| 1243 | { |
| 1244 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1245 | "geometry column '%s' of type '%s' ignored", pszName, |
| 1246 | osType.c_str()); |
| 1247 | } |
| 1248 | } |
| 1249 | else |
| 1250 | { |
| 1251 | if (nType > OFTMaxType) |
| 1252 | { |
| 1253 | CPLDebug("GPKG", |
| 1254 | "For table %s, unrecognized type name %s for " |
| 1255 | "column %s. Using string type", |
| 1256 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., osType.c_str(), pszName); |
| 1257 | nType = OFTString; |
| 1258 | } |
| 1259 | |
| 1260 | /* Is this the FID column? */ |
| 1261 | if (nPKIDIndex > 0 && nCountPKIDColumns == 1 && |
| 1262 | (nType == OFTInteger || nType == OFTInteger64)) |
| 1263 | { |
| 1264 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. = CPLStrdup(pszName); |
| 1265 | } |
| 1266 | else |
| 1267 | { |
| 1268 | OGRFieldDefncxx . . $ OGRFieldDefn# oFieldcxx . . $ OGRFieldDefn#OGRFieldDefn(786ecb48a0b3b841).(pszName, static_cast<OGRFieldType>(nType)); |
| 1269 | oField.SetSubTypecxx . . $ OGRFieldDefn#SetSubType(89cba9d8fed1b3f9).(eSubType); |
| 1270 | oField.SetWidthcxx . . $ OGRFieldDefn#SetWidth(d4f767463ce0a6b3).(nMaxWidth); |
| 1271 | if (bNotNull) |
| 1272 | oField.SetNullablecxx . . $ OGRFieldDefn#SetNullable(d4f767463ce0a6b3).(FALSEcxx . . $ `port/cpl_port.h:1180:9`!); |
| 1273 | |
| 1274 | if (cplcxx . . $ cpl/::contains(uniqueFieldsUC, CPLString(pszName).toupper())) |
| 1275 | { |
| 1276 | oField.SetUniquecxx . . $ OGRFieldDefn#SetUnique(d4f767463ce0a6b3).(TRUEcxx . . $ `port/cpl_port.h:1184:9`!); |
| 1277 | } |
| 1278 | |
| 1279 | if (pszDefault != nullptr) |
| 1280 | { |
| 1281 | int nYear = 0; |
| 1282 | int nMonth = 0; |
| 1283 | int nDay = 0; |
| 1284 | int nHour = 0; |
| 1285 | int nMinute = 0; |
| 1286 | float fSecond = 0.0f; |
| 1287 | if (oField.GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTString && |
| 1288 | !EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszDefault, "NULL") && |
| 1289 | !STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(pszDefault, "CURRENT_") && |
| 1290 | pszDefault[0] != '(' && pszDefault[0] != '\'' && |
| 1291 | CPLGetValueType(pszDefault) == CPL_VALUE_STRING) |
| 1292 | { |
| 1293 | CPLString osDefault("'"); |
| 1294 | char *pszTmp = |
| 1295 | CPLEscapeString(pszDefault, -1, CPLES_SQLcxx . . $ `port/cpl_string.h:159:9`!); |
| 1296 | osDefault += pszTmp; |
| 1297 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszTmp); |
| 1298 | osDefault += "'"; |
| 1299 | oField.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).(osDefault); |
| 1300 | } |
| 1301 | else if (nType == OFTDateTime && |
| 1302 | sscanf(pszDefault, "'%d-%d-%dT%d:%d:%fZ'", &nYear, |
| 1303 | &nMonth, &nDay, &nHour, &nMinute, |
| 1304 | &fSecond) == 6) |
| 1305 | { |
| 1306 | if (strchr(pszDefault, '.') == nullptr) |
| 1307 | oField.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).( |
| 1308 | CPLSPrintf("'%04d/%02d/%02d %02d:%02d:%02d'", |
| 1309 | nYear, nMonth, nDay, nHour, nMinute, |
| 1310 | static_cast<int>(fSecond + 0.5))); |
| 1311 | else |
| 1312 | oField.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).(CPLSPrintf( |
| 1313 | "'%04d/%02d/%02d %02d:%02d:%06.3f'", nYear, |
| 1314 | nMonth, nDay, nHour, nMinute, fSecond)); |
| 1315 | } |
| 1316 | else if ((oField.GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTDate || |
| 1317 | oField.GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTDateTime) && |
| 1318 | !EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszDefault, "NULL") && |
| 1319 | !STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(pszDefault, "CURRENT_") && |
| 1320 | pszDefault[0] != '(' && pszDefault[0] != '\'' && |
| 1321 | !(pszDefault[0] >= '0' && pszDefault[0] <= '9') && |
| 1322 | CPLGetValueType(pszDefault) == CPL_VALUE_STRING) |
| 1323 | { |
| 1324 | CPLString osDefault("("); |
| 1325 | osDefault += pszDefault; |
| 1326 | osDefault += ")"; |
| 1327 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(osDefault, |
| 1328 | "(strftime('%Y-%m-%dT%H:%M:%fZ','now'))")) |
| 1329 | oField.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).("CURRENT_TIMESTAMP"); |
| 1330 | else |
| 1331 | oField.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).(osDefault); |
| 1332 | } |
| 1333 | else |
| 1334 | { |
| 1335 | oField.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).(pszDefault); |
| 1336 | } |
| 1337 | } |
| 1338 | oField.SetGeneratedcxx . . $ OGRFieldDefn#SetGenerated(b45ddcbc8423892c).(bIsGenerated); |
| 1339 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->AddFieldDefncxx . . $ OGRFeatureDefn#AddFieldDefn(f8bad7d30df65bbb).(&oField); |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /* Wait, we didn't find a FID? Some operations will not be possible */ |
| 1345 | if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. && m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr) |
| 1346 | { |
| 1347 | CPLDebug("GPKG", "no integer primary key defined for table '%s'", |
| 1348 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1349 | } |
| 1350 | |
| 1351 | if (bReadExtent) |
| 1352 | { |
| 1353 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. = stdcxx . . $ std/::make_unique<OGREnvelope>(oExtent); |
| 1354 | } |
| 1355 | |
| 1356 | // Look for sub-types such as JSON |
| 1357 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasDataColumnsTablecxx . . $ GDALGeoPackageDataset#HasDataColumnsTable(50ce9a9e25b4a850).()) |
| 1358 | { |
| 1359 | pszSQL = sqlite3_mprintf( |
| 1360 | "SELECT column_name, name, mime_type, " |
| 1361 | "constraint_name, description FROM gpkg_data_columns " |
| 1362 | "WHERE table_name = '%q'", |
| 1363 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1364 | oResultTable = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(poDb, pszSQL); |
| 1365 | sqlite3_free(pszSQL); |
| 1366 | if (oResultTable) |
| 1367 | { |
| 1368 | for (int iRecord = 0; iRecord < oResultTable->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); iRecord++) |
| 1369 | { |
| 1370 | const char *pszColumn = oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, iRecord); |
| 1371 | if (pszColumn == nullptr) |
| 1372 | continue; |
| 1373 | const char *pszName = oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, iRecord); |
| 1374 | |
| 1375 | // We use the "name" attribute from gpkg_data_columns as the |
| 1376 | // field alternative name, so long as it isn't just a copy |
| 1377 | // of the column name |
| 1378 | const char *pszAlias = nullptr; |
| 1379 | if (pszName && !EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszName, pszColumn)) |
| 1380 | pszAlias = pszName; |
| 1381 | |
| 1382 | if (pszAlias) |
| 1383 | { |
| 1384 | const int iIdx = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(pszColumn); |
| 1385 | if (iIdx >= 0) |
| 1386 | { |
| 1387 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iIdx)->SetAlternativeNamecxx . . $ OGRFieldDefn#SetAlternativeName(85c52e162fed56f9).( |
| 1388 | pszAlias); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | if (const char *pszDescription = |
| 1393 | oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(4, iRecord)) |
| 1394 | { |
| 1395 | const int iIdx = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(pszColumn); |
| 1396 | if (iIdx >= 0) |
| 1397 | { |
| 1398 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iIdx)->SetCommentcxx . . $ OGRFieldDefn#SetComment(9c546c94e5fcce4e).( |
| 1399 | pszDescription); |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | const char *pszMimeType = oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, iRecord); |
| 1404 | const char *pszConstraintName = |
| 1405 | oResultTable->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(3, iRecord); |
| 1406 | if (pszMimeType && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMimeType, "application/json")) |
| 1407 | { |
| 1408 | const int iIdx = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(pszColumn); |
| 1409 | if (iIdx >= 0 && |
| 1410 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iIdx)->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == |
| 1411 | OFTString) |
| 1412 | { |
| 1413 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iIdx)->SetSubTypecxx . . $ OGRFieldDefn#SetSubType(89cba9d8fed1b3f9).( |
| 1414 | OFSTJSON); |
| 1415 | } |
| 1416 | } |
| 1417 | else if (pszConstraintName) |
| 1418 | { |
| 1419 | const int iIdx = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(pszColumn); |
| 1420 | if (iIdx >= 0) |
| 1421 | { |
| 1422 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iIdx)->SetDomainNamecxx . . $ OGRFieldDefn#SetDomainName(9c546c94e5fcce4e).( |
| 1423 | pszConstraintName); |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | // Look for geometry column coordinate precision in gpkg_metadata |
| 1431 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasMetadataTablescxx . . $ GDALGeoPackageDataset#HasMetadataTables(50ce9a9e25b4a850).() && m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() > 0) |
| 1432 | { |
| 1433 | pszSQL = sqlite3_mprintf( |
| 1434 | "SELECT md.metadata, mdr.column_name " |
| 1435 | "FROM gpkg_metadata md " |
| 1436 | "JOIN gpkg_metadata_reference mdr ON (md.id = mdr.md_file_id) " |
| 1437 | "WHERE lower(mdr.table_name) = lower('%q') " |
| 1438 | "AND md.md_standard_uri = 'http://gdal.org' " |
| 1439 | "AND md.mime_type = 'text/xml' " |
| 1440 | "AND mdr.reference_scope = 'column' " |
| 1441 | "AND md.metadata LIKE '<CoordinatePrecision%%' " |
| 1442 | "ORDER BY md.id LIMIT 1000", // to avoid denial of service |
| 1443 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1444 | |
| 1445 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 1446 | sqlite3_free(pszSQL); |
| 1447 | |
| 1448 | for (int i = 0; oResult && i < oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); i++) |
| 1449 | { |
| 1450 | const char *pszMetadata = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, i); |
| 1451 | const char *pszColumn = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, i); |
| 1452 | if (pszMetadata && pszColumn) |
| 1453 | { |
| 1454 | const int iGeomCol = |
| 1455 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldIndexcxx . . $ OGRFeatureDefn#GetGeomFieldIndex(78f035161ffa9fe2).(pszColumn); |
| 1456 | if (iGeomCol >= 0) |
| 1457 | { |
| 1458 | auto psXMLNode = |
| 1459 | CPLXMLTreeCloser(CPLParseXMLString(pszMetadata)); |
| 1460 | if (psXMLNode) |
| 1461 | { |
| 1462 | OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision# sCoordPrec; |
| 1463 | if (const char *pszVal = CPLGetXMLValue( |
| 1464 | psXMLNode.get(), "xy_resolution", nullptr)) |
| 1465 | { |
| 1466 | sCoordPrec.dfXYResolutioncxx . . $ OGRGeomCoordinatePrecision#dfXYResolution. = CPLAtof(pszVal); |
| 1467 | } |
| 1468 | if (const char *pszVal = CPLGetXMLValue( |
| 1469 | psXMLNode.get(), "z_resolution", nullptr)) |
| 1470 | { |
| 1471 | sCoordPrec.dfZResolutioncxx . . $ OGRGeomCoordinatePrecision#dfZResolution. = CPLAtof(pszVal); |
| 1472 | } |
| 1473 | if (const char *pszVal = CPLGetXMLValue( |
| 1474 | psXMLNode.get(), "m_resolution", nullptr)) |
| 1475 | { |
| 1476 | sCoordPrec.dfMResolutioncxx . . $ OGRGeomCoordinatePrecision#dfMResolution. = CPLAtof(pszVal); |
| 1477 | } |
| 1478 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(iGeomCol) |
| 1479 | ->SetCoordinatePrecisioncxx . . $ OGRGeomFieldDefn#SetCoordinatePrecision(a66dcf8fa4d01368).(sCoordPrec); |
| 1480 | if (CPLTestBool(CPLGetXMLValue( |
| 1481 | psXMLNode.get(), "discard_coord_lsb", "false"))) |
| 1482 | { |
| 1483 | m_sBinaryPrecisioncxx . . $ OGRGeoPackageTableLayer#m_sBinaryPrecision..SetFromcxx . . $ OGRGeomCoordinateBinaryPrecision#SetFrom(a66dcf8fa4d01368).(sCoordPrec); |
| 1484 | m_bUndoDiscardCoordLSBOnReadingcxx . . $ OGRGeoPackageLayer#m_bUndoDiscardCoordLSBOnReading. = |
| 1485 | CPLTestBool(CPLGetXMLValue( |
| 1486 | psXMLNode.get(), |
| 1487 | "undo_discard_coord_lsb_on_reading", |
| 1488 | "false")); |
| 1489 | } |
| 1490 | } |
| 1491 | } |
| 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | /* Update the columns string */ |
| 1497 | BuildColumnscxx . . $ OGRGeoPackageTableLayer#BuildColumns(b126dc7c1de90089).(); |
| 1498 | |
| 1499 | CheckUnknownExtensionscxx . . $ OGRGeoPackageTableLayer#CheckUnknownExtensions(49f6e7a06ebc5aa8).(); |
| 1500 | |
| 1501 | InitViewcxx . . $ OGRGeoPackageTableLayer#InitView(49f6e7a06ebc5aa8).(); |
| 1502 | |
| 1503 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 1504 | } |
| 1505 | |
| 1506 | /************************************************************************/ |
| 1507 | /* OGRGeoPackageTableLayer() */ |
| 1508 | /************************************************************************/ |
| 1509 | |
| 1510 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#OGRGeoPackageTableLayer(def90c2c0bbf0ba5).(GDALGeoPackageDatasetcxx . . $ GDALGeoPackageDataset# *poDS, |
| 1511 | const char *pszTableName) |
| 1512 | : OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#OGRGeoPackageLayer(708af067f9bb9c4a).(poDS), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.(CPLStrdup(pszTableName)) |
| 1513 | { |
| 1514 | memset(m_abHasGeometryExtensioncxx . . $ OGRGeoPackageTableLayer#m_abHasGeometryExtension., 0, sizeof(m_abHasGeometryExtensioncxx . . $ OGRGeoPackageTableLayer#m_abHasGeometryExtension.)); |
| 1515 | |
| 1516 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn. = new OGRFeatureDefncxx . . $ OGRFeatureDefn#(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1517 | SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).()); |
| 1518 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->SetGeomTypecxx . . $ OGRFeatureDefn#SetGeomType(f47ce3f1fe923726).(wkbNone); |
| 1519 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->Referencecxx . . $ OGRFeatureDefn#Reference(b126dc7c1de90089).(); |
| 1520 | } |
| 1521 | |
| 1522 | /************************************************************************/ |
| 1523 | /* ~OGRGeoPackageTableLayer() */ |
| 1524 | /************************************************************************/ |
| 1525 | |
| 1526 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::~cxx . . $ OGRGeoPackageTableLayer#`~OGRGeoPackageTableLayer`(ced63f7c635d850d).OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#() |
| 1527 | { |
| 1528 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SyncToDiskcxx . . $ OGRGeoPackageTableLayer#SyncToDisk(b126dc7c1de90089).(); |
| 1529 | |
| 1530 | /* Clean up resources in memory */ |
| 1531 | if (m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.) |
| 1532 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1533 | |
| 1534 | if (m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.) |
| 1535 | sqlite3_finalize(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 1536 | |
| 1537 | if (m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.) |
| 1538 | sqlite3_finalize(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 1539 | |
| 1540 | if (m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.) |
| 1541 | sqlite3_finalize(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 1542 | |
| 1543 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 1544 | } |
| 1545 | |
| 1546 | /************************************************************************/ |
| 1547 | /* CancelAsyncNextArrowArray() */ |
| 1548 | /************************************************************************/ |
| 1549 | |
| 1550 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).() |
| 1551 | { |
| 1552 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.) |
| 1553 | { |
| 1554 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 1555 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. = -1; |
| 1556 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oCVcxx . . $ OGRGPKGTableLayerFillArrowArray#oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 1557 | } |
| 1558 | |
| 1559 | if (m_oThreadNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_oThreadNextArrowArray..joinablecxx . . $ std/thread#joinable(3482b152b9333168).()) |
| 1560 | { |
| 1561 | m_oThreadNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_oThreadNextArrowArray..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 1562 | } |
| 1563 | |
| 1564 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray..reset(); |
| 1565 | |
| 1566 | while (!m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..emptycxx . . $ std/queue#empty(50ce9a9e25b4a850).()) |
| 1567 | { |
| 1568 | auto task = stdcxx . . $ std/::move(m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..frontcxx . . $ std/queue#front(d8c1a3bbdff15733).()); |
| 1569 | m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..popcxx . . $ std/queue#pop(49f6e7a06ebc5aa8).(); |
| 1570 | |
| 1571 | { |
| 1572 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(task->m_oMutexcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oMutex.); |
| 1573 | task->m_bStopcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bStop. = true; |
| 1574 | task->m_oCVcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 1575 | } |
| 1576 | if (task->m_oThreadcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oThread..joinablecxx . . $ std/thread#joinable(3482b152b9333168).()) |
| 1577 | task->m_oThreadcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oThread..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 1578 | |
| 1579 | if (task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.) |
| 1580 | { |
| 1581 | if (task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.->release) |
| 1582 | task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.->release(task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray..get()); |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | /************************************************************************/ |
| 1588 | /* InitView() */ |
| 1589 | /************************************************************************/ |
| 1590 | |
| 1591 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::InitViewcxx . . $ OGRGeoPackageTableLayer#InitView(49f6e7a06ebc5aa8).() |
| 1592 | { |
| 1593 | #ifdef SQLITE_HAS_COLUMN_METADATAcxx . . $ `<built-in>:488:9`! |
| 1594 | if (!m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.) |
| 1595 | { |
| 1596 | /* Detect if the view columns have the FID and geom columns of a */ |
| 1597 | /* table that has itself a spatial index */ |
| 1598 | sqlite3_stmt *hStmt = nullptr; |
| 1599 | char *pszSQL = sqlite3_mprintf("SELECT * FROM \"%w\"", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1600 | CPL_IGNORE_RET_VAL( |
| 1601 | sqlite3_prepare_v2(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, -1, &hStmt, nullptr)); |
| 1602 | sqlite3_free(pszSQL); |
| 1603 | if (hStmt) |
| 1604 | { |
| 1605 | if (sqlite3_step(hStmt) == SQLITE_ROWcxx . . $ `<external>/2400532043262193228/sqlite3.h:479:9`!) |
| 1606 | { |
| 1607 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *poLayerGeom = nullptr; |
| 1608 | const int nRawColumns = sqlite3_column_count(hStmt); |
| 1609 | for (int iCol = 0; iCol < nRawColumns; iCol++) |
| 1610 | { |
| 1611 | CPLString osColName( |
| 1612 | SQLUnescapecxx . . $ SQLUnescape(a9d72c988d85d6d8).(sqlite3_column_name(hStmt, iCol))); |
| 1613 | const char *pszTableName = |
| 1614 | sqlite3_column_table_name(hStmt, iCol); |
| 1615 | const char *pszOriginName = |
| 1616 | sqlite3_column_origin_name(hStmt, iCol); |
| 1617 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(osColName, "OGC_FID") && |
| 1618 | (pszOriginName == nullptr || |
| 1619 | osColName != pszOriginName)) |
| 1620 | { |
| 1621 | // in the case we have a OGC_FID column, and that |
| 1622 | // is not the name of the original column, then |
| 1623 | // interpret this as an explicit intent to be a |
| 1624 | // PKID. |
| 1625 | // We cannot just take the FID of a source table as |
| 1626 | // a FID because of potential joins that would result |
| 1627 | // in multiple records with same source FID. |
| 1628 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 1629 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. = CPLStrdup(osColName); |
| 1630 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->DeleteFieldDefncxx . . $ OGRFeatureDefn#DeleteFieldDefn(7864480464b09eea).( |
| 1631 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(osColName)); |
| 1632 | } |
| 1633 | else if (iCol == 0 && |
| 1634 | sqlite3_column_type(hStmt, iCol) == SQLITE_INTEGERcxx . . $ `<external>/2400532043262193228/sqlite3.h:5356:9`!) |
| 1635 | { |
| 1636 | // Assume the first column of integer type is the FID |
| 1637 | // column per the latest requirements of the GPKG spec |
| 1638 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 1639 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. = CPLStrdup(osColName); |
| 1640 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->DeleteFieldDefncxx . . $ OGRFeatureDefn#DeleteFieldDefn(7864480464b09eea).( |
| 1641 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(osColName)); |
| 1642 | } |
| 1643 | else if (pszTableName != nullptr && |
| 1644 | pszOriginName != nullptr) |
| 1645 | { |
| 1646 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *poLayer = |
| 1647 | dynamic_cast<OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *>( |
| 1648 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetLayerByNamecxx . . $ GDALDataset#GetLayerByName(5ddf27af0841fa5b).(pszTableName)); |
| 1649 | if (poLayer != nullptr && |
| 1650 | osColName == GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).() && |
| 1651 | strcmp(pszOriginName, |
| 1652 | poLayer->GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).()) == 0) |
| 1653 | { |
| 1654 | poLayerGeom = poLayer; |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | if (poLayerGeom != nullptr && poLayerGeom->HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 1660 | { |
| 1661 | for (int iCol = 0; iCol < nRawColumns; iCol++) |
| 1662 | { |
| 1663 | const stdcxx . . $ std/::string osColName( |
| 1664 | SQLUnescapecxx . . $ SQLUnescape(a9d72c988d85d6d8).(sqlite3_column_name(hStmt, iCol))); |
| 1665 | const char *pszTableName = |
| 1666 | sqlite3_column_table_name(hStmt, iCol); |
| 1667 | const char *pszOriginName = |
| 1668 | sqlite3_column_origin_name(hStmt, iCol); |
| 1669 | if (pszTableName != nullptr && pszOriginName != nullptr) |
| 1670 | { |
| 1671 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *poLayer = |
| 1672 | dynamic_cast<OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *>( |
| 1673 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetLayerByNamecxx . . $ GDALDataset#GetLayerByName(5ddf27af0841fa5b).(pszTableName)); |
| 1674 | if (poLayer != nullptr && poLayer == poLayerGeom && |
| 1675 | strcmp(pszOriginName, |
| 1676 | poLayer->GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).()) == 0) |
| 1677 | { |
| 1678 | m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. = true; |
| 1679 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = poLayerGeom->m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.; |
| 1680 | m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree. = osColName; |
| 1681 | break; |
| 1682 | } |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | sqlite3_finalize(hStmt); |
| 1688 | } |
| 1689 | |
| 1690 | /* Update the columns string */ |
| 1691 | BuildColumnscxx . . $ OGRGeoPackageTableLayer#BuildColumns(b126dc7c1de90089).(); |
| 1692 | } |
| 1693 | #endif |
| 1694 | } |
| 1695 | |
| 1696 | /************************************************************************/ |
| 1697 | /* CheckUpdatableTable() */ |
| 1698 | /************************************************************************/ |
| 1699 | |
| 1700 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).(const char *pszOperation) |
| 1701 | { |
| 1702 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).()) |
| 1703 | { |
| 1704 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY., |
| 1705 | pszOperation); |
| 1706 | return false; |
| 1707 | } |
| 1708 | /* -------------------------------------------------------------------- */ |
| 1709 | /* Check that is a table and not a view */ |
| 1710 | /* -------------------------------------------------------------------- */ |
| 1711 | if (!m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.) |
| 1712 | { |
| 1713 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Layer %s is not a table", |
| 1714 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 1715 | return false; |
| 1716 | } |
| 1717 | return true; |
| 1718 | } |
| 1719 | |
| 1720 | /************************************************************************/ |
| 1721 | /* CreateField() */ |
| 1722 | /************************************************************************/ |
| 1723 | |
| 1724 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateFieldcxx . . $ OGRGeoPackageTableLayer#CreateField(2cf5282e6e90de1e).(const OGRFieldDefncxx . . $ OGRFieldDefn# *poField, |
| 1725 | int /* bApproxOK */) |
| 1726 | { |
| 1727 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 1728 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 1729 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("CreateField")) |
| 1730 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1731 | |
| 1732 | OGRFieldDefncxx . . $ OGRFieldDefn# oFieldDefncxx . . $ OGRFieldDefn#OGRFieldDefn(f8bad7d30df65bbb).(poField); |
| 1733 | int nMaxWidth = 0; |
| 1734 | if (m_bPreservePrecisioncxx . . $ OGRGeoPackageTableLayer#m_bPreservePrecision. && poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTString) |
| 1735 | nMaxWidth = poField->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).(); |
| 1736 | else |
| 1737 | oFieldDefn.SetWidthcxx . . $ OGRFieldDefn#SetWidth(d4f767463ce0a6b3).(0); |
| 1738 | oFieldDefn.SetPrecisioncxx . . $ OGRFieldDefn#SetPrecision(d4f767463ce0a6b3).(0); |
| 1739 | |
| 1740 | if (m_bLaundercxx . . $ OGRGeoPackageTableLayer#m_bLaunder.) |
| 1741 | oFieldDefn.SetNamecxx . . $ OGRFieldDefn#SetName(85c52e162fed56f9).( |
| 1742 | GDALGeoPackageDatasetcxx . . $ GDALGeoPackageDataset#::LaunderNamecxx . . $ GDALGeoPackageDataset#LaunderName(fd626fc03107dd24).(oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 1743 | .c_str()); |
| 1744 | |
| 1745 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) >= 0) |
| 1746 | { |
| 1747 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1748 | "Cannot create field %s. " |
| 1749 | "A field with the same name already exists.", |
| 1750 | oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 1751 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1752 | } |
| 1753 | |
| 1754 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldIndexcxx . . $ OGRFeatureDefn#GetGeomFieldIndex(78f035161ffa9fe2).(oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) >= 0) |
| 1755 | { |
| 1756 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1757 | "Cannot create field %s. " |
| 1758 | "It has the same name as the geometry field.", |
| 1759 | oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 1760 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1761 | } |
| 1762 | |
| 1763 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr && |
| 1764 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(oFieldDefn.GetNameRef(), m_pszFidColumn) && |
| 1765 | poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() != OFTInteger && |
| 1766 | poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() != OFTInteger64 && |
| 1767 | // typically a GeoPackage exported with QGIS as a shapefile and |
| 1768 | // re-imported See https://github.com/qgis/QGIS/pull/43118 |
| 1769 | !(poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTReal && poField->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).() == 20 && |
| 1770 | poField->GetPrecisioncxx . . $ OGRFieldDefn#GetPrecision(455f465bc33b4cdf).() == 0)) |
| 1771 | { |
| 1772 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Wrong field type for %s", |
| 1773 | oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 1774 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1775 | } |
| 1776 | |
| 1777 | const int nMaxColumns = |
| 1778 | sqlite3_limit(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), SQLITE_LIMIT_COLUMNcxx . . $ `<external>/2400532043262193228/sqlite3.h:4411:9`!, -1); |
| 1779 | // + 1 for the FID column |
| 1780 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).() + |
| 1781 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() + 1 >= |
| 1782 | nMaxColumns) |
| 1783 | { |
| 1784 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1785 | "Cannot add field %s. Limit of %d columns reached", |
| 1786 | oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), nMaxColumns); |
| 1787 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1788 | } |
| 1789 | |
| 1790 | if (!m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation.) |
| 1791 | { |
| 1792 | CPLString osCommand; |
| 1793 | |
| 1794 | // ADD COLUMN has several restrictions |
| 1795 | // See https://www.sqlite.org/lang_altertable.html#altertabaddcol |
| 1796 | |
| 1797 | osCommand.Printf("ALTER TABLE \"%s\" ADD COLUMN \"%s\" %s", |
| 1798 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 1799 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(oFieldDefn.GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 1800 | GPkgFieldFromOGRcxx . . $ GPkgFieldFromOGR(d1570bcf2edf7d6a).(poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).(), |
| 1801 | poField->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).(), nMaxWidth)); |
| 1802 | if (!poField->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).()) |
| 1803 | osCommand += " NOT NULL"; |
| 1804 | if (poField->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).()) |
| 1805 | { |
| 1806 | // this will fail when SQLCommand() is run, as it is not allowed |
| 1807 | // by SQLite. This is a bit of an artificial restriction. |
| 1808 | // We could override it by rewriting the table. |
| 1809 | osCommand += " UNIQUE"; |
| 1810 | } |
| 1811 | if (poField->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).() != nullptr && |
| 1812 | !poField->IsDefaultDriverSpecificcxx . . $ OGRFieldDefn#IsDefaultDriverSpecific(455f465bc33b4cdf).()) |
| 1813 | { |
| 1814 | osCommand += " DEFAULT "; |
| 1815 | int nYear = 0; |
| 1816 | int nMonth = 0; |
| 1817 | int nDay = 0; |
| 1818 | int nHour = 0; |
| 1819 | int nMinute = 0; |
| 1820 | float fSecond = 0.0f; |
| 1821 | if (poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTDateTime && |
| 1822 | sscanf(poField->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(), "'%d/%d/%d %d:%d:%f'", &nYear, |
| 1823 | &nMonth, &nDay, &nHour, &nMinute, &fSecond) == 6) |
| 1824 | { |
| 1825 | if (strchr(poField->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(), '.') == nullptr) |
| 1826 | osCommand += CPLSPrintf("'%04d-%02d-%02dT%02d:%02d:%02dZ'", |
| 1827 | nYear, nMonth, nDay, nHour, nMinute, |
| 1828 | static_cast<int>(fSecond + 0.5)); |
| 1829 | else |
| 1830 | osCommand += |
| 1831 | CPLSPrintf("'%04d-%02d-%02dT%02d:%02d:%06.3fZ'", nYear, |
| 1832 | nMonth, nDay, nHour, nMinute, fSecond); |
| 1833 | } |
| 1834 | else |
| 1835 | { |
| 1836 | // This could fail if it is CURRENT_TIMESTAMP, etc. |
| 1837 | osCommand += poField->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(); |
| 1838 | } |
| 1839 | } |
| 1840 | else if (!poField->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).()) |
| 1841 | { |
| 1842 | // SQLite mandates a DEFAULT value when adding a NOT NULL column in |
| 1843 | // an ALTER TABLE ADD COLUMN. |
| 1844 | osCommand += " DEFAULT ''"; |
| 1845 | } |
| 1846 | |
| 1847 | OGRErr err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osCommand.c_str()); |
| 1848 | |
| 1849 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 1850 | return err; |
| 1851 | |
| 1852 | if (!DoSpecialProcessingForColumnCreationcxx . . $ OGRGeoPackageTableLayer#DoSpecialProcessingForColumnCreation(6ac7e7c63d694732).(poField)) |
| 1853 | { |
| 1854 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | whileUnsealingcxx . . $ whileUnsealing(de07598ec200be45).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.)->cxx . . $ OGRFeatureDefn#TemporaryUnsealer#`operator->`(407fccde18759965).AddFieldDefncxx . . $ OGRFeatureDefn#AddFieldDefn(f8bad7d30df65bbb).(&oFieldDefn); |
| 1859 | |
| 1860 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).()) |
| 1861 | { |
| 1862 | m_apoFieldDefnChangescxx . . $ OGRLayer#m_apoFieldDefnChanges..emplace_back( |
| 1863 | stdcxx . . $ std/::make_unique<OGRFieldDefncxx . . $ OGRFieldDefn#>(oFieldDefn), |
| 1864 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).() - 1, FieldChangeTypecxx . . $ OGRLayer#FieldChangeType#::ADD_FIELDcxx . . $ OGRLayer#FieldChangeType#ADD_FIELD., |
| 1865 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentSavepointcxx . . $ OGRSQLiteBaseDataSource#GetCurrentSavepoint(219584694fe2b248).()); |
| 1866 | } |
| 1867 | |
| 1868 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr && |
| 1869 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(oFieldDefn.GetNameRef(), m_pszFidColumn)) |
| 1870 | { |
| 1871 | m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).() - 1; |
| 1872 | } |
| 1873 | |
| 1874 | if (!m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation.) |
| 1875 | { |
| 1876 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 1877 | } |
| 1878 | |
| 1879 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 1880 | } |
| 1881 | |
| 1882 | /************************************************************************/ |
| 1883 | /* DoSpecialProcessingForColumnCreation() */ |
| 1884 | /************************************************************************/ |
| 1885 | |
| 1886 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DoSpecialProcessingForColumnCreationcxx . . $ OGRGeoPackageTableLayer#DoSpecialProcessingForColumnCreation(6ac7e7c63d694732).( |
| 1887 | const OGRFieldDefncxx . . $ OGRFieldDefn# *poField) |
| 1888 | { |
| 1889 | const stdcxx . . $ std/::string &osConstraintName(poField->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).()); |
| 1890 | const stdcxx . . $ std/::string osName(poField->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).()); |
| 1891 | const stdcxx . . $ std/::string &osDescription(poField->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).()); |
| 1892 | |
| 1893 | stdcxx . . $ std/::string osMimeType; |
| 1894 | if (poField->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTString && poField->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).() == OFSTJSON) |
| 1895 | { |
| 1896 | osMimeType = "application/json"; |
| 1897 | } |
| 1898 | |
| 1899 | if (osConstraintName.empty() && osName.empty() && osDescription.empty() && |
| 1900 | osMimeType.empty()) |
| 1901 | { |
| 1902 | // no record required |
| 1903 | return true; |
| 1904 | } |
| 1905 | |
| 1906 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->CreateColumnsTableAndColumnConstraintsTablesIfNecessarycxx . . $ GDALGeoPackageDataset#CreateColumnsTableAndColumnConstraintsTablesIfNecessary(c9857a73d68e59ba).()) |
| 1907 | return false; |
| 1908 | |
| 1909 | /* Now let's register our column. */ |
| 1910 | stdcxx . . $ std/::string osNameSqlValue; |
| 1911 | if (osName.empty()) |
| 1912 | { |
| 1913 | osNameSqlValue = "NULL"; |
| 1914 | } |
| 1915 | else |
| 1916 | { |
| 1917 | char *pszName = sqlite3_mprintf("'%q'", osName.c_str()); |
| 1918 | osNameSqlValue = stdcxx . . $ std/::string(pszName); |
| 1919 | sqlite3_free(pszName); |
| 1920 | } |
| 1921 | |
| 1922 | stdcxx . . $ std/::string osDescriptionSqlValue; |
| 1923 | if (osDescription.empty()) |
| 1924 | { |
| 1925 | osDescriptionSqlValue = "NULL"; |
| 1926 | } |
| 1927 | else |
| 1928 | { |
| 1929 | char *pszDescription = sqlite3_mprintf("'%q'", osDescription.c_str()); |
| 1930 | osDescriptionSqlValue = stdcxx . . $ std/::string(pszDescription); |
| 1931 | sqlite3_free(pszDescription); |
| 1932 | } |
| 1933 | |
| 1934 | stdcxx . . $ std/::string osMimeTypeSqlValue; |
| 1935 | if (osMimeType.empty()) |
| 1936 | { |
| 1937 | osMimeTypeSqlValue = "NULL"; |
| 1938 | } |
| 1939 | else |
| 1940 | { |
| 1941 | char *pszMimeType = sqlite3_mprintf("'%q'", osMimeType.c_str()); |
| 1942 | osMimeTypeSqlValue = stdcxx . . $ std/::string(pszMimeType); |
| 1943 | sqlite3_free(pszMimeType); |
| 1944 | } |
| 1945 | |
| 1946 | stdcxx . . $ std/::string osConstraintNameValue; |
| 1947 | if (osConstraintName.empty()) |
| 1948 | { |
| 1949 | osConstraintNameValue = "NULL"; |
| 1950 | } |
| 1951 | else |
| 1952 | { |
| 1953 | char *pszConstraintName = |
| 1954 | sqlite3_mprintf("'%q'", osConstraintName.c_str()); |
| 1955 | osConstraintNameValue = stdcxx . . $ std/::string(pszConstraintName); |
| 1956 | sqlite3_free(pszConstraintName); |
| 1957 | } |
| 1958 | |
| 1959 | char *pszSQL = sqlite3_mprintf( |
| 1960 | "INSERT INTO gpkg_data_columns (table_name, column_name, name, " |
| 1961 | "title, description, mime_type, constraint_name) VALUES (" |
| 1962 | "'%q', '%q', %s, NULL, %s, %s, %s)", |
| 1963 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., poField->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), osNameSqlValue.c_str(), |
| 1964 | osDescriptionSqlValue.c_str(), osMimeTypeSqlValue.c_str(), |
| 1965 | osConstraintNameValue.c_str()); |
| 1966 | |
| 1967 | bool ok = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 1968 | sqlite3_free(pszSQL); |
| 1969 | return ok; |
| 1970 | } |
| 1971 | |
| 1972 | /************************************************************************/ |
| 1973 | /* CreateGeomField() */ |
| 1974 | /************************************************************************/ |
| 1975 | |
| 1976 | OGRErr |
| 1977 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateGeomFieldcxx . . $ OGRGeoPackageTableLayer#CreateGeomField(6dac0ba981f896cd).(const OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# *poGeomFieldIn, |
| 1978 | int /* bApproxOK */) |
| 1979 | { |
| 1980 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 1981 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 1982 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("CreateGeomField")) |
| 1983 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1984 | |
| 1985 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 1) |
| 1986 | { |
| 1987 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1988 | "Cannot create more than one geometry field in GeoPackage"); |
| 1989 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1990 | } |
| 1991 | |
| 1992 | OGRwkbGeometryType eType = poGeomFieldIn->GetTypecxx . . $ OGRGeomFieldDefn#GetType(5a40c54c5ff210ce).(); |
| 1993 | if (eType == wkbNone) |
| 1994 | { |
| 1995 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 1996 | "Cannot create geometry field of type wkbNone"); |
| 1997 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 1998 | } |
| 1999 | |
| 2000 | OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# oGeomFieldcxx . . $ OGRGeomFieldDefn#OGRGeomFieldDefn(9997450ff2bf2bb5).(poGeomFieldIn); |
| 2001 | const auto poSRSOri = poGeomFieldIn->GetSpatialRefcxx . . $ OGRGeomFieldDefn#GetSpatialRef(8a5496c2eeefaeaf).(); |
| 2002 | if (poSRSOri) |
| 2003 | { |
| 2004 | auto poSRS = OGRSpatialReferenceRefCountedPtrcxx . . $ OGRSpatialReferenceRefCountedPtr#::makeClonecxx . . $ OGRRefCountedPtr#makeClone(52807447ccd2a8c8).(poSRSOri); |
| 2005 | poSRS->cxx . . $ OGRRefCountedPtrBase#`operator->`(5a2a78a048fb49a8).SetAxisMappingStrategycxx . . $ OGRSpatialReference#SetAxisMappingStrategy(3d39f43974738d6a).(OAMS_TRADITIONAL_GIS_ORDER); |
| 2006 | oGeomField.SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(poSRS.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 2007 | } |
| 2008 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(oGeomField.GetNameRef(), "")) |
| 2009 | { |
| 2010 | oGeomField.SetNamecxx . . $ OGRGeomFieldDefn#SetName(85c52e162fed56f9).("geom"); |
| 2011 | } |
| 2012 | |
| 2013 | const OGRSpatialReferencecxx . . $ OGRSpatialReference# *poSRS = oGeomField.GetSpatialRefcxx . . $ OGRGeomFieldDefn#GetSpatialRef(8a5496c2eeefaeaf).(); |
| 2014 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSrsIdcxx . . $ GDALGeoPackageDataset#GetSrsId(8a145e066b724d94).(poSRS); |
| 2015 | |
| 2016 | /* -------------------------------------------------------------------- */ |
| 2017 | /* Create the new field. */ |
| 2018 | /* -------------------------------------------------------------------- */ |
| 2019 | if (!m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation.) |
| 2020 | { |
| 2021 | char *pszSQL = sqlite3_mprintf( |
| 2022 | "ALTER TABLE \"%w\" ADD COLUMN \"%w\" %s%s" |
| 2023 | ";" |
| 2024 | "UPDATE gpkg_contents SET data_type = 'features' " |
| 2025 | "WHERE lower(table_name) = lower('%q')", |
| 2026 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., oGeomField.GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 2027 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetGeometryTypeStringcxx . . $ GDALGeoPackageDataset#GetGeometryTypeString(10f7d487d41f9e63).(oGeomField.GetTypecxx . . $ OGRGeomFieldDefn#GetType(5a40c54c5ff210ce).()), |
| 2028 | !oGeomField.IsNullablecxx . . $ OGRGeomFieldDefn#IsNullable(455f465bc33b4cdf).() ? " NOT NULL DEFAULT ''" : "", |
| 2029 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2030 | CPLString osSQL(pszSQL); |
| 2031 | sqlite3_free(pszSQL); |
| 2032 | |
| 2033 | OGRErr err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL); |
| 2034 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 2035 | return err; |
| 2036 | } |
| 2037 | |
| 2038 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).()) |
| 2039 | { |
| 2040 | m_apoGeomFieldDefnChangescxx . . $ OGRLayer#m_apoGeomFieldDefnChanges..emplace_back( |
| 2041 | stdcxx . . $ std/::make_unique<OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn#>(oGeomField), |
| 2042 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).(), FieldChangeTypecxx . . $ OGRLayer#FieldChangeType#::ADD_FIELDcxx . . $ OGRLayer#FieldChangeType#ADD_FIELD.); |
| 2043 | } |
| 2044 | |
| 2045 | whileUnsealingcxx . . $ whileUnsealing(de07598ec200be45).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.)->cxx . . $ OGRFeatureDefn#TemporaryUnsealer#`operator->`(407fccde18759965).AddGeomFieldDefncxx . . $ OGRFeatureDefn#AddGeomFieldDefn(9997450ff2bf2bb5).(&oGeomField); |
| 2046 | |
| 2047 | if (!m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation.) |
| 2048 | { |
| 2049 | OGRErr err = RegisterGeometryColumncxx . . $ OGRGeoPackageTableLayer#RegisterGeometryColumn(b126dc7c1de90089).(); |
| 2050 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 2051 | return err; |
| 2052 | |
| 2053 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 2054 | } |
| 2055 | |
| 2056 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 2057 | } |
| 2058 | |
| 2059 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 2060 | |
| 2061 | /************************************************************************/ |
| 2062 | /* DisableFeatureCount() */ |
| 2063 | /************************************************************************/ |
| 2064 | |
| 2065 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DisableFeatureCountcxx . . $ OGRGeoPackageTableLayer#DisableFeatureCount(49f6e7a06ebc5aa8).() |
| 2066 | { |
| 2067 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = -1; |
| 2068 | } |
| 2069 | |
| 2070 | /************************************************************************/ |
| 2071 | /* CreateFeatureCountTriggers() */ |
| 2072 | /************************************************************************/ |
| 2073 | |
| 2074 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#CreateFeatureCountTriggers(85c52e162fed56f9).( |
| 2075 | const char *pszTableName) |
| 2076 | { |
| 2077 | if (m_bAddOGRFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#m_bAddOGRFeatureCountTriggers.) |
| 2078 | { |
| 2079 | if (pszTableName == nullptr) |
| 2080 | pszTableName = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 2081 | |
| 2082 | m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled. = true; |
| 2083 | m_bAddOGRFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#m_bAddOGRFeatureCountTriggers. = false; |
| 2084 | m_bFeatureCountTriggersDeletedInTransactioncxx . . $ OGRGeoPackageTableLayer#m_bFeatureCountTriggersDeletedInTransaction. = false; |
| 2085 | |
| 2086 | CPLDebug("GPKG", "Creating insert/delete feature_count triggers"); |
| 2087 | char *pszSQL = sqlite3_mprintf( |
| 2088 | "CREATE TRIGGER \"trigger_insert_feature_count_%w\" " |
| 2089 | "AFTER INSERT ON \"%w\" " |
| 2090 | "BEGIN UPDATE gpkg_ogr_contents SET feature_count = " |
| 2091 | "feature_count + 1 WHERE lower(table_name) = lower('%q'); END;", |
| 2092 | pszTableName, pszTableName, pszTableName); |
| 2093 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2094 | sqlite3_free(pszSQL); |
| 2095 | |
| 2096 | pszSQL = sqlite3_mprintf( |
| 2097 | "CREATE TRIGGER \"trigger_delete_feature_count_%w\" " |
| 2098 | "AFTER DELETE ON \"%w\" " |
| 2099 | "BEGIN UPDATE gpkg_ogr_contents SET feature_count = " |
| 2100 | "feature_count - 1 WHERE lower(table_name) = lower('%q'); END;", |
| 2101 | pszTableName, pszTableName, pszTableName); |
| 2102 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2103 | sqlite3_free(pszSQL); |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | /************************************************************************/ |
| 2108 | /* DisableFeatureCountTriggers() */ |
| 2109 | /************************************************************************/ |
| 2110 | |
| 2111 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DisableFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#DisableFeatureCountTriggers(b45ddcbc8423892c).( |
| 2112 | bool bNullifyFeatureCount) |
| 2113 | { |
| 2114 | if (m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled.) |
| 2115 | { |
| 2116 | m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled. = false; |
| 2117 | m_bAddOGRFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#m_bAddOGRFeatureCountTriggers. = true; |
| 2118 | m_bFeatureCountTriggersDeletedInTransactioncxx . . $ OGRGeoPackageTableLayer#m_bFeatureCountTriggersDeletedInTransaction. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).(); |
| 2119 | |
| 2120 | CPLDebug("GPKG", "Deleting insert/delete feature_count triggers"); |
| 2121 | |
| 2122 | char *pszSQL = sqlite3_mprintf( |
| 2123 | "DROP TRIGGER \"trigger_insert_feature_count_%w\"", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2124 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2125 | sqlite3_free(pszSQL); |
| 2126 | |
| 2127 | pszSQL = sqlite3_mprintf( |
| 2128 | "DROP TRIGGER \"trigger_delete_feature_count_%w\"", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2129 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2130 | sqlite3_free(pszSQL); |
| 2131 | |
| 2132 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents. && bNullifyFeatureCount) |
| 2133 | { |
| 2134 | pszSQL = sqlite3_mprintf( |
| 2135 | "UPDATE gpkg_ogr_contents SET feature_count = NULL WHERE " |
| 2136 | "lower(table_name )= lower('%q')", |
| 2137 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2138 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2139 | sqlite3_free(pszSQL); |
| 2140 | } |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | #endif // #ifdef ENABLE_GPKG_OGR_CONTENTS |
| 2145 | |
| 2146 | /************************************************************************/ |
| 2147 | /* CheckGeometryType() */ |
| 2148 | /************************************************************************/ |
| 2149 | |
| 2150 | /** Check that the feature geometry type is consistent with the layer geometry |
| 2151 | * type. |
| 2152 | * |
| 2153 | * And potentially update the Z and M flags of gpkg_geometry_columns to |
| 2154 | * reflect the dimensionality of feature geometries. |
| 2155 | */ |
| 2156 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CheckGeometryTypecxx . . $ OGRGeoPackageTableLayer#CheckGeometryType(c79b2f12299c1ae2).(const OGRFeaturecxx . . $ OGRFeature# *poFeature) |
| 2157 | { |
| 2158 | const OGRwkbGeometryType eLayerGeomType = GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).(); |
| 2159 | const OGRwkbGeometryType eFlattenLayerGeomType = wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(eLayerGeomType); |
| 2160 | const OGRGeometrycxx . . $ OGRGeometry# *poGeom = poFeature->GetGeometryRefcxx . . $ OGRFeature#GetGeometryRef(5cd284b510ae083c).(); |
| 2161 | if (eFlattenLayerGeomType != wkbNone && eFlattenLayerGeomType != wkbUnknown) |
| 2162 | { |
| 2163 | if (poGeom != nullptr) |
| 2164 | { |
| 2165 | OGRwkbGeometryType eGeomType = |
| 2166 | wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(poGeom->getGeometryType()); |
| 2167 | if (!OGR_GT_IsSubClassOf(eGeomType, eFlattenLayerGeomType) && |
| 2168 | !cplcxx . . $ cpl/::contains(m_eSetBadGeomTypeWarnedcxx . . $ OGRGeoPackageTableLayer#m_eSetBadGeomTypeWarned., eGeomType)) |
| 2169 | { |
| 2170 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2171 | "A geometry of type %s is inserted into layer %s " |
| 2172 | "of geometry type %s, which is not normally allowed " |
| 2173 | "by the GeoPackage specification, but the driver will " |
| 2174 | "however do it. " |
| 2175 | "To create a conformant GeoPackage, if using ogr2ogr, " |
| 2176 | "the -nlt option can be used to override the layer " |
| 2177 | "geometry type. " |
| 2178 | "This warning will no longer be emitted for this " |
| 2179 | "combination of layer and feature geometry type.", |
| 2180 | OGRToOGCGeomTypecxx . . $ OGRToOGCGeomType(59e7cc99d9ae6078).(eGeomType), GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), |
| 2181 | OGRToOGCGeomTypecxx . . $ OGRToOGCGeomType(59e7cc99d9ae6078).(eFlattenLayerGeomType)); |
| 2182 | m_eSetBadGeomTypeWarnedcxx . . $ OGRGeoPackageTableLayer#m_eSetBadGeomTypeWarned..insertcxx . . $ std/set#insert(411a10a755068dfe).(eGeomType); |
| 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | // Make sure to update the z and m columns of gpkg_geometry_columns to 2 |
| 2188 | // if we have geometries with Z and M components |
| 2189 | if (m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. == 0 || m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag. == 0) |
| 2190 | { |
| 2191 | if (poGeom != nullptr) |
| 2192 | { |
| 2193 | bool bUpdateGpkgGeometryColumnsTable = false; |
| 2194 | const OGRwkbGeometryType eGeomType = poGeom->getGeometryTypecxx . . $ OGRGeometry#getGeometryType(5a40c54c5ff210ce).(); |
| 2195 | if (m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. == 0 && wkbHasZcxx . . $ `ogr/ogr_core.h:581:9`!(eGeomType)) |
| 2196 | { |
| 2197 | if (eLayerGeomType != wkbUnknown && !wkbHasZcxx . . $ `ogr/ogr_core.h:581:9`!(eLayerGeomType)) |
| 2198 | { |
| 2199 | CPLError( |
| 2200 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2201 | "Layer '%s' has been declared with non-Z geometry type " |
| 2202 | "%s, but it does contain geometries with Z. Setting " |
| 2203 | "the Z=2 hint into gpkg_geometry_columns. " |
| 2204 | "If using ogr2ogr, specify the -nlt option to avoid " |
| 2205 | "ambiguity.", |
| 2206 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), |
| 2207 | OGRToOGCGeomTypecxx . . $ OGRToOGCGeomType(59e7cc99d9ae6078).(eLayerGeomType, true, true, true)); |
| 2208 | } |
| 2209 | m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. = 2; |
| 2210 | bUpdateGpkgGeometryColumnsTable = true; |
| 2211 | } |
| 2212 | if (m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag. == 0 && wkbHasMcxx . . $ `ogr/ogr_core.h:589:9`!(eGeomType)) |
| 2213 | { |
| 2214 | if (eLayerGeomType != wkbUnknown && !wkbHasMcxx . . $ `ogr/ogr_core.h:589:9`!(eLayerGeomType)) |
| 2215 | { |
| 2216 | CPLError( |
| 2217 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2218 | "Layer '%s' has been declared with non-M geometry type " |
| 2219 | "%s, but it does contain geometries with M. Setting " |
| 2220 | "the M=2 hint into gpkg_geometry_columns. " |
| 2221 | "If using ogr2ogr, specify the -nlt option to avoid " |
| 2222 | "ambiguity.", |
| 2223 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), |
| 2224 | OGRToOGCGeomTypecxx . . $ OGRToOGCGeomType(59e7cc99d9ae6078).(eLayerGeomType, true, true, true)); |
| 2225 | } |
| 2226 | m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag. = 2; |
| 2227 | bUpdateGpkgGeometryColumnsTable = true; |
| 2228 | } |
| 2229 | if (bUpdateGpkgGeometryColumnsTable) |
| 2230 | { |
| 2231 | /* Update gpkg_geometry_columns */ |
| 2232 | char *pszSQL = sqlite3_mprintf( |
| 2233 | "UPDATE gpkg_geometry_columns SET z = %d, m = %d WHERE " |
| 2234 | "table_name = '%q' AND column_name = '%q'", |
| 2235 | m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag., m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag., GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).()); |
| 2236 | CPL_IGNORE_RET_VAL(SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL)); |
| 2237 | sqlite3_free(pszSQL); |
| 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | /************************************************************************/ |
| 2244 | /* CheckFIDAndFIDColumnConsistency() */ |
| 2245 | /************************************************************************/ |
| 2246 | |
| 2247 | static bool CheckFIDAndFIDColumnConsistencycxx . . $ CheckFIDAndFIDColumnConsistency(760bd0252d02a09d).(const OGRFeaturecxx . . $ OGRFeature# *poFeature, |
| 2248 | int iFIDAsRegularColumnIndex) |
| 2249 | { |
| 2250 | bool ok = true; |
| 2251 | if (!poFeature->IsFieldSetAndNotNullcxx . . $ OGRFeature#IsFieldSetAndNotNull(4a668f6de69bf818).(iFIDAsRegularColumnIndex)) |
| 2252 | { |
| 2253 | // nothing to do |
| 2254 | } |
| 2255 | else if (poFeature->GetDefnRefcxx . . $ OGRFeature#GetDefnRef(448b209f43d15bcc).() |
| 2256 | ->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(iFIDAsRegularColumnIndex) |
| 2257 | ->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTReal) |
| 2258 | { |
| 2259 | const double dfFID = |
| 2260 | poFeature->GetFieldAsDoublecxx . . $ OGRFeature#GetFieldAsDouble(8bbae5fb2e9ef7ac).(iFIDAsRegularColumnIndex); |
| 2261 | if (GDALIsValueInRangecxx . . $ GDALIsValueInRange(f8197d536af80c96).<int64_t>(dfFID)) |
| 2262 | { |
| 2263 | const auto nFID = static_cast<GIntBigcxx . . $ GIntBig#>(dfFID); |
| 2264 | if (nFID != poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()) |
| 2265 | { |
| 2266 | ok = false; |
| 2267 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2268 | "Inconsistent values of FID (" CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! |
| 2269 | ") and field of same name (%g)", |
| 2270 | poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).(), |
| 2271 | poFeature->GetFieldAsDoublecxx . . $ OGRFeature#GetFieldAsDouble(8bbae5fb2e9ef7ac).(iFIDAsRegularColumnIndex)); |
| 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | else if (poFeature->GetFieldAsInteger64cxx . . $ OGRFeature#GetFieldAsInteger64(f3f16611d465c84c).(iFIDAsRegularColumnIndex) != |
| 2276 | poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()) |
| 2277 | { |
| 2278 | ok = false; |
| 2279 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2280 | "Inconsistent values of FID (" CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! |
| 2281 | ") and field of same name (" CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! ")", |
| 2282 | poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).(), |
| 2283 | poFeature->GetFieldAsInteger64cxx . . $ OGRFeature#GetFieldAsInteger64(f3f16611d465c84c).(iFIDAsRegularColumnIndex)); |
| 2284 | } |
| 2285 | return ok; |
| 2286 | } |
| 2287 | |
| 2288 | /************************************************************************/ |
| 2289 | /* ICreateFeature() */ |
| 2290 | /************************************************************************/ |
| 2291 | |
| 2292 | // rtreeValueDown() / rtreeValueUp() come from SQLite3 source code |
| 2293 | // SQLite3 RTree stores min/max values as float. So do the same for our |
| 2294 | // GPKGRTreeEntry |
| 2295 | |
| 2296 | /* |
| 2297 | ** Rounding constants for float->double conversion. |
| 2298 | */ |
| 2299 | #define RNDTOWARDScxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:2299:9`! (1.0 - 1.0 / 8388608.0) /* Round towards zero */ |
| 2300 | #define RNDAWAYcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:2300:9`! (1.0 + 1.0 / 8388608.0) /* Round away from zero */ |
| 2301 | |
| 2302 | /* |
| 2303 | ** Convert an sqlite3_value into an RtreeValue (presumably a float) |
| 2304 | ** while taking care to round toward negative or positive, respectively. |
| 2305 | */ |
| 2306 | static float rtreeValueDowncxx . . $ rtreeValueDown(2f2c9d02d22c701f).(double d) |
| 2307 | { |
| 2308 | float f = static_cast<float>(d); |
| 2309 | if (f > d) |
| 2310 | { |
| 2311 | f = static_cast<float>(d * (d < 0 ? RNDAWAYcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:2300:9`! : RNDTOWARDScxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:2299:9`!)); |
| 2312 | } |
| 2313 | return f; |
| 2314 | } |
| 2315 | |
| 2316 | static float rtreeValueUpcxx . . $ rtreeValueUp(2f2c9d02d22c701f).(double d) |
| 2317 | { |
| 2318 | float f = static_cast<float>(d); |
| 2319 | if (f < d) |
| 2320 | { |
| 2321 | f = static_cast<float>(d * (d < 0 ? RNDTOWARDScxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:2299:9`! : RNDAWAYcxx . . $ `ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp:2300:9`!)); |
| 2322 | } |
| 2323 | return f; |
| 2324 | } |
| 2325 | |
| 2326 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateOrUpsertFeaturecxx . . $ OGRGeoPackageTableLayer#CreateOrUpsertFeature(2552997c5ecc345e).(OGRFeaturecxx . . $ OGRFeature# *poFeature, |
| 2327 | bool bUpsert) |
| 2328 | { |
| 2329 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 2330 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 2331 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).()) |
| 2332 | { |
| 2333 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY., |
| 2334 | "CreateFeature"); |
| 2335 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2336 | } |
| 2337 | |
| 2338 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 2339 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2340 | |
| 2341 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 2342 | |
| 2343 | stdcxx . . $ std/::string osUpsertUniqueColumnName; |
| 2344 | if (bUpsert && poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) |
| 2345 | { |
| 2346 | int nUniqueColumns = 0; |
| 2347 | const int nFieldCount = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); |
| 2348 | for (int i = 0; i < nFieldCount; ++i) |
| 2349 | { |
| 2350 | const auto poFieldDefn = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(i); |
| 2351 | if (poFieldDefn->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).()) |
| 2352 | { |
| 2353 | if (osUpsertUniqueColumnName.empty()) |
| 2354 | osUpsertUniqueColumnName = poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 2355 | nUniqueColumns++; |
| 2356 | } |
| 2357 | } |
| 2358 | if (nUniqueColumns == 0) |
| 2359 | { |
| 2360 | // This is just a regular INSERT |
| 2361 | bUpsert = false; |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | if (bUpsert) |
| 2366 | { |
| 2367 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 2368 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 2369 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 2370 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2371 | if (!m_bUpdate1TriggerDisabledcxx . . $ OGRGeoPackageTableLayer#m_bUpdate1TriggerDisabled. && HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 2372 | WorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#WorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).(); |
| 2373 | } |
| 2374 | |
| 2375 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 2376 | if (bUpsert) |
| 2377 | { |
| 2378 | if (m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. >= 0) |
| 2379 | { |
| 2380 | // There's no reliable way of knowing if a new row has been inserted |
| 2381 | // or just updated, so serialize known value and then |
| 2382 | // invalidate feature count. |
| 2383 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 2384 | { |
| 2385 | const char *pszCount = |
| 2386 | CPLSPrintf(CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.); |
| 2387 | char *pszSQL = sqlite3_mprintf( |
| 2388 | "UPDATE gpkg_ogr_contents SET feature_count = %s WHERE " |
| 2389 | "lower(table_name )= lower('%q')", |
| 2390 | pszCount, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2391 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2392 | sqlite3_free(pszSQL); |
| 2393 | } |
| 2394 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = -1; |
| 2395 | |
| 2396 | if (!m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled.) |
| 2397 | CreateFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#CreateFeatureCountTriggers(85c52e162fed56f9).(); |
| 2398 | } |
| 2399 | } |
| 2400 | else |
| 2401 | { |
| 2402 | // To maximize performance of insertion, disable feature count triggers |
| 2403 | if (m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled.) |
| 2404 | { |
| 2405 | DisableFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#DisableFeatureCountTriggers(b45ddcbc8423892c).(); |
| 2406 | } |
| 2407 | } |
| 2408 | #endif |
| 2409 | |
| 2410 | CheckGeometryTypecxx . . $ OGRGeoPackageTableLayer#CheckGeometryType(c79b2f12299c1ae2).(poFeature); |
| 2411 | |
| 2412 | /* Substitute default values for null Date/DateTime fields as the standard |
| 2413 | */ |
| 2414 | /* format of SQLite is not the one mandated by GeoPackage */ |
| 2415 | poFeature->FillUnsetWithDefaultcxx . . $ OGRFeature#FillUnsetWithDefault(5151383285df94d8).(FALSEcxx . . $ `port/cpl_port.h:1180:9`!, nullptr); |
| 2416 | bool bHasDefaultValue = false; |
| 2417 | const int nFieldCount = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); |
| 2418 | for (int iField = 0; iField < nFieldCount; iField++) |
| 2419 | { |
| 2420 | if (poFeature->IsFieldSetUnsafecxx . . $ OGRFeature#IsFieldSetUnsafe(4a668f6de69bf818).(iField)) |
| 2421 | continue; |
| 2422 | const char *pszDefault = |
| 2423 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefnUnsafecxx . . $ OGRFeatureDefn#GetFieldDefnUnsafe(2ec36f91b6ceefc7).(iField)->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(); |
| 2424 | if (pszDefault != nullptr) |
| 2425 | { |
| 2426 | bHasDefaultValue = true; |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | /* In case the FID column has also been created as a regular field */ |
| 2431 | if (m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0) |
| 2432 | { |
| 2433 | if (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) |
| 2434 | { |
| 2435 | if (poFeature->IsFieldSetAndNotNullcxx . . $ OGRFeature#IsFieldSetAndNotNull(4a668f6de69bf818).(m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.)) |
| 2436 | { |
| 2437 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.) |
| 2438 | ->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTReal) |
| 2439 | { |
| 2440 | bool ok = false; |
| 2441 | const double dfFID = |
| 2442 | poFeature->GetFieldAsDoublecxx . . $ OGRFeature#GetFieldAsDouble(8bbae5fb2e9ef7ac).(m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.); |
| 2443 | if (dfFID >= static_cast<double>( |
| 2444 | stdcxx . . $ std/::numeric_limits<int64_t>::min()) && |
| 2445 | dfFID <= static_cast<double>( |
| 2446 | stdcxx . . $ std/::numeric_limits<int64_t>::max())) |
| 2447 | { |
| 2448 | const auto nFID = static_cast<GIntBigcxx . . $ GIntBig#>(dfFID); |
| 2449 | if (static_cast<double>(nFID) == dfFID) |
| 2450 | { |
| 2451 | poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(nFID); |
| 2452 | ok = true; |
| 2453 | } |
| 2454 | } |
| 2455 | if (!ok) |
| 2456 | { |
| 2457 | CPLError( |
| 2458 | CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2459 | "Value of FID %g cannot be parsed to an Integer64", |
| 2460 | dfFID); |
| 2461 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2462 | } |
| 2463 | } |
| 2464 | else |
| 2465 | { |
| 2466 | poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(poFeature->GetFieldAsInteger64cxx . . $ OGRFeature#GetFieldAsInteger64(f3f16611d465c84c).( |
| 2467 | m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.)); |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | else if (!CheckFIDAndFIDColumnConsistencycxx . . $ CheckFIDAndFIDColumnConsistency(760bd0252d02a09d).(poFeature, |
| 2472 | m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.)) |
| 2473 | { |
| 2474 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | /* If there's a unset field with a default value, then we must create */ |
| 2479 | /* a specific INSERT statement to avoid unset fields to be bound to NULL */ |
| 2480 | if (m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement. && |
| 2481 | (bHasDefaultValue || |
| 2482 | m_bInsertStatementWithFIDcxx . . $ OGRGeoPackageTableLayer#m_bInsertStatementWithFID. != (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() != OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) || |
| 2483 | m_bInsertStatementWithUpsertcxx . . $ OGRGeoPackageTableLayer#m_bInsertStatementWithUpsert. != bUpsert || |
| 2484 | m_osInsertStatementUpsertUniqueColumnNamecxx . . $ OGRGeoPackageTableLayer#m_osInsertStatementUpsertUniqueColumnName. != osUpsertUniqueColumnName)) |
| 2485 | { |
| 2486 | sqlite3_finalize(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2487 | m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement. = nullptr; |
| 2488 | } |
| 2489 | |
| 2490 | if (!m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.) |
| 2491 | { |
| 2492 | /* Construct a SQL INSERT statement from the OGRFeature */ |
| 2493 | /* Only work with fields that are set */ |
| 2494 | /* Do not stick values into SQL, use placeholder and bind values later |
| 2495 | */ |
| 2496 | m_bInsertStatementWithFIDcxx . . $ OGRGeoPackageTableLayer#m_bInsertStatementWithFID. = poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() != OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!; |
| 2497 | m_bInsertStatementWithUpsertcxx . . $ OGRGeoPackageTableLayer#m_bInsertStatementWithUpsert. = bUpsert; |
| 2498 | m_osInsertStatementUpsertUniqueColumnNamecxx . . $ OGRGeoPackageTableLayer#m_osInsertStatementUpsertUniqueColumnName. = osUpsertUniqueColumnName; |
| 2499 | CPLString osCommand = FeatureGenerateInsertSQLcxx . . $ OGRGeoPackageTableLayer#FeatureGenerateInsertSQL(778ee83e2d2e6b80).( |
| 2500 | poFeature, m_bInsertStatementWithFIDcxx . . $ OGRGeoPackageTableLayer#m_bInsertStatementWithFID., !bHasDefaultValue, bUpsert, |
| 2501 | osUpsertUniqueColumnName); |
| 2502 | |
| 2503 | /* Prepare the SQL into a statement */ |
| 2504 | sqlite3 *poDb = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 2505 | int err = SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(poDb, osCommand, -1, &m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement., |
| 2506 | nullptr); |
| 2507 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 2508 | { |
| 2509 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2510 | } |
| 2511 | } |
| 2512 | |
| 2513 | /* Bind values onto the statement now */ |
| 2514 | OGRErr errOgr = FeatureBindInsertParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindInsertParameters(17e8baf1e071a650).(poFeature, m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement., |
| 2515 | m_bInsertStatementWithFIDcxx . . $ OGRGeoPackageTableLayer#m_bInsertStatementWithFID., |
| 2516 | !bHasDefaultValue); |
| 2517 | if (errOgr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 2518 | { |
| 2519 | sqlite3_reset(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2520 | sqlite3_clear_bindings(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2521 | sqlite3_finalize(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2522 | m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement. = nullptr; |
| 2523 | return errOgr; |
| 2524 | } |
| 2525 | |
| 2526 | /* From here execute the statement and check errors */ |
| 2527 | const int err = sqlite3_step(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2528 | if (!(err == SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`! || err == SQLITE_DONEcxx . . $ `<external>/2400532043262193228/sqlite3.h:480:9`! |
| 2529 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3035000L |
| 2530 | || err == SQLITE_ROWcxx . . $ `<external>/2400532043262193228/sqlite3.h:479:9`! |
| 2531 | #endif |
| 2532 | )) |
| 2533 | { |
| 2534 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "failed to execute insert : %s", |
| 2535 | sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()) |
| 2536 | ? sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()) |
| 2537 | : ""); |
| 2538 | sqlite3_reset(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2539 | sqlite3_clear_bindings(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2540 | sqlite3_finalize(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2541 | m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement. = nullptr; |
| 2542 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2543 | } |
| 2544 | |
| 2545 | /* Read the latest FID value */ |
| 2546 | const GIntBigcxx . . $ GIntBig# nFID = (bUpsert && !osUpsertUniqueColumnName.empty()) |
| 2547 | ? |
| 2548 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3035000L |
| 2549 | sqlite3_column_int64(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement., 0) |
| 2550 | #else |
| 2551 | OGRNullFID |
| 2552 | #endif |
| 2553 | : sqlite3_last_insert_rowid(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 2554 | |
| 2555 | sqlite3_reset(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2556 | sqlite3_clear_bindings(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2557 | |
| 2558 | if (bHasDefaultValue) |
| 2559 | { |
| 2560 | sqlite3_finalize(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 2561 | m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement. = nullptr; |
| 2562 | } |
| 2563 | |
| 2564 | if (nFID != OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) |
| 2565 | { |
| 2566 | poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(nFID); |
| 2567 | if (m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0) |
| 2568 | poFeature->SetFieldcxx . . $ OGRFeature#SetField(9ffed314a0a4f263).(m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex., nFID); |
| 2569 | } |
| 2570 | else |
| 2571 | { |
| 2572 | poFeature->SetFIDcxx . . $ OGRFeature#SetFID(a070d6d14e988596).(OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!); |
| 2573 | } |
| 2574 | |
| 2575 | /* Update the layer extents with this new object */ |
| 2576 | if (IsGeomFieldSetcxx . . $ OGRGeoPackageTableLayer#IsGeomFieldSet(9d38d33a35b5766a).(poFeature)) |
| 2577 | { |
| 2578 | OGRGeometrycxx . . $ OGRGeometry# *poGeom = poFeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(0); |
| 2579 | if (!poGeom->IsEmptycxx . . $ OGRGeometry#IsEmpty(455f465bc33b4cdf).()) |
| 2580 | { |
| 2581 | OGREnvelope oEnv; |
| 2582 | poGeom->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&oEnv); |
| 2583 | UpdateExtentcxx . . $ OGRGeoPackageTableLayer#UpdateExtent(6720dbbe3ac92137).(&oEnv); |
| 2584 | |
| 2585 | if (!bUpsert && !m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation. && |
| 2586 | HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).() && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).()) |
| 2587 | { |
| 2588 | m_nCountInsertInTransactioncxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransaction.++; |
| 2589 | if (m_nCountInsertInTransactionThresholdcxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransactionThreshold. < 0) |
| 2590 | { |
| 2591 | m_nCountInsertInTransactionThresholdcxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransactionThreshold. = |
| 2592 | atoicxx . . $ atoi(f5ecf3191ed0cd93).(CPLGetConfigOption( |
| 2593 | "OGR_GPKG_DEFERRED_SPI_UPDATE_THRESHOLD", "100")); |
| 2594 | } |
| 2595 | if (m_nCountInsertInTransactioncxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransaction. == |
| 2596 | m_nCountInsertInTransactionThresholdcxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransactionThreshold.) |
| 2597 | { |
| 2598 | StartDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#StartDeferredSpatialIndexUpdate(c9857a73d68e59ba).(); |
| 2599 | } |
| 2600 | else if (!m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..empty()) |
| 2601 | { |
| 2602 | if (m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..size() == 1000 * 1000) |
| 2603 | { |
| 2604 | if (!FlushPendingSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#FlushPendingSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 2605 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 2606 | } |
| 2607 | GPKGRTreeEntrycxx . . $ OGRGeoPackageTableLayer#GPKGRTreeEntry# sEntry; |
| 2608 | sEntry.nIdcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#nId. = nFID; |
| 2609 | sEntry.fMinXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinX. = rtreeValueDowncxx . . $ rtreeValueDown(2f2c9d02d22c701f).(oEnv.MinX); |
| 2610 | sEntry.fMaxXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxX. = rtreeValueUpcxx . . $ rtreeValueUp(2f2c9d02d22c701f).(oEnv.MaxX); |
| 2611 | sEntry.fMinYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinY. = rtreeValueDowncxx . . $ rtreeValueDown(2f2c9d02d22c701f).(oEnv.MinY); |
| 2612 | sEntry.fMaxYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxY. = rtreeValueUpcxx . . $ rtreeValueUp(2f2c9d02d22c701f).(oEnv.MaxY); |
| 2613 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..push_back(sEntry); |
| 2614 | } |
| 2615 | } |
| 2616 | else if (!bUpsert && m_bAllowedRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bAllowedRTreeThread. && |
| 2617 | !m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread.) |
| 2618 | { |
| 2619 | GPKGRTreeEntrycxx . . $ OGRGeoPackageTableLayer#GPKGRTreeEntry# sEntry; |
| 2620 | #ifdef DEBUG_VERBOSE |
| 2621 | if (m_aoRTreeEntries.empty()) |
| 2622 | CPLDebug("GPKG", |
| 2623 | "Starting to fill m_aoRTreeEntries at " |
| 2624 | "FID " CPL_FRMT_GIB, |
| 2625 | nFID); |
| 2626 | #endif |
| 2627 | sEntry.nIdcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#nId. = nFID; |
| 2628 | sEntry.fMinXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinX. = rtreeValueDowncxx . . $ rtreeValueDown(2f2c9d02d22c701f).(oEnv.MinX); |
| 2629 | sEntry.fMaxXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxX. = rtreeValueUpcxx . . $ rtreeValueUp(2f2c9d02d22c701f).(oEnv.MaxX); |
| 2630 | sEntry.fMinYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinY. = rtreeValueDowncxx . . $ rtreeValueDown(2f2c9d02d22c701f).(oEnv.MinY); |
| 2631 | sEntry.fMaxYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxY. = rtreeValueUpcxx . . $ rtreeValueUp(2f2c9d02d22c701f).(oEnv.MaxY); |
| 2632 | try |
| 2633 | { |
| 2634 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..push_back(sEntry); |
| 2635 | if (m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..size() == m_nRTreeBatchSizecxx . . $ OGRGeoPackageTableLayer#m_nRTreeBatchSize.) |
| 2636 | { |
| 2637 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..pushcxx . . $ cpl/ThreadSafeQueue#push(fe7a8a4d1eddb70).(stdcxx . . $ std/::move(m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.)); |
| 2638 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries. = stdcxx . . $ std/::vector<GPKGRTreeEntrycxx . . $ OGRGeoPackageTableLayer#GPKGRTreeEntry#>(); |
| 2639 | } |
| 2640 | if (!m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted. && |
| 2641 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..sizecxx . . $ cpl/ThreadSafeQueue#size(fe4d2d262d4164a8).() == |
| 2642 | m_nRTreeBatchesBeforeStartcxx . . $ OGRGeoPackageTableLayer#m_nRTreeBatchesBeforeStart.) |
| 2643 | { |
| 2644 | StartAsyncRTreecxx . . $ OGRGeoPackageTableLayer#StartAsyncRTree(49f6e7a06ebc5aa8).(); |
| 2645 | } |
| 2646 | } |
| 2647 | catch (const stdcxx . . $ std/::bad_alloc &) |
| 2648 | { |
| 2649 | CPLDebug("GPKG", |
| 2650 | "Memory allocation error regarding RTree " |
| 2651 | "structures. Falling back to slower method"); |
| 2652 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 2653 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 2654 | else |
| 2655 | m_bAllowedRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bAllowedRTreeThread. = false; |
| 2656 | } |
| 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 2662 | if (m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. >= 0) |
| 2663 | { |
| 2664 | if (m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. < stdcxx . . $ std/::numeric_limits<int64_t>::max()) |
| 2665 | { |
| 2666 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.++; |
| 2667 | } |
| 2668 | else |
| 2669 | { |
| 2670 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 2671 | { |
| 2672 | char *pszSQL = sqlite3_mprintf( |
| 2673 | "UPDATE gpkg_ogr_contents SET feature_count = null " |
| 2674 | "WHERE lower(table_name) = lower('%q')", |
| 2675 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2676 | CPL_IGNORE_RET_VAL(sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, |
| 2677 | nullptr, nullptr)); |
| 2678 | sqlite3_free(pszSQL); |
| 2679 | } |
| 2680 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = -1; |
| 2681 | } |
| 2682 | } |
| 2683 | #endif |
| 2684 | |
| 2685 | m_bContentChangedcxx . . $ OGRGeoPackageTableLayer#m_bContentChanged. = true; |
| 2686 | |
| 2687 | /* All done! */ |
| 2688 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 2689 | } |
| 2690 | |
| 2691 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ICreateFeaturecxx . . $ OGRGeoPackageTableLayer#ICreateFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature) |
| 2692 | { |
| 2693 | return CreateOrUpsertFeaturecxx . . $ OGRGeoPackageTableLayer#CreateOrUpsertFeature(2552997c5ecc345e).(poFeature, /* bUpsert=*/false); |
| 2694 | } |
| 2695 | |
| 2696 | /************************************************************************/ |
| 2697 | /* SetDeferredSpatialIndexCreation() */ |
| 2698 | /************************************************************************/ |
| 2699 | |
| 2700 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#SetDeferredSpatialIndexCreation(b45ddcbc8423892c).(bool bFlag) |
| 2701 | { |
| 2702 | m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation. = bFlag; |
| 2703 | if (bFlag) |
| 2704 | { |
| 2705 | // This method is invoked before the layer is added to the dataset, |
| 2706 | // so GetLayerCount() will return 0 for the first layer added. |
| 2707 | m_bAllowedRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bAllowedRTreeThread. = |
| 2708 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetLayerCountcxx . . $ GDALGeoPackageDataset#GetLayerCount(455f465bc33b4cdf).() == 0 && sqlite3_threadsafe() != 0 && |
| 2709 | CPLGetNumCPUs() >= 2 && |
| 2710 | CPLTestBool( |
| 2711 | CPLGetConfigOption("OGR_GPKG_ALLOW_THREADED_RTREE", "YES")); |
| 2712 | |
| 2713 | // For unit tests |
| 2714 | if (CPLTestBool(CPLGetConfigOption( |
| 2715 | "OGR_GPKG_THREADED_RTREE_AT_FIRST_FEATURE", "NO"))) |
| 2716 | { |
| 2717 | m_nRTreeBatchSizecxx . . $ OGRGeoPackageTableLayer#m_nRTreeBatchSize. = 10; |
| 2718 | m_nRTreeBatchesBeforeStartcxx . . $ OGRGeoPackageTableLayer#m_nRTreeBatchesBeforeStart. = 1; |
| 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | /************************************************************************/ |
| 2724 | /* StartAsyncRTree() */ |
| 2725 | /************************************************************************/ |
| 2726 | |
| 2727 | // We create a temporary database with only the RTree, and we insert |
| 2728 | // records into it in a dedicated thread, in parallel of the main thread |
| 2729 | // that inserts rows in the user table. When the layer is finalized, we |
| 2730 | // just use bulk copy statements of the form |
| 2731 | // INSERT INTO rtree_xxxx_rowid/node/parent SELECT * FROM |
| 2732 | // temp_rtree.my_rtree_rowid/node/parent to copy the RTree auxiliary tables into |
| 2733 | // the main database, which is a very fast operation. |
| 2734 | |
| 2735 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::StartAsyncRTreecxx . . $ OGRGeoPackageTableLayer#StartAsyncRTree(49f6e7a06ebc5aa8).() |
| 2736 | { |
| 2737 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDescriptioncxx . . $ GDALMajorObject#GetDescription(a9f41ea0e82d88cf).(); |
| 2738 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName. += ".tmp_rtree_"; |
| 2739 | bool bCanUseTableName = false; |
| 2740 | if (strlen(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.) <= 32) |
| 2741 | { |
| 2742 | bCanUseTableName = true; |
| 2743 | constexpr char DIGIT_ZERO = '0'; |
| 2744 | for (int i = 0; m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.[i] != '\0'; ++i) |
| 2745 | { |
| 2746 | const char ch = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.[i]; |
| 2747 | if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || |
| 2748 | (ch >= DIGIT_ZERO && ch <= '9') || ch == '.' || ch == '_')) |
| 2749 | { |
| 2750 | bCanUseTableName = false; |
| 2751 | break; |
| 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | if (bCanUseTableName) |
| 2756 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName. += m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 2757 | else |
| 2758 | { |
| 2759 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName. += CPLMD5String(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2760 | } |
| 2761 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName. += ".db"; |
| 2762 | |
| 2763 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName. = "temp_rtree_"; |
| 2764 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName. += CPLMD5String(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 2765 | |
| 2766 | VSIUnlink(m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str()); |
| 2767 | CPLDebug("GPKG", "Creating background RTree DB %s", |
| 2768 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str()); |
| 2769 | if (sqlite3_open_v2(m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str(), &m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., |
| 2770 | SQLITE_OPEN_READWRITEcxx . . $ `<external>/2400532043262193228/sqlite3.h:604:9`! | SQLITE_OPEN_CREATEcxx . . $ `<external>/2400532043262193228/sqlite3.h:605:9`!, |
| 2771 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetVFScxx . . $ OGRSQLiteBaseDataSource#GetVFS(2d0fc68366be6c4f).() ? m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetVFScxx . . $ OGRSQLiteBaseDataSource#GetVFS(2d0fc68366be6c4f).()->zNamecxx . . $ sqlite3_vfs#zName. : nullptr) != |
| 2772 | SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 2773 | { |
| 2774 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "sqlite3_open_v2() of %s failed", |
| 2775 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str()); |
| 2776 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 2777 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 2778 | } |
| 2779 | if (m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. != nullptr) |
| 2780 | { |
| 2781 | /* Make sure our auxiliary DB has the same page size as the main one. |
| 2782 | * Because the number of RTree cells depends on the SQLite page size. |
| 2783 | * However the sqlite implementation limits to 51 cells maximum per page, |
| 2784 | * which is reached starting with a page size of 2048 bytes. |
| 2785 | * As the default SQLite page size is 4096 currently, having potentially |
| 2786 | * different page sizes >= 4096 between the main and auxiliary DBs would |
| 2787 | * not be a practical issue, but better be consistent. |
| 2788 | */ |
| 2789 | const int nPageSize = |
| 2790 | SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "PRAGMA page_size", nullptr); |
| 2791 | |
| 2792 | if (SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., |
| 2793 | CPLSPrintf("PRAGMA page_size = %d;\n" |
| 2794 | "PRAGMA journal_mode = OFF;\n" |
| 2795 | "PRAGMA synchronous = OFF;", |
| 2796 | nPageSize)) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 2797 | { |
| 2798 | char *pszSQL = sqlite3_mprintf("ATTACH DATABASE '%q' AS '%q'", |
| 2799 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str(), |
| 2800 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..c_str()); |
| 2801 | OGRErr eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 2802 | sqlite3_free(pszSQL); |
| 2803 | |
| 2804 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 2805 | { |
| 2806 | m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree. = gdal_sqlite_rtree_bl_new(nPageSize); |
| 2807 | try |
| 2808 | { |
| 2809 | m_oThreadRTreecxx . . $ OGRGeoPackageTableLayer#m_oThreadRTree. =cxx . . $ std/thread#`operator=`(e140d598480f0461). |
| 2810 | stdcxx . . $ std/::threadcxx . . $ std/thread#([this]() { AsyncRTreeThreadFunctioncxx . . $ OGRGeoPackageTableLayer#AsyncRTreeThreadFunction(49f6e7a06ebc5aa8).(); }); |
| 2811 | m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted. = true; |
| 2812 | } |
| 2813 | catch (const stdcxx . . $ std/::exception &e) |
| 2814 | { |
| 2815 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2816 | "RTree thread cannot be created: %s", e.what()); |
| 2817 | } |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | if (!m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 2822 | { |
| 2823 | if (m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.) |
| 2824 | { |
| 2825 | gdal_sqlite_rtree_bl_free(m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.); |
| 2826 | m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree. = nullptr; |
| 2827 | } |
| 2828 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..clearcxx . . $ cpl/ThreadSafeQueue#clear(49f6e7a06ebc5aa8).(); |
| 2829 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 2830 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 2831 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 2832 | VSIUnlink(m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str()); |
| 2833 | } |
| 2834 | } |
| 2835 | else |
| 2836 | { |
| 2837 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..clearcxx . . $ cpl/ThreadSafeQueue#clear(49f6e7a06ebc5aa8).(); |
| 2838 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | /************************************************************************/ |
| 2843 | /* RemoveAsyncRTreeTempDB() */ |
| 2844 | /************************************************************************/ |
| 2845 | |
| 2846 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RemoveAsyncRTreeTempDBcxx . . $ OGRGeoPackageTableLayer#RemoveAsyncRTreeTempDB(49f6e7a06ebc5aa8).() |
| 2847 | { |
| 2848 | if (!m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..empty()) |
| 2849 | { |
| 2850 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).( |
| 2851 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), |
| 2852 | CPLSPrintf("DETACH DATABASE \"%s\"", |
| 2853 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..c_str()).c_str())); |
| 2854 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..clear(); |
| 2855 | VSIUnlink(m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str()); |
| 2856 | m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..clear(); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | /************************************************************************/ |
| 2861 | /* CancelAsyncRTree() */ |
| 2862 | /************************************************************************/ |
| 2863 | |
| 2864 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).() |
| 2865 | { |
| 2866 | CPLDebug("GPKG", "Cancel background RTree creation"); |
| 2867 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..pushcxx . . $ cpl/ThreadSafeQueue#push(fe7a8a4d1eddb70).({}); |
| 2868 | m_oThreadRTreecxx . . $ OGRGeoPackageTableLayer#m_oThreadRTree..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 2869 | m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted. = false; |
| 2870 | if (m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.) |
| 2871 | { |
| 2872 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 2873 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 2874 | } |
| 2875 | gdal_sqlite_rtree_bl_free(m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.); |
| 2876 | m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree. = nullptr; |
| 2877 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 2878 | RemoveAsyncRTreeTempDBcxx . . $ OGRGeoPackageTableLayer#RemoveAsyncRTreeTempDB(49f6e7a06ebc5aa8).(); |
| 2879 | } |
| 2880 | |
| 2881 | /************************************************************************/ |
| 2882 | /* FinishOrDisableThreadedRTree() */ |
| 2883 | /************************************************************************/ |
| 2884 | |
| 2885 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FinishOrDisableThreadedRTreecxx . . $ OGRGeoPackageTableLayer#FinishOrDisableThreadedRTree(49f6e7a06ebc5aa8).() |
| 2886 | { |
| 2887 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 2888 | { |
| 2889 | CreateSpatialIndexIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndexIfNecessary(49f6e7a06ebc5aa8).(); |
| 2890 | } |
| 2891 | m_bAllowedRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bAllowedRTreeThread. = false; |
| 2892 | } |
| 2893 | |
| 2894 | /************************************************************************/ |
| 2895 | /* FlushInMemoryRTree() */ |
| 2896 | /************************************************************************/ |
| 2897 | |
| 2898 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FlushInMemoryRTreecxx . . $ OGRGeoPackageTableLayer#FlushInMemoryRTree(dbc94f338baa5231).(sqlite3 *hRTreeDB, |
| 2899 | const char *pszRTreeName) |
| 2900 | { |
| 2901 | if (hRTreeDB == m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.) |
| 2902 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hRTreeDB, "BEGIN"); |
| 2903 | |
| 2904 | char *pszErrMsg = nullptr; |
| 2905 | bool bRet = gdal_sqlite_rtree_bl_serialize(m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree., hRTreeDB, pszRTreeName, |
| 2906 | "id", "minx", "miny", "maxx", |
| 2907 | "maxy", &pszErrMsg); |
| 2908 | if (hRTreeDB == m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.) |
| 2909 | { |
| 2910 | if (bRet) |
| 2911 | bRet = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hRTreeDB, "COMMIT") == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 2912 | else |
| 2913 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hRTreeDB, "ROLLBACK"); |
| 2914 | } |
| 2915 | |
| 2916 | gdal_sqlite_rtree_bl_free(m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.); |
| 2917 | m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree. = nullptr; |
| 2918 | |
| 2919 | if (!bRet) |
| 2920 | { |
| 2921 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 2922 | "sqlite_rtree_bl_serialize() failed with %s", |
| 2923 | pszErrMsg ? pszErrMsg : "(null)"); |
| 2924 | |
| 2925 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 2926 | |
| 2927 | if (m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.) |
| 2928 | { |
| 2929 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 2930 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 2931 | } |
| 2932 | |
| 2933 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..clearcxx . . $ cpl/ThreadSafeQueue#clear(49f6e7a06ebc5aa8).(); |
| 2934 | } |
| 2935 | sqlite3_free(pszErrMsg); |
| 2936 | |
| 2937 | return bRet; |
| 2938 | } |
| 2939 | |
| 2940 | /************************************************************************/ |
| 2941 | /* GetMaxRAMUsageAllowedForRTree() */ |
| 2942 | /************************************************************************/ |
| 2943 | |
| 2944 | static size_t GetMaxRAMUsageAllowedForRTreecxx . . $ GetMaxRAMUsageAllowedForRTree(f708dce9a8856c70).() |
| 2945 | { |
| 2946 | const uint64_tcxx . . $ uint64_t# nUsableRAM = CPLGetUsablePhysicalRAM(); |
| 2947 | uint64_tcxx . . $ uint64_t# nMaxRAMUsageAllowed = |
| 2948 | (nUsableRAM ? nUsableRAM / 10 : 100 * 1024 * 1024); |
| 2949 | const char *pszMaxRAMUsageAllowed = |
| 2950 | CPLGetConfigOption("OGR_GPKG_MAX_RAM_USAGE_RTREE", nullptr); |
| 2951 | if (pszMaxRAMUsageAllowed) |
| 2952 | { |
| 2953 | nMaxRAMUsageAllowed = static_cast<uint64_tcxx . . $ uint64_t#>( |
| 2954 | stdcxx . . $ std/::strtoull(pszMaxRAMUsageAllowed, nullptr, 10)); |
| 2955 | } |
| 2956 | if (nMaxRAMUsageAllowed > stdcxx . . $ std/::numeric_limits<size_t>::max() - 1U) |
| 2957 | { |
| 2958 | nMaxRAMUsageAllowed = stdcxx . . $ std/::numeric_limits<size_t>::max() - 1U; |
| 2959 | } |
| 2960 | return static_cast<size_t>(nMaxRAMUsageAllowed); |
| 2961 | } |
| 2962 | |
| 2963 | /************************************************************************/ |
| 2964 | /* AsyncRTreeThreadFunction() */ |
| 2965 | /************************************************************************/ |
| 2966 | |
| 2967 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::AsyncRTreeThreadFunctioncxx . . $ OGRGeoPackageTableLayer#AsyncRTreeThreadFunction(49f6e7a06ebc5aa8).() |
| 2968 | { |
| 2969 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(m_hRTree); |
| 2970 | |
| 2971 | const size_t nMaxRAMUsageAllowed = GetMaxRAMUsageAllowedForRTreecxx . . $ GetMaxRAMUsageAllowedForRTree(f708dce9a8856c70).(); |
| 2972 | sqlite3_stmt *hStmt = nullptr; |
| 2973 | GIntBigcxx . . $ GIntBig# nCount = 0; |
| 2974 | while (true) |
| 2975 | { |
| 2976 | const auto aoEntries = m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..get_and_pop_frontcxx . . $ cpl/ThreadSafeQueue#get_and_pop_front(5f357b03ed472e5e).(); |
| 2977 | if (aoEntries.empty()) |
| 2978 | break; |
| 2979 | |
| 2980 | constexpr int NOTIFICATION_INTERVAL = 500 * 1000; |
| 2981 | |
| 2982 | auto oIter = aoEntries.begin(); |
| 2983 | if (m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.) |
| 2984 | { |
| 2985 | for (; oIter != aoEntries.end(); ++oIter) |
| 2986 | { |
| 2987 | const auto &entry = *oIter; |
| 2988 | if (gdal_sqlite_rtree_bl_ram_usage(m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.) > |
| 2989 | nMaxRAMUsageAllowed || |
| 2990 | !gdal_sqlite_rtree_bl_insert(m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree., entry.nIdcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#nId., |
| 2991 | entry.fMinXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinX., entry.fMinYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinY., |
| 2992 | entry.fMaxXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxX., entry.fMaxYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxY.)) |
| 2993 | { |
| 2994 | CPLDebug("GPKG", "Too large in-memory RTree. " |
| 2995 | "Flushing it and using memory friendly " |
| 2996 | "algorithm for the rest"); |
| 2997 | if (!FlushInMemoryRTreecxx . . $ OGRGeoPackageTableLayer#FlushInMemoryRTree(dbc94f338baa5231).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., "my_rtree")) |
| 2998 | return; |
| 2999 | break; |
| 3000 | } |
| 3001 | ++nCount; |
| 3002 | if ((nCount % NOTIFICATION_INTERVAL) == 0) |
| 3003 | { |
| 3004 | CPLDebug("GPKG", CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! " rows indexed in rtree", |
| 3005 | nCount); |
| 3006 | } |
| 3007 | } |
| 3008 | if (oIter == aoEntries.end()) |
| 3009 | continue; |
| 3010 | } |
| 3011 | |
| 3012 | if (hStmt == nullptr) |
| 3013 | { |
| 3014 | const char *pszInsertSQL = |
| 3015 | CPLGetConfigOption( |
| 3016 | "OGR_GPKG_SIMULATE_INSERT_INTO_MY_RTREE_PREPARATION_ERROR", |
| 3017 | nullptr) |
| 3018 | ? "INSERT INTO my_rtree_SIMULATE_ERROR VALUES (?,?,?,?,?)" |
| 3019 | : "INSERT INTO my_rtree VALUES (?,?,?,?,?)"; |
| 3020 | if (SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., pszInsertSQL, -1, &hStmt, |
| 3021 | nullptr) != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3022 | { |
| 3023 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 3024 | |
| 3025 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 3026 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 3027 | |
| 3028 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..clearcxx . . $ cpl/ThreadSafeQueue#clear(49f6e7a06ebc5aa8).(); |
| 3029 | return; |
| 3030 | } |
| 3031 | |
| 3032 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., "BEGIN"); |
| 3033 | } |
| 3034 | |
| 3035 | #ifdef DEBUG_VERBOSE |
| 3036 | CPLDebug("GPKG", |
| 3037 | "AsyncRTreeThreadFunction(): " |
| 3038 | "Processing batch of %d features, " |
| 3039 | "starting at FID " CPL_FRMT_GIB " and ending " |
| 3040 | "at FID " CPL_FRMT_GIB, |
| 3041 | static_cast<int>(aoEntries.size()), aoEntries.front().nId, |
| 3042 | aoEntries.back().nId); |
| 3043 | #endif |
| 3044 | for (; oIter != aoEntries.end(); ++oIter) |
| 3045 | { |
| 3046 | const auto &entry = *oIter; |
| 3047 | sqlite3_reset(hStmt); |
| 3048 | |
| 3049 | sqlite3_bind_int64(hStmt, 1, entry.nIdcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#nId.); |
| 3050 | sqlite3_bind_double(hStmt, 2, entry.fMinXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinX.); |
| 3051 | sqlite3_bind_double(hStmt, 3, entry.fMaxXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxX.); |
| 3052 | sqlite3_bind_double(hStmt, 4, entry.fMinYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinY.); |
| 3053 | sqlite3_bind_double(hStmt, 5, entry.fMaxYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxY.); |
| 3054 | int sqlite_err = sqlite3_step(hStmt); |
| 3055 | if (sqlite_err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`! && sqlite_err != SQLITE_DONEcxx . . $ `<external>/2400532043262193228/sqlite3.h:480:9`!) |
| 3056 | { |
| 3057 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 3058 | "failed to execute insertion in RTree : %s", |
| 3059 | sqlite3_errmsg(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.)); |
| 3060 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 3061 | break; |
| 3062 | } |
| 3063 | ++nCount; |
| 3064 | if ((nCount % NOTIFICATION_INTERVAL) == 0) |
| 3065 | { |
| 3066 | CPLDebug("GPKG", CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! " rows indexed in rtree", nCount); |
| 3067 | if (SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., "COMMIT") != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3068 | { |
| 3069 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 3070 | break; |
| 3071 | } |
| 3072 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., "BEGIN"); |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | if (!m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.) |
| 3077 | { |
| 3078 | if (m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread.) |
| 3079 | { |
| 3080 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., "ROLLBACK"); |
| 3081 | } |
| 3082 | else if (SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle., "COMMIT") != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3083 | { |
| 3084 | m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread. = true; |
| 3085 | } |
| 3086 | |
| 3087 | sqlite3_finalize(hStmt); |
| 3088 | |
| 3089 | if (m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread.) |
| 3090 | { |
| 3091 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 3092 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 3093 | |
| 3094 | VSIUnlink(m_osAsyncDBNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBName..c_str()); |
| 3095 | |
| 3096 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..clearcxx . . $ cpl/ThreadSafeQueue#clear(49f6e7a06ebc5aa8).(); |
| 3097 | } |
| 3098 | } |
| 3099 | CPLDebug("GPKG", |
| 3100 | "AsyncRTreeThreadFunction(): " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! |
| 3101 | " rows inserted into RTree", |
| 3102 | nCount); |
| 3103 | } |
| 3104 | |
| 3105 | /************************************************************************/ |
| 3106 | /* ISetFeature() */ |
| 3107 | /************************************************************************/ |
| 3108 | |
| 3109 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ISetFeaturecxx . . $ OGRGeoPackageTableLayer#ISetFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature) |
| 3110 | { |
| 3111 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3112 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 3113 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() || m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr) |
| 3114 | { |
| 3115 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY., |
| 3116 | "SetFeature"); |
| 3117 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3118 | } |
| 3119 | |
| 3120 | /* No FID? */ |
| 3121 | if (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) |
| 3122 | { |
| 3123 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 3124 | "FID required on features given to SetFeature()."); |
| 3125 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3126 | } |
| 3127 | |
| 3128 | /* In case the FID column has also been created as a regular field */ |
| 3129 | if (m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0 && |
| 3130 | !CheckFIDAndFIDColumnConsistencycxx . . $ CheckFIDAndFIDColumnConsistency(760bd0252d02a09d).(poFeature, m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.)) |
| 3131 | { |
| 3132 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3133 | } |
| 3134 | |
| 3135 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3136 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3137 | |
| 3138 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 3139 | |
| 3140 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 3141 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 3142 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 3143 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3144 | |
| 3145 | const sqlite3_int64 nTotalChangesBefore = |
| 3146 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3037000L |
| 3147 | sqlite3_total_changes64(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 3148 | #else |
| 3149 | sqlite3_total_changes(m_poDS->GetDB()); |
| 3150 | #endif |
| 3151 | |
| 3152 | CheckGeometryTypecxx . . $ OGRGeoPackageTableLayer#CheckGeometryType(c79b2f12299c1ae2).(poFeature); |
| 3153 | |
| 3154 | if (!m_osUpdateStatementSQLcxx . . $ OGRGeoPackageTableLayer#m_osUpdateStatementSQL..empty()) |
| 3155 | { |
| 3156 | m_osUpdateStatementSQLcxx . . $ OGRGeoPackageTableLayer#m_osUpdateStatementSQL..clear(); |
| 3157 | if (m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.) |
| 3158 | sqlite3_finalize(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3159 | m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement. = nullptr; |
| 3160 | } |
| 3161 | if (!m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.) |
| 3162 | { |
| 3163 | /* Construct a SQL UPDATE statement from the OGRFeature */ |
| 3164 | /* Only work with fields that are set */ |
| 3165 | /* Do not stick values into SQL, use placeholder and bind values later |
| 3166 | */ |
| 3167 | const stdcxx . . $ std/::string osCommand = FeatureGenerateUpdateSQLcxx . . $ OGRGeoPackageTableLayer#FeatureGenerateUpdateSQL(8b7d08ed93ae3f3a).(poFeature); |
| 3168 | if (osCommand.empty()) |
| 3169 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 3170 | |
| 3171 | /* Prepare the SQL into a statement */ |
| 3172 | int err = SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osCommand.c_str(), |
| 3173 | static_cast<int>(osCommand.size()), |
| 3174 | &m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement., nullptr); |
| 3175 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3176 | { |
| 3177 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | /* Bind values onto the statement now */ |
| 3182 | OGRErr errOgr = FeatureBindUpdateParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindUpdateParameters(280a200759cc63a1).(poFeature, m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3183 | if (errOgr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3184 | { |
| 3185 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3186 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3187 | return errOgr; |
| 3188 | } |
| 3189 | |
| 3190 | /* From here execute the statement and check errors */ |
| 3191 | int err = sqlite3_step(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3192 | if (!(err == SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`! || err == SQLITE_DONEcxx . . $ `<external>/2400532043262193228/sqlite3.h:480:9`!)) |
| 3193 | { |
| 3194 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "failed to execute update : %s", |
| 3195 | sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).())); |
| 3196 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3197 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3198 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3199 | } |
| 3200 | |
| 3201 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3202 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3203 | |
| 3204 | const sqlite3_int64 nTotalChangesAfter = |
| 3205 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3037000L |
| 3206 | sqlite3_total_changes64(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 3207 | #else |
| 3208 | sqlite3_total_changes(m_poDS->GetDB()); |
| 3209 | #endif |
| 3210 | |
| 3211 | /* Only update the envelope if we changed something */ |
| 3212 | OGRErr eErr = nTotalChangesAfter != nTotalChangesBefore |
| 3213 | ? OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! |
| 3214 | : OGRERR_NON_EXISTING_FEATUREcxx . . $ `ogr/ogr_core.h:399:9`!; |
| 3215 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3216 | { |
| 3217 | /* Update the layer extents with this new object */ |
| 3218 | if (IsGeomFieldSetcxx . . $ OGRGeoPackageTableLayer#IsGeomFieldSet(9d38d33a35b5766a).(poFeature)) |
| 3219 | { |
| 3220 | OGRGeometrycxx . . $ OGRGeometry# *poGeom = poFeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(0); |
| 3221 | if (!poGeom->IsEmptycxx . . $ OGRGeometry#IsEmpty(455f465bc33b4cdf).()) |
| 3222 | { |
| 3223 | OGREnvelope oEnv; |
| 3224 | poGeom->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&oEnv); |
| 3225 | UpdateExtentcxx . . $ OGRGeoPackageTableLayer#UpdateExtent(6720dbbe3ac92137).(&oEnv); |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | m_bContentChangedcxx . . $ OGRGeoPackageTableLayer#m_bContentChanged. = true; |
| 3230 | } |
| 3231 | |
| 3232 | /* All done! */ |
| 3233 | return eErr; |
| 3234 | } |
| 3235 | |
| 3236 | /************************************************************************/ |
| 3237 | /* IUpsertFeature() */ |
| 3238 | /************************************************************************/ |
| 3239 | |
| 3240 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::IUpsertFeaturecxx . . $ OGRGeoPackageTableLayer#IUpsertFeature(2048609adab03aab).(OGRFeaturecxx . . $ OGRFeature# *poFeature) |
| 3241 | |
| 3242 | { |
| 3243 | return CreateOrUpsertFeaturecxx . . $ OGRGeoPackageTableLayer#CreateOrUpsertFeature(2552997c5ecc345e).(poFeature, /* bUpsert = */ true); |
| 3244 | } |
| 3245 | |
| 3246 | //---------------------------------------------------------------------- |
| 3247 | // FeatureGenerateUpdateSQL() |
| 3248 | // |
| 3249 | // Build a SQL UPDATE statement that references all the columns in |
| 3250 | // the OGRFeatureDefn that the user asked to be updated, then prepare it for |
| 3251 | // repeated use in a prepared statement. All statements start off with geometry |
| 3252 | // (if it exists, and if it is asked to be updated), then reference each column |
| 3253 | // in the order it appears in the OGRFeatureDefn. |
| 3254 | // FeatureBindParameters operates on the expectation of this |
| 3255 | // column ordering. |
| 3256 | |
| 3257 | // |
| 3258 | stdcxx . . $ std/::string OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FeatureGenerateUpdateSQLcxx . . $ OGRGeoPackageTableLayer#FeatureGenerateUpdateSQL(f326ec8caab1d9c2).( |
| 3259 | const OGRFeaturecxx . . $ OGRFeature# *poFeature, int nUpdatedFieldsCount, |
| 3260 | const int *panUpdatedFieldsIdx, int nUpdatedGeomFieldsCount, |
| 3261 | const int * /*panUpdatedGeomFieldsIdx*/) const |
| 3262 | { |
| 3263 | bool bNeedComma = false; |
| 3264 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *poFeatureDefn = poFeature->GetDefnRefcxx . . $ OGRFeature#GetDefnRef(448b209f43d15bcc).(); |
| 3265 | |
| 3266 | /* Set up our SQL string basics */ |
| 3267 | stdcxx . . $ std/::string osUpdate("UPDATE \""); |
| 3268 | osUpdate += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 3269 | osUpdate += "\" SET "; |
| 3270 | |
| 3271 | if (nUpdatedGeomFieldsCount == 1 && poFeatureDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() > 0) |
| 3272 | { |
| 3273 | osUpdate += '"'; |
| 3274 | osUpdate += |
| 3275 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 3276 | osUpdate += "\"=?"; |
| 3277 | bNeedComma = true; |
| 3278 | } |
| 3279 | |
| 3280 | /* Add attribute column names (except FID) to the SQL */ |
| 3281 | for (int i = 0; i < nUpdatedFieldsCount; i++) |
| 3282 | { |
| 3283 | const int iField = panUpdatedFieldsIdx[i]; |
| 3284 | if (iField == m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. || |
| 3285 | poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(iField)->IsGeneratedcxx . . $ OGRFieldDefn#IsGenerated(50ce9a9e25b4a850).()) |
| 3286 | continue; |
| 3287 | if (!poFeature->IsFieldSetcxx . . $ OGRFeature#IsFieldSet(7ccb52b1bfe01045).(iField)) |
| 3288 | continue; |
| 3289 | if (!bNeedComma) |
| 3290 | bNeedComma = true; |
| 3291 | else |
| 3292 | osUpdate += ", "; |
| 3293 | |
| 3294 | osUpdate += '"'; |
| 3295 | osUpdate += |
| 3296 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFeatureDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(53a8093e6b73def).(iField)->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 3297 | osUpdate += "\"=?"; |
| 3298 | } |
| 3299 | if (!bNeedComma) |
| 3300 | return CPLString(); |
| 3301 | |
| 3302 | osUpdate += " WHERE \""; |
| 3303 | osUpdate += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 3304 | osUpdate += "\" = ?"; |
| 3305 | |
| 3306 | return osUpdate; |
| 3307 | } |
| 3308 | |
| 3309 | /************************************************************************/ |
| 3310 | /* UpdateFeature() */ |
| 3311 | /************************************************************************/ |
| 3312 | |
| 3313 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::IUpdateFeaturecxx . . $ OGRGeoPackageTableLayer#IUpdateFeature(81c9b962c9c18011).( |
| 3314 | OGRFeaturecxx . . $ OGRFeature# *poFeature, int nUpdatedFieldsCount, |
| 3315 | const int *panUpdatedFieldsIdx, int nUpdatedGeomFieldsCount, |
| 3316 | const int *panUpdatedGeomFieldsIdx, bool /* bUpdateStyleString*/) |
| 3317 | |
| 3318 | { |
| 3319 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3320 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 3321 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() || m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr) |
| 3322 | { |
| 3323 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY., |
| 3324 | "UpdateFeature"); |
| 3325 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3326 | } |
| 3327 | |
| 3328 | /* No FID? */ |
| 3329 | if (poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).() == OGRNullFIDcxx . . $ `ogr/ogr_core.h:848:9`!) |
| 3330 | { |
| 3331 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 3332 | "FID required on features given to SetFeature()."); |
| 3333 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3334 | } |
| 3335 | |
| 3336 | /* In case the FID column has also been created as a regular field */ |
| 3337 | if (m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0 && |
| 3338 | !CheckFIDAndFIDColumnConsistencycxx . . $ CheckFIDAndFIDColumnConsistency(760bd0252d02a09d).(poFeature, m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.)) |
| 3339 | { |
| 3340 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3341 | } |
| 3342 | |
| 3343 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3344 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3345 | |
| 3346 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 3347 | |
| 3348 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 3349 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 3350 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 3351 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3352 | |
| 3353 | CheckGeometryTypecxx . . $ OGRGeoPackageTableLayer#CheckGeometryType(c79b2f12299c1ae2).(poFeature); |
| 3354 | |
| 3355 | /* Construct a SQL UPDATE statement from the OGRFeature */ |
| 3356 | /* Only work with fields that are set */ |
| 3357 | /* Do not stick values into SQL, use placeholder and bind values later |
| 3358 | */ |
| 3359 | stdcxx . . $ std/::string osUpdateStatementSQL = FeatureGenerateUpdateSQLcxx . . $ OGRGeoPackageTableLayer#FeatureGenerateUpdateSQL(f326ec8caab1d9c2).( |
| 3360 | poFeature, nUpdatedFieldsCount, panUpdatedFieldsIdx, |
| 3361 | nUpdatedGeomFieldsCount, panUpdatedGeomFieldsIdx); |
| 3362 | if (osUpdateStatementSQL.empty()) |
| 3363 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 3364 | |
| 3365 | if (m_osUpdateStatementSQLcxx . . $ OGRGeoPackageTableLayer#m_osUpdateStatementSQL. != osUpdateStatementSQL) |
| 3366 | { |
| 3367 | if (m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.) |
| 3368 | sqlite3_finalize(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3369 | m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement. = nullptr; |
| 3370 | /* Prepare the SQL into a statement */ |
| 3371 | int err = |
| 3372 | SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osUpdateStatementSQL.c_str(), |
| 3373 | static_cast<int>(osUpdateStatementSQL.size()), |
| 3374 | &m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement., nullptr); |
| 3375 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3376 | { |
| 3377 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3378 | } |
| 3379 | m_osUpdateStatementSQLcxx . . $ OGRGeoPackageTableLayer#m_osUpdateStatementSQL. = stdcxx . . $ std/::move(osUpdateStatementSQL); |
| 3380 | } |
| 3381 | |
| 3382 | /* Bind values onto the statement now */ |
| 3383 | int nColCount = 0; |
| 3384 | const OGRErr errOgr = |
| 3385 | FeatureBindParameterscxx . . $ OGRGeoPackageTableLayer#FeatureBindParameters(9088abe2cac88272).(poFeature, m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement., &nColCount, false, |
| 3386 | false, nUpdatedFieldsCount, panUpdatedFieldsIdx, |
| 3387 | nUpdatedGeomFieldsCount, panUpdatedGeomFieldsIdx); |
| 3388 | if (errOgr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3389 | { |
| 3390 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3391 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3392 | return errOgr; |
| 3393 | } |
| 3394 | |
| 3395 | // Bind the FID to the "WHERE" clause. |
| 3396 | const int sqlite_err = |
| 3397 | sqlite3_bind_int64(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement., nColCount, poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()); |
| 3398 | if (sqlite_err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3399 | { |
| 3400 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 3401 | "failed to bind FID '" CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! "' to statement", |
| 3402 | poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()); |
| 3403 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3404 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3405 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3406 | } |
| 3407 | |
| 3408 | const sqlite3_int64 nTotalChangesBefore = |
| 3409 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3037000L |
| 3410 | sqlite3_total_changes64(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 3411 | #else |
| 3412 | sqlite3_total_changes(m_poDS->GetDB()); |
| 3413 | #endif |
| 3414 | |
| 3415 | /* From here execute the statement and check errors */ |
| 3416 | int err = sqlite3_step(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3417 | if (!(err == SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`! || err == SQLITE_DONEcxx . . $ `<external>/2400532043262193228/sqlite3.h:480:9`!)) |
| 3418 | { |
| 3419 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "failed to execute update : %s", |
| 3420 | sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).())); |
| 3421 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3422 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3423 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3424 | } |
| 3425 | |
| 3426 | sqlite3_reset(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3427 | sqlite3_clear_bindings(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3428 | |
| 3429 | const sqlite3_int64 nTotalChangesAfter = |
| 3430 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3037000L |
| 3431 | sqlite3_total_changes64(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 3432 | #else |
| 3433 | sqlite3_total_changes(m_poDS->GetDB()); |
| 3434 | #endif |
| 3435 | |
| 3436 | /* Only update the envelope if we changed something */ |
| 3437 | OGRErr eErr = nTotalChangesAfter != nTotalChangesBefore |
| 3438 | ? OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! |
| 3439 | : OGRERR_NON_EXISTING_FEATUREcxx . . $ `ogr/ogr_core.h:399:9`!; |
| 3440 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3441 | { |
| 3442 | /* Update the layer extents with this new object */ |
| 3443 | if (nUpdatedGeomFieldsCount == 1 && IsGeomFieldSetcxx . . $ OGRGeoPackageTableLayer#IsGeomFieldSet(9d38d33a35b5766a).(poFeature)) |
| 3444 | { |
| 3445 | OGRGeometrycxx . . $ OGRGeometry# *poGeom = poFeature->GetGeomFieldRefcxx . . $ OGRFeature#GetGeomFieldRef(ea443ccec24c6360).(0); |
| 3446 | if (!poGeom->IsEmptycxx . . $ OGRGeometry#IsEmpty(455f465bc33b4cdf).()) |
| 3447 | { |
| 3448 | OGREnvelope oEnv; |
| 3449 | poGeom->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&oEnv); |
| 3450 | UpdateExtentcxx . . $ OGRGeoPackageTableLayer#UpdateExtent(6720dbbe3ac92137).(&oEnv); |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | m_bContentChangedcxx . . $ OGRGeoPackageTableLayer#m_bContentChanged. = true; |
| 3455 | } |
| 3456 | |
| 3457 | /* All done! */ |
| 3458 | return eErr; |
| 3459 | } |
| 3460 | |
| 3461 | /************************************************************************/ |
| 3462 | /* SetAttributeFilter() */ |
| 3463 | /************************************************************************/ |
| 3464 | |
| 3465 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetAttributeFiltercxx . . $ OGRGeoPackageTableLayer#SetAttributeFilter(5c4306d8553b3696).(const char *pszQuery) |
| 3466 | |
| 3467 | { |
| 3468 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3469 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 3470 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString.); |
| 3471 | m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. = (pszQuery) ? CPLStrdup(pszQuery) : nullptr; |
| 3472 | |
| 3473 | if (pszQuery == nullptr) |
| 3474 | osQuerycxx . . $ OGRGeoPackageTableLayer#osQuery. = ""; |
| 3475 | else |
| 3476 | osQuerycxx . . $ OGRGeoPackageTableLayer#osQuery. = pszQuery; |
| 3477 | |
| 3478 | BuildWherecxx . . $ OGRGeoPackageTableLayer#BuildWhere(49f6e7a06ebc5aa8).(); |
| 3479 | |
| 3480 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 3481 | |
| 3482 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 3483 | } |
| 3484 | |
| 3485 | /************************************************************************/ |
| 3486 | /* ResetReading() */ |
| 3487 | /************************************************************************/ |
| 3488 | |
| 3489 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).() |
| 3490 | { |
| 3491 | m_bEOFcxx . . $ OGRGeoPackageLayer#m_bEOF. = false; |
| 3492 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3493 | return; |
| 3494 | |
| 3495 | OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#::ResetReadingcxx . . $ OGRGeoPackageLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 3496 | |
| 3497 | if (m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.) |
| 3498 | { |
| 3499 | sqlite3_finalize(m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement.); |
| 3500 | m_poInsertStatementcxx . . $ OGRGeoPackageTableLayer#m_poInsertStatement. = nullptr; |
| 3501 | } |
| 3502 | |
| 3503 | if (m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.) |
| 3504 | { |
| 3505 | sqlite3_finalize(m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement.); |
| 3506 | m_poUpdateStatementcxx . . $ OGRGeoPackageTableLayer#m_poUpdateStatement. = nullptr; |
| 3507 | } |
| 3508 | m_osUpdateStatementSQLcxx . . $ OGRGeoPackageTableLayer#m_osUpdateStatementSQL..clear(); |
| 3509 | |
| 3510 | if (m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.) |
| 3511 | { |
| 3512 | sqlite3_finalize(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3513 | m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement. = nullptr; |
| 3514 | } |
| 3515 | |
| 3516 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 3517 | |
| 3518 | m_bGetNextArrowArrayCalledSinceResetReadingcxx . . $ OGRGeoPackageTableLayer#m_bGetNextArrowArrayCalledSinceResetReading. = false; |
| 3519 | |
| 3520 | BuildColumnscxx . . $ OGRGeoPackageTableLayer#BuildColumns(b126dc7c1de90089).(); |
| 3521 | } |
| 3522 | |
| 3523 | /************************************************************************/ |
| 3524 | /* SetNextByIndex() */ |
| 3525 | /************************************************************************/ |
| 3526 | |
| 3527 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetNextByIndexcxx . . $ OGRGeoPackageTableLayer#SetNextByIndex(a070d6d14e988596).(GIntBigcxx . . $ GIntBig# nIndex) |
| 3528 | { |
| 3529 | if (nIndex < 0) |
| 3530 | { |
| 3531 | m_bEOFcxx . . $ OGRGeoPackageLayer#m_bEOF. = true; |
| 3532 | return OGRERR_NON_EXISTING_FEATUREcxx . . $ `ogr/ogr_core.h:399:9`!; |
| 3533 | } |
| 3534 | if (m_soColumnscxx . . $ OGRGeoPackageTableLayer#m_soColumns..empty()) |
| 3535 | BuildColumnscxx . . $ OGRGeoPackageTableLayer#BuildColumns(b126dc7c1de90089).(); |
| 3536 | return ResetStatementInternalcxx . . $ OGRGeoPackageTableLayer#ResetStatementInternal(a070d6d14e988596).(nIndex); |
| 3537 | } |
| 3538 | |
| 3539 | /************************************************************************/ |
| 3540 | /* ResetStatement() */ |
| 3541 | /************************************************************************/ |
| 3542 | |
| 3543 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ResetStatementcxx . . $ OGRGeoPackageTableLayer#ResetStatement(b126dc7c1de90089).() |
| 3544 | |
| 3545 | { |
| 3546 | return ResetStatementInternalcxx . . $ OGRGeoPackageTableLayer#ResetStatementInternal(a070d6d14e988596).(0); |
| 3547 | } |
| 3548 | |
| 3549 | /************************************************************************/ |
| 3550 | /* ResetStatementInternal() */ |
| 3551 | /************************************************************************/ |
| 3552 | |
| 3553 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ResetStatementInternalcxx . . $ OGRGeoPackageTableLayer#ResetStatementInternal(a070d6d14e988596).(GIntBigcxx . . $ GIntBig# nStartIndex) |
| 3554 | |
| 3555 | { |
| 3556 | ClearStatementcxx . . $ OGRGeoPackageLayer#ClearStatement(49f6e7a06ebc5aa8).(); |
| 3557 | |
| 3558 | /* There is no active query statement set up, */ |
| 3559 | /* so job #1 is to prepare the statement. */ |
| 3560 | /* Append the attribute filter, if there is one */ |
| 3561 | CPLString soSQL; |
| 3562 | if (!m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty()) |
| 3563 | { |
| 3564 | soSQL.Printf("SELECT %s FROM \"%s\" m WHERE %s", m_soColumnscxx . . $ OGRGeoPackageTableLayer#m_soColumns..c_str(), |
| 3565 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..c_str()); |
| 3566 | |
| 3567 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr && m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. == nullptr && |
| 3568 | HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 3569 | { |
| 3570 | OGREnvelope sEnvelope; |
| 3571 | |
| 3572 | m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom.->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&sEnvelope); |
| 3573 | |
| 3574 | bool bUseSpatialIndex = true; |
| 3575 | if (m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. && sEnvelope.MinX <= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinX && |
| 3576 | sEnvelope.MinY <= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinY && |
| 3577 | sEnvelope.MaxX >= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxX && |
| 3578 | sEnvelope.MaxY >= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxY) |
| 3579 | { |
| 3580 | // Selecting from spatial filter on whole extent can be rather |
| 3581 | // slow. So use function based filtering, just in case the |
| 3582 | // advertized global extent might be wrong. Otherwise we might |
| 3583 | // just discard completely the spatial filter. |
| 3584 | bUseSpatialIndex = false; |
| 3585 | } |
| 3586 | |
| 3587 | if (bUseSpatialIndex && !stdcxx . . $ std/::isinf(sEnvelope.MinX) && |
| 3588 | !stdcxx . . $ std/::isinf(sEnvelope.MinY) && !stdcxx . . $ std/::isinf(sEnvelope.MaxX) && |
| 3589 | !stdcxx . . $ std/::isinf(sEnvelope.MaxY)) |
| 3590 | { |
| 3591 | soSQL.Printf("SELECT %s FROM \"%s\" m " |
| 3592 | "JOIN \"%s\" r " |
| 3593 | "ON m.\"%s\" = r.id WHERE " |
| 3594 | "r.maxx >= %.12f AND r.minx <= %.12f AND " |
| 3595 | "r.maxy >= %.12f AND r.miny <= %.12f", |
| 3596 | m_soColumnscxx . . $ OGRGeoPackageTableLayer#m_soColumns..c_str(), |
| 3597 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 3598 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.).c_str(), |
| 3599 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree.).c_str(), |
| 3600 | sEnvelope.MinX - 1e-11, sEnvelope.MaxX + 1e-11, |
| 3601 | sEnvelope.MinY - 1e-11, sEnvelope.MaxY + 1e-11); |
| 3602 | } |
| 3603 | } |
| 3604 | } |
| 3605 | else |
| 3606 | soSQL.Printf("SELECT %s FROM \"%s\" m", m_soColumnscxx . . $ OGRGeoPackageTableLayer#m_soColumns..c_str(), |
| 3607 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str()); |
| 3608 | if (nStartIndex > 0) |
| 3609 | { |
| 3610 | soSQL += CPLSPrintf(" LIMIT -1 OFFSET " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, nStartIndex); |
| 3611 | } |
| 3612 | |
| 3613 | CPLDebug("GPKG", "ResetStatement(%s)", soSQL.c_str()); |
| 3614 | |
| 3615 | int err = SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), soSQL.c_str(), -1, |
| 3616 | &m_poQueryStatementcxx . . $ OGRGeoPackageLayer#m_poQueryStatement., nullptr); |
| 3617 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3618 | { |
| 3619 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3620 | } |
| 3621 | |
| 3622 | m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. = nStartIndex; |
| 3623 | m_bGetNextArrowArrayCalledSinceResetReadingcxx . . $ OGRGeoPackageTableLayer#m_bGetNextArrowArrayCalledSinceResetReading. = false; |
| 3624 | |
| 3625 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 3626 | } |
| 3627 | |
| 3628 | /************************************************************************/ |
| 3629 | /* GetNextFeature() */ |
| 3630 | /************************************************************************/ |
| 3631 | |
| 3632 | OGRFeaturecxx . . $ OGRFeature# *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetNextFeaturecxx . . $ OGRGeoPackageTableLayer#GetNextFeature(ec9eceddec1d9563).() |
| 3633 | { |
| 3634 | if (m_bEOFcxx . . $ OGRGeoPackageLayer#m_bEOF.) |
| 3635 | return nullptr; |
| 3636 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3637 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 3638 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3639 | return nullptr; |
| 3640 | |
| 3641 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 3642 | |
| 3643 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr) |
| 3644 | { |
| 3645 | // Both are exclusive |
| 3646 | CreateSpatialIndexIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndexIfNecessary(49f6e7a06ebc5aa8).(); |
| 3647 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 3648 | return nullptr; |
| 3649 | } |
| 3650 | |
| 3651 | OGRFeaturecxx . . $ OGRFeature# *poFeature = OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#::GetNextFeaturecxx . . $ OGRGeoPackageLayer#GetNextFeature(ec9eceddec1d9563).(); |
| 3652 | if (poFeature && m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0) |
| 3653 | { |
| 3654 | poFeature->SetFieldcxx . . $ OGRFeature#SetField(9ffed314a0a4f263).(m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex., poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()); |
| 3655 | } |
| 3656 | return poFeature; |
| 3657 | } |
| 3658 | |
| 3659 | /************************************************************************/ |
| 3660 | /* GetFeature() */ |
| 3661 | /************************************************************************/ |
| 3662 | |
| 3663 | OGRFeaturecxx . . $ OGRFeature# *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetFeaturecxx . . $ OGRGeoPackageTableLayer#GetFeature(86ac52c37891ada7).(GIntBigcxx . . $ GIntBig# nFID) |
| 3664 | { |
| 3665 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3666 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 3667 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3668 | return nullptr; |
| 3669 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 3670 | |
| 3671 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr) |
| 3672 | return OGRLayercxx . . $ OGRLayer#::GetFeaturecxx . . $ OGRLayer#GetFeature(86ac52c37891ada7).(nFID); |
| 3673 | |
| 3674 | if (m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement. == nullptr) |
| 3675 | { |
| 3676 | CPLString soSQL; |
| 3677 | soSQL.Printf("SELECT %s FROM \"%s\" m " |
| 3678 | "WHERE \"%s\" = ?", |
| 3679 | m_soColumnscxx . . $ OGRGeoPackageTableLayer#m_soColumns..c_str(), SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 3680 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.).c_str()); |
| 3681 | |
| 3682 | const int err = SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), soSQL.c_str(), -1, |
| 3683 | &m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement., nullptr); |
| 3684 | if (err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3685 | { |
| 3686 | return nullptr; |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | CPL_IGNORE_RET_VAL(sqlite3_bind_int64(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement., 1, nFID)); |
| 3691 | |
| 3692 | /* Should be only one or zero results */ |
| 3693 | const int err = sqlite3_step(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3694 | |
| 3695 | /* Aha, got one */ |
| 3696 | if (err == SQLITE_ROWcxx . . $ `<external>/2400532043262193228/sqlite3.h:479:9`!) |
| 3697 | { |
| 3698 | OGRFeaturecxx . . $ OGRFeature# *poFeature = TranslateFeaturecxx . . $ OGRGeoPackageLayer#TranslateFeature(9324c33e54292d5b).(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3699 | if (m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex. >= 0) |
| 3700 | { |
| 3701 | poFeature->SetFieldcxx . . $ OGRFeature#SetField(9ffed314a0a4f263).(m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex., |
| 3702 | poFeature->GetFIDcxx . . $ OGRFeature#GetFID(98833e9ab7de59a4).()); |
| 3703 | } |
| 3704 | |
| 3705 | sqlite3_reset(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3706 | sqlite3_clear_bindings(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3707 | |
| 3708 | return poFeature; |
| 3709 | } |
| 3710 | |
| 3711 | sqlite3_reset(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3712 | sqlite3_clear_bindings(m_poGetFeatureStatementcxx . . $ OGRGeoPackageTableLayer#m_poGetFeatureStatement.); |
| 3713 | |
| 3714 | /* Error out on all other return codes */ |
| 3715 | return nullptr; |
| 3716 | } |
| 3717 | |
| 3718 | /************************************************************************/ |
| 3719 | /* DeleteFeature() */ |
| 3720 | /************************************************************************/ |
| 3721 | |
| 3722 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DeleteFeaturecxx . . $ OGRGeoPackageTableLayer#DeleteFeature(a070d6d14e988596).(GIntBigcxx . . $ GIntBig# nFID) |
| 3723 | { |
| 3724 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3725 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 3726 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).()) |
| 3727 | { |
| 3728 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY., |
| 3729 | "DeleteFeature"); |
| 3730 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3731 | } |
| 3732 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr) |
| 3733 | { |
| 3734 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3735 | } |
| 3736 | |
| 3737 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3738 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3739 | |
| 3740 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 3741 | |
| 3742 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 3743 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 3744 | |
| 3745 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 3746 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3747 | |
| 3748 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 3749 | if (m_bOGRFeatureCountTriggersEnabledcxx . . $ OGRGeoPackageTableLayer#m_bOGRFeatureCountTriggersEnabled.) |
| 3750 | { |
| 3751 | DisableFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#DisableFeatureCountTriggers(b45ddcbc8423892c).(); |
| 3752 | } |
| 3753 | #endif |
| 3754 | |
| 3755 | /* Clear out any existing query */ |
| 3756 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 3757 | |
| 3758 | /* No filters apply, just use the FID */ |
| 3759 | CPLString soSQL; |
| 3760 | soSQL.Printf("DELETE FROM \"%s\" WHERE \"%s\" = " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, |
| 3761 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 3762 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.).c_str(), nFID); |
| 3763 | |
| 3764 | const sqlite3_int64 nTotalChangesBefore = |
| 3765 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3037000L |
| 3766 | sqlite3_total_changes64(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 3767 | #else |
| 3768 | sqlite3_total_changes(m_poDS->GetDB()); |
| 3769 | #endif |
| 3770 | |
| 3771 | OGRErr eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), soSQL.c_str()); |
| 3772 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3773 | { |
| 3774 | const sqlite3_int64 nTotalChangesAfter = |
| 3775 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3037000L |
| 3776 | sqlite3_total_changes64(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 3777 | #else |
| 3778 | sqlite3_total_changes(m_poDS->GetDB()); |
| 3779 | #endif |
| 3780 | |
| 3781 | eErr = nTotalChangesAfter != nTotalChangesBefore |
| 3782 | ? OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! |
| 3783 | : OGRERR_NON_EXISTING_FEATUREcxx . . $ `ogr/ogr_core.h:399:9`!; |
| 3784 | |
| 3785 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3786 | { |
| 3787 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 3788 | if (m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. >= 0) |
| 3789 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.--; |
| 3790 | #endif |
| 3791 | |
| 3792 | m_bContentChangedcxx . . $ OGRGeoPackageTableLayer#m_bContentChanged. = true; |
| 3793 | } |
| 3794 | } |
| 3795 | return eErr; |
| 3796 | } |
| 3797 | |
| 3798 | /************************************************************************/ |
| 3799 | /* DoJobAtTransactionCommit() */ |
| 3800 | /************************************************************************/ |
| 3801 | |
| 3802 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DoJobAtTransactionCommitcxx . . $ OGRGeoPackageTableLayer#DoJobAtTransactionCommit(c9857a73d68e59ba).() |
| 3803 | { |
| 3804 | if (m_bAllowedRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bAllowedRTreeThread.) |
| 3805 | return true; |
| 3806 | |
| 3807 | bool ret = RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && |
| 3808 | RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).(); |
| 3809 | m_nCountInsertInTransactioncxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransaction. = 0; |
| 3810 | m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..clear(); |
| 3811 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..clear(); |
| 3812 | return ret; |
| 3813 | } |
| 3814 | |
| 3815 | /************************************************************************/ |
| 3816 | /* DoJobAtTransactionRollback() */ |
| 3817 | /************************************************************************/ |
| 3818 | |
| 3819 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DoJobAtTransactionRollbackcxx . . $ OGRGeoPackageTableLayer#DoJobAtTransactionRollback(c9857a73d68e59ba).() |
| 3820 | { |
| 3821 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 3822 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 3823 | m_nCountInsertInTransactioncxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransaction. = 0; |
| 3824 | m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..clear(); |
| 3825 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..clear(); |
| 3826 | if (m_bTableCreatedInTransactioncxx . . $ OGRGeoPackageTableLayer#m_bTableCreatedInTransaction.) |
| 3827 | { |
| 3828 | SyncToDiskcxx . . $ OGRGeoPackageTableLayer#SyncToDisk(b126dc7c1de90089).(); |
| 3829 | } |
| 3830 | else |
| 3831 | { |
| 3832 | bool bDeferredSpatialIndexCreationBackup = |
| 3833 | m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation.; |
| 3834 | m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation. = false; |
| 3835 | SyncToDiskcxx . . $ OGRGeoPackageTableLayer#SyncToDisk(b126dc7c1de90089).(); |
| 3836 | m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation. = bDeferredSpatialIndexCreationBackup; |
| 3837 | } |
| 3838 | |
| 3839 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 3840 | return true; |
| 3841 | } |
| 3842 | |
| 3843 | /************************************************************************/ |
| 3844 | /* StartDeferredSpatialIndexUpdate() */ |
| 3845 | /************************************************************************/ |
| 3846 | |
| 3847 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::StartDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#StartDeferredSpatialIndexUpdate(c9857a73d68e59ba).() |
| 3848 | { |
| 3849 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 0) |
| 3850 | return true; |
| 3851 | |
| 3852 | RevertWorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#RevertWorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).(); |
| 3853 | |
| 3854 | m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..clear(); |
| 3855 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..clear(); |
| 3856 | |
| 3857 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 3858 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 3859 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = "rtree_"; |
| 3860 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszT; |
| 3861 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += "_"; |
| 3862 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszC; |
| 3863 | |
| 3864 | char *pszSQL = sqlite3_mprintf( |
| 3865 | "SELECT sql FROM sqlite_master WHERE type = 'trigger' " |
| 3866 | "AND name IN ('%q', '%q', '%q', '%q', '%q', '%q', " |
| 3867 | "'%q', '%q', '%q')", |
| 3868 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_insert").c_str(), |
| 3869 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update1").c_str(), |
| 3870 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update2").c_str(), |
| 3871 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update3").c_str(), |
| 3872 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update4").c_str(), |
| 3873 | // update5 replaces update3 in GPKG 1.4 |
| 3874 | // cf https://github.com/opengeospatial/geopackage/pull/661 |
| 3875 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update5").c_str(), |
| 3876 | // update6 and update7 replace update1 in GPKG 1.4 |
| 3877 | // cf https://github.com/opengeospatial/geopackage/pull/661 |
| 3878 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update6").c_str(), |
| 3879 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update7").c_str(), |
| 3880 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_delete").c_str()); |
| 3881 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 3882 | sqlite3_free(pszSQL); |
| 3883 | if (oResult) |
| 3884 | { |
| 3885 | for (int iRecord = 0; iRecord < oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); iRecord++) |
| 3886 | { |
| 3887 | const char *pszTriggerSQL = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, iRecord); |
| 3888 | if (pszTriggerSQL) |
| 3889 | { |
| 3890 | m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..push_back(pszTriggerSQL); |
| 3891 | } |
| 3892 | } |
| 3893 | } |
| 3894 | if (m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..size() != 6 && m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..size() != 7) |
| 3895 | { |
| 3896 | CPLDebug("GPKG", "Could not find expected RTree triggers"); |
| 3897 | m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..clear(); |
| 3898 | return false; |
| 3899 | } |
| 3900 | |
| 3901 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), ReturnSQLDropSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLDropSpatialIndexTriggers(cdfd1e859161399b).()); |
| 3902 | |
| 3903 | return true; |
| 3904 | } |
| 3905 | |
| 3906 | /************************************************************************/ |
| 3907 | /* FlushPendingSpatialIndexUpdate() */ |
| 3908 | /************************************************************************/ |
| 3909 | |
| 3910 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::FlushPendingSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#FlushPendingSpatialIndexUpdate(c9857a73d68e59ba).() |
| 3911 | { |
| 3912 | bool ret = true; |
| 3913 | |
| 3914 | // CPLDebug("GPKG", "Insert %d features in spatial index", |
| 3915 | // static_cast<int>(m_aoRTreeEntries.size())); |
| 3916 | |
| 3917 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 3918 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 3919 | |
| 3920 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = "rtree_"; |
| 3921 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszT; |
| 3922 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += "_"; |
| 3923 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszC; |
| 3924 | |
| 3925 | char *pszSQL = sqlite3_mprintf("INSERT INTO \"%w\" VALUES (?,?,?,?,?)", |
| 3926 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 3927 | sqlite3_stmt *hInsertStmt = nullptr; |
| 3928 | if (SQLPrepareWithErrorcxx . . $ SQLPrepareWithError(e684c70afc08ac0a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, -1, &hInsertStmt, |
| 3929 | nullptr) != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 3930 | { |
| 3931 | sqlite3_free(pszSQL); |
| 3932 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..clear(); |
| 3933 | return false; |
| 3934 | } |
| 3935 | sqlite3_free(pszSQL); |
| 3936 | |
| 3937 | for (size_t i = 0; i < m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..size(); ++i) |
| 3938 | { |
| 3939 | sqlite3_reset(hInsertStmt); |
| 3940 | |
| 3941 | sqlite3_bind_int64(hInsertStmt, 1, m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.[i].nIdcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#nId.); |
| 3942 | sqlite3_bind_double(hInsertStmt, 2, m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.[i].fMinXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinX.); |
| 3943 | sqlite3_bind_double(hInsertStmt, 3, m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.[i].fMaxXcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxX.); |
| 3944 | sqlite3_bind_double(hInsertStmt, 4, m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.[i].fMinYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMinY.); |
| 3945 | sqlite3_bind_double(hInsertStmt, 5, m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.[i].fMaxYcxx . . $ OGRGeoPackageTableLayer#$anonymous_type_1#fMaxY.); |
| 3946 | int sqlite_err = sqlite3_step(hInsertStmt); |
| 3947 | if (sqlite_err != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`! && sqlite_err != SQLITE_DONEcxx . . $ `<external>/2400532043262193228/sqlite3.h:480:9`!) |
| 3948 | { |
| 3949 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 3950 | "failed to execute insertion in RTree : %s", |
| 3951 | sqlite3_errmsg(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).())); |
| 3952 | ret = false; |
| 3953 | break; |
| 3954 | } |
| 3955 | } |
| 3956 | sqlite3_finalize(hInsertStmt); |
| 3957 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..clear(); |
| 3958 | return ret; |
| 3959 | } |
| 3960 | |
| 3961 | /************************************************************************/ |
| 3962 | /* RunDeferredSpatialIndexUpdate() */ |
| 3963 | /************************************************************************/ |
| 3964 | |
| 3965 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).() |
| 3966 | { |
| 3967 | m_nCountInsertInTransactioncxx . . $ OGRGeoPackageTableLayer#m_nCountInsertInTransaction. = 0; |
| 3968 | if (m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..empty()) |
| 3969 | return true; |
| 3970 | |
| 3971 | bool ret = FlushPendingSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#FlushPendingSpatialIndexUpdate(c9857a73d68e59ba).(); |
| 3972 | |
| 3973 | RevertWorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#RevertWorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).(); |
| 3974 | |
| 3975 | for (const auto &osSQL : m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL.) |
| 3976 | { |
| 3977 | ret &= SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 3978 | } |
| 3979 | m_aoRTreeTriggersSQLcxx . . $ OGRGeoPackageTableLayer#m_aoRTreeTriggersSQL..clear(); |
| 3980 | return ret; |
| 3981 | } |
| 3982 | |
| 3983 | /************************************************************************/ |
| 3984 | /* SyncToDisk() */ |
| 3985 | /************************************************************************/ |
| 3986 | |
| 3987 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SyncToDiskcxx . . $ OGRGeoPackageTableLayer#SyncToDisk(b126dc7c1de90089).() |
| 3988 | { |
| 3989 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 3990 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 3991 | |
| 3992 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 3993 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3994 | |
| 3995 | // Both are exclusive |
| 3996 | CreateSpatialIndexIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndexIfNecessary(49f6e7a06ebc5aa8).(); |
| 3997 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 3998 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 3999 | RevertWorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#RevertWorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).(); |
| 4000 | |
| 4001 | /* Save metadata back to the database */ |
| 4002 | SaveExtentcxx . . $ OGRGeoPackageTableLayer#SaveExtent(b126dc7c1de90089).(); |
| 4003 | SaveTimestampcxx . . $ OGRGeoPackageTableLayer#SaveTimestamp(b126dc7c1de90089).(); |
| 4004 | |
| 4005 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 4006 | CreateFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#CreateFeatureCountTriggers(85c52e162fed56f9).(); |
| 4007 | #endif |
| 4008 | |
| 4009 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 4010 | } |
| 4011 | |
| 4012 | /************************************************************************/ |
| 4013 | /* StartTransaction() */ |
| 4014 | /************************************************************************/ |
| 4015 | |
| 4016 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::StartTransactioncxx . . $ OGRGeoPackageTableLayer#StartTransaction(b126dc7c1de90089).() |
| 4017 | { |
| 4018 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 4019 | return m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->StartTransactioncxx . . $ OGRSQLiteBaseDataSource#StartTransaction(7864480464b09eea).(); |
| 4020 | } |
| 4021 | |
| 4022 | /************************************************************************/ |
| 4023 | /* CommitTransaction() */ |
| 4024 | /************************************************************************/ |
| 4025 | |
| 4026 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CommitTransactioncxx . . $ OGRGeoPackageTableLayer#CommitTransaction(b126dc7c1de90089).() |
| 4027 | { |
| 4028 | return m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->CommitTransactioncxx . . $ GDALGeoPackageDataset#CommitTransaction(b126dc7c1de90089).(); |
| 4029 | } |
| 4030 | |
| 4031 | /************************************************************************/ |
| 4032 | /* RollbackTransaction() */ |
| 4033 | /************************************************************************/ |
| 4034 | |
| 4035 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RollbackTransactioncxx . . $ OGRGeoPackageTableLayer#RollbackTransaction(b126dc7c1de90089).() |
| 4036 | { |
| 4037 | return m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->RollbackTransactioncxx . . $ GDALGeoPackageDataset#RollbackTransaction(b126dc7c1de90089).(); |
| 4038 | } |
| 4039 | |
| 4040 | /************************************************************************/ |
| 4041 | /* GetTotalFeatureCount() */ |
| 4042 | /************************************************************************/ |
| 4043 | |
| 4044 | GIntBigcxx . . $ GIntBig# OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#GetTotalFeatureCount(a5d9f2bf8849668d).() |
| 4045 | { |
| 4046 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 4047 | if (m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. < 0 && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 4048 | { |
| 4049 | char *pszSQL = |
| 4050 | sqlite3_mprintf("SELECT feature_count FROM gpkg_ogr_contents WHERE " |
| 4051 | "lower(table_name) = lower('%q') LIMIT 2", |
| 4052 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 4053 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4054 | sqlite3_free(pszSQL); |
| 4055 | if (oResult && oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 1) |
| 4056 | { |
| 4057 | const char *pszFeatureCount = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, 0); |
| 4058 | if (pszFeatureCount) |
| 4059 | { |
| 4060 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = |
| 4061 | stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).<GIntBigcxx . . $ GIntBig#>(0, CPLAtoGIntBig(pszFeatureCount)); |
| 4062 | // According to https://sqlite.org/limits.html |
| 4063 | // "A 281 terabytes database can hold no more than approximately 2e+13 rows" |
| 4064 | // We do that check to avoid returning values close to INT64_MAX |
| 4065 | if (m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. > |
| 4066 | static_cast<GIntBigcxx . . $ GIntBig#>(30) * 1000 * 1000 * 1000 * 1000) |
| 4067 | { |
| 4068 | CPLDebug("GPKG", "Invalid value in feature_count field of " |
| 4069 | "gpkg_ogr_contents"); |
| 4070 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = -1; |
| 4071 | } |
| 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | return m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.; |
| 4076 | #else |
| 4077 | return 0; |
| 4078 | #endif |
| 4079 | } |
| 4080 | |
| 4081 | /************************************************************************/ |
| 4082 | /* GetFeatureCount() */ |
| 4083 | /************************************************************************/ |
| 4084 | |
| 4085 | GIntBigcxx . . $ GIntBig# OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetFeatureCountcxx . . $ OGRGeoPackageTableLayer#GetFeatureCount(9ccc33c3ebad048d).(int /*bForce*/) |
| 4086 | { |
| 4087 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 4088 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 4089 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 4090 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr && m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. == nullptr) |
| 4091 | { |
| 4092 | const auto nCount = GetTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#GetTotalFeatureCount(a5d9f2bf8849668d).(); |
| 4093 | if (nCount >= 0) |
| 4094 | return nCount; |
| 4095 | } |
| 4096 | #endif |
| 4097 | |
| 4098 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4099 | return 0; |
| 4100 | |
| 4101 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 4102 | |
| 4103 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr) |
| 4104 | { |
| 4105 | // Both are exclusive |
| 4106 | CreateSpatialIndexIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndexIfNecessary(49f6e7a06ebc5aa8).(); |
| 4107 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 4108 | return -1; |
| 4109 | } |
| 4110 | |
| 4111 | /* Ignore bForce, because we always do a full count on the database */ |
| 4112 | OGRErr err; |
| 4113 | CPLString soSQL; |
| 4114 | bool bUnregisterSQLFunction = false; |
| 4115 | if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. && m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr && |
| 4116 | m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. == nullptr && HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 4117 | { |
| 4118 | OGREnvelope sEnvelope; |
| 4119 | |
| 4120 | m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom.->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&sEnvelope); |
| 4121 | |
| 4122 | if (!stdcxx . . $ std/::isinf(sEnvelope.MinX) && !stdcxx . . $ std/::isinf(sEnvelope.MinY) && |
| 4123 | !stdcxx . . $ std/::isinf(sEnvelope.MaxX) && !stdcxx . . $ std/::isinf(sEnvelope.MaxY)) |
| 4124 | { |
| 4125 | soSQL.Printf("SELECT COUNT(*) FROM \"%s\" WHERE " |
| 4126 | "maxx >= %.12f AND minx <= %.12f AND " |
| 4127 | "maxy >= %.12f AND miny <= %.12f", |
| 4128 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.).c_str(), |
| 4129 | sEnvelope.MinX - 1e-11, sEnvelope.MaxX + 1e-11, |
| 4130 | sEnvelope.MinY - 1e-11, sEnvelope.MaxY + 1e-11); |
| 4131 | |
| 4132 | if (OGRGeometryFactorycxx . . $ OGRGeometryFactory#::haveGEOScxx . . $ OGRGeometryFactory#haveGEOS(c9857a73d68e59ba).() && |
| 4133 | !(m_bFilterIsEnvelopecxx . . $ OGRLayer#m_bFilterIsEnvelope. && |
| 4134 | wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!( |
| 4135 | m_poFeatureDefn->GetGeomFieldDefn(m_iGeomFieldFilter) |
| 4136 | ->GetType()) == wkbPoint)) |
| 4137 | { |
| 4138 | bUnregisterSQLFunction = true; |
| 4139 | sqlite3_create_function( |
| 4140 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., "OGR_GPKG_Intersects_Spatial_Filter", 1, |
| 4141 | SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`!, this, OGR_GPKG_Intersects_Spatial_Filtercxx . . $ OGR_GPKG_Intersects_Spatial_Filter(77c4cd3acce4959d)., |
| 4142 | nullptr, nullptr); |
| 4143 | const char *pszC = |
| 4144 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(m_iGeomFieldFiltercxx . . $ OGRLayer#m_iGeomFieldFilter.) |
| 4145 | ->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 4146 | soSQL.Printf("SELECT COUNT(*) FROM \"%s\" m " |
| 4147 | "JOIN \"%s\" r " |
| 4148 | "ON m.\"%s\" = r.id WHERE " |
| 4149 | "r.maxx >= %.12f AND r.minx <= %.12f AND " |
| 4150 | "r.maxy >= %.12f AND r.miny <= %.12f AND " |
| 4151 | "OGR_GPKG_Intersects_Spatial_Filter(m.\"%s\")", |
| 4152 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 4153 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.).c_str(), |
| 4154 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree.).c_str(), |
| 4155 | sEnvelope.MinX - 1e-11, sEnvelope.MaxX + 1e-11, |
| 4156 | sEnvelope.MinY - 1e-11, sEnvelope.MaxY + 1e-11, |
| 4157 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC).c_str()); |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | if (soSQL.empty()) |
| 4163 | { |
| 4164 | if (!m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty()) |
| 4165 | soSQL.Printf("SELECT Count(*) FROM \"%s\" WHERE %s", |
| 4166 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 4167 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..c_str()); |
| 4168 | else |
| 4169 | soSQL.Printf("SELECT Count(*) FROM \"%s\"", |
| 4170 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str()); |
| 4171 | } |
| 4172 | |
| 4173 | /* Just run the query directly and get back integer */ |
| 4174 | GIntBigcxx . . $ GIntBig# iFeatureCount = |
| 4175 | SQLGetInteger64cxx . . $ SQLGetInteger64(c8fc3d71eb4a6aab).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), soSQL.c_str(), &err); |
| 4176 | |
| 4177 | if (bUnregisterSQLFunction) |
| 4178 | { |
| 4179 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., |
| 4180 | "OGR_GPKG_Intersects_Spatial_Filter", 1, |
| 4181 | SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`!, this, nullptr, nullptr, nullptr); |
| 4182 | } |
| 4183 | |
| 4184 | /* Generic implementation uses -1 for error condition, so we will too */ |
| 4185 | if (err == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4186 | { |
| 4187 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 4188 | if (m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. && m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr && |
| 4189 | m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. == nullptr) |
| 4190 | { |
| 4191 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = iFeatureCount; |
| 4192 | |
| 4193 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 4194 | { |
| 4195 | const char *pszCount = |
| 4196 | CPLSPrintf(CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.); |
| 4197 | char *pszSQL = sqlite3_mprintf( |
| 4198 | "UPDATE gpkg_ogr_contents SET feature_count = %s WHERE " |
| 4199 | "lower(table_name )= lower('%q')", |
| 4200 | pszCount, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 4201 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4202 | sqlite3_free(pszSQL); |
| 4203 | } |
| 4204 | } |
| 4205 | #endif |
| 4206 | return iFeatureCount; |
| 4207 | } |
| 4208 | else |
| 4209 | return -1; |
| 4210 | } |
| 4211 | |
| 4212 | /************************************************************************/ |
| 4213 | /* GetExtentFromRTree() */ |
| 4214 | /************************************************************************/ |
| 4215 | |
| 4216 | static bool GetExtentFromRTreecxx . . $ GetExtentFromRTree(a6706b96113a0024).(sqlite3 *hDB, const stdcxx . . $ std/::string &osRTreeName, |
| 4217 | double &minx, double &miny, double &maxx, |
| 4218 | double &maxy) |
| 4219 | { |
| 4220 | // Cf https://github.com/sqlite/sqlite/blob/master/ext/rtree/rtree.c |
| 4221 | // for the description of the content of the rtree _node table |
| 4222 | // We fetch the root node (nodeno = 1) and iterates over its cells, to |
| 4223 | // take the min/max of their minx/maxx/miny/maxy values. |
| 4224 | char *pszSQL = sqlite3_mprintf( |
| 4225 | "SELECT data FROM \"%w_node\" WHERE nodeno = 1", osRTreeName.c_str()); |
| 4226 | sqlite3_stmt *hStmt = nullptr; |
| 4227 | CPL_IGNORE_RET_VAL(sqlite3_prepare_v2(hDB, pszSQL, -1, &hStmt, nullptr)); |
| 4228 | sqlite3_free(pszSQL); |
| 4229 | bool bOK = false; |
| 4230 | if (hStmt) |
| 4231 | { |
| 4232 | if (sqlite3_step(hStmt) == SQLITE_ROWcxx . . $ `<external>/2400532043262193228/sqlite3.h:479:9`! && |
| 4233 | sqlite3_column_type(hStmt, 0) == SQLITE_BLOBcxx . . $ `<external>/2400532043262193228/sqlite3.h:5358:9`!) |
| 4234 | { |
| 4235 | const int nBytes = sqlite3_column_bytes(hStmt, 0); |
| 4236 | // coverity[tainted_data_return] |
| 4237 | const GBytecxx . . $ GByte# *pabyData = |
| 4238 | static_cast<const GBytecxx . . $ GByte# *>(sqlite3_column_blob(hStmt, 0)); |
| 4239 | constexpr int BLOB_HEADER_SIZE = 4; |
| 4240 | if (nBytes > BLOB_HEADER_SIZE) |
| 4241 | { |
| 4242 | const int nCellCount = (pabyData[2] << 8) | pabyData[3]; |
| 4243 | constexpr int SIZEOF_CELL = 24; // int64_t + 4 float |
| 4244 | if (nCellCount >= 1 && |
| 4245 | nBytes >= BLOB_HEADER_SIZE + SIZEOF_CELL * nCellCount) |
| 4246 | { |
| 4247 | minx = stdcxx . . $ std/::numeric_limits<double>::max(); |
| 4248 | miny = stdcxx . . $ std/::numeric_limits<double>::max(); |
| 4249 | maxx = -stdcxx . . $ std/::numeric_limits<double>::max(); |
| 4250 | maxy = -stdcxx . . $ std/::numeric_limits<double>::max(); |
| 4251 | size_t offset = BLOB_HEADER_SIZE; |
| 4252 | for (int i = 0; i < nCellCount; ++i) |
| 4253 | { |
| 4254 | offset += sizeof(int64_t); |
| 4255 | |
| 4256 | float fMinX; |
| 4257 | memcpy(&fMinX, pabyData + offset, sizeof(float)); |
| 4258 | offset += sizeof(float); |
| 4259 | CPL_MSBPTR32cxx . . $ `port/cpl_port.h:765:9`!(&fMinX); |
| 4260 | minx = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(minx, static_cast<double>(fMinX)); |
| 4261 | |
| 4262 | float fMaxX; |
| 4263 | memcpy(&fMaxX, pabyData + offset, sizeof(float)); |
| 4264 | offset += sizeof(float); |
| 4265 | CPL_MSBPTR32cxx . . $ `port/cpl_port.h:765:9`!(&fMaxX); |
| 4266 | maxx = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(maxx, static_cast<double>(fMaxX)); |
| 4267 | |
| 4268 | float fMinY; |
| 4269 | memcpy(&fMinY, pabyData + offset, sizeof(float)); |
| 4270 | offset += sizeof(float); |
| 4271 | CPL_MSBPTR32cxx . . $ `port/cpl_port.h:765:9`!(&fMinY); |
| 4272 | miny = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(miny, static_cast<double>(fMinY)); |
| 4273 | |
| 4274 | float fMaxY; |
| 4275 | memcpy(&fMaxY, pabyData + offset, sizeof(float)); |
| 4276 | offset += sizeof(float); |
| 4277 | CPL_MSBPTR32cxx . . $ `port/cpl_port.h:765:9`!(&fMaxY); |
| 4278 | maxy = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(maxy, static_cast<double>(fMaxY)); |
| 4279 | } |
| 4280 | |
| 4281 | bOK = true; |
| 4282 | } |
| 4283 | } |
| 4284 | } |
| 4285 | sqlite3_finalize(hStmt); |
| 4286 | } |
| 4287 | return bOK; |
| 4288 | } |
| 4289 | |
| 4290 | /************************************************************************/ |
| 4291 | /* IGetExtent() */ |
| 4292 | /************************************************************************/ |
| 4293 | |
| 4294 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::IGetExtentcxx . . $ OGRGeoPackageTableLayer#IGetExtent(ee9c866093418aa0).(int /* iGeomField */, |
| 4295 | OGREnvelope *psExtent, bool bForce) |
| 4296 | { |
| 4297 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 4298 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 4299 | /* Extent already calculated! We're done. */ |
| 4300 | if (m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. != nullptr) |
| 4301 | { |
| 4302 | if (psExtent) |
| 4303 | { |
| 4304 | *psExtent = *m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.; |
| 4305 | } |
| 4306 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 4307 | } |
| 4308 | |
| 4309 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4310 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 4311 | |
| 4312 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 4313 | |
| 4314 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() && HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).() && |
| 4315 | CPLTestBool( |
| 4316 | CPLGetConfigOption("OGR_GPKG_USE_RTREE_FOR_GET_EXTENT", "TRUE"))) |
| 4317 | { |
| 4318 | if (GetExtentFromRTreecxx . . $ GetExtentFromRTree(a6706b96113a0024).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName., psExtent->MinX, |
| 4319 | psExtent->MinY, psExtent->MaxX, psExtent->MaxY)) |
| 4320 | { |
| 4321 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. = stdcxx . . $ std/::make_unique<OGREnvelope>(*psExtent); |
| 4322 | m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. = true; |
| 4323 | SaveExtentcxx . . $ OGRGeoPackageTableLayer#SaveExtent(b126dc7c1de90089).(); |
| 4324 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 4325 | } |
| 4326 | else |
| 4327 | { |
| 4328 | UpdateContentsToNullExtentcxx . . $ OGRGeoPackageTableLayer#UpdateContentsToNullExtent(49f6e7a06ebc5aa8).(); |
| 4329 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | /* User is OK with expensive calculation */ |
| 4334 | if (bForce && m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 4335 | { |
| 4336 | /* fall back to default implementation (scan all features) and save */ |
| 4337 | /* the result for later */ |
| 4338 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 4339 | char *pszSQL = sqlite3_mprintf( |
| 4340 | "SELECT MIN(ST_MinX(\"%w\")), MIN(ST_MinY(\"%w\")), " |
| 4341 | "MAX(ST_MaxX(\"%w\")), MAX(ST_MaxY(\"%w\")) FROM \"%w\" WHERE " |
| 4342 | "\"%w\" IS NOT NULL AND NOT ST_IsEmpty(\"%w\")", |
| 4343 | pszC, pszC, pszC, pszC, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszC, pszC); |
| 4344 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4345 | sqlite3_free(pszSQL); |
| 4346 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent..reset(); |
| 4347 | if (oResult && oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 1 && |
| 4348 | oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, 0) != nullptr) |
| 4349 | { |
| 4350 | psExtent->MinX = CPLAtof(oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, 0)); |
| 4351 | psExtent->MinY = CPLAtof(oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, 0)); |
| 4352 | psExtent->MaxX = CPLAtof(oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, 0)); |
| 4353 | psExtent->MaxY = CPLAtof(oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(3, 0)); |
| 4354 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. = stdcxx . . $ std/::make_unique<OGREnvelope>(*psExtent); |
| 4355 | m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. = true; |
| 4356 | SaveExtentcxx . . $ OGRGeoPackageTableLayer#SaveExtent(b126dc7c1de90089).(); |
| 4357 | } |
| 4358 | else |
| 4359 | { |
| 4360 | UpdateContentsToNullExtentcxx . . $ OGRGeoPackageTableLayer#UpdateContentsToNullExtent(49f6e7a06ebc5aa8).(); |
| 4361 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; // we didn't get an extent |
| 4362 | } |
| 4363 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 4364 | } |
| 4365 | |
| 4366 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 4367 | } |
| 4368 | |
| 4369 | /************************************************************************/ |
| 4370 | /* UpdateContentsToNullExtent() */ |
| 4371 | /************************************************************************/ |
| 4372 | |
| 4373 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::UpdateContentsToNullExtentcxx . . $ OGRGeoPackageTableLayer#UpdateContentsToNullExtent(49f6e7a06ebc5aa8).() |
| 4374 | { |
| 4375 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).()) |
| 4376 | { |
| 4377 | char *pszSQL = |
| 4378 | sqlite3_mprintf("UPDATE gpkg_contents SET " |
| 4379 | "min_x = NULL, min_y = NULL, " |
| 4380 | "max_x = NULL, max_y = NULL " |
| 4381 | "WHERE lower(table_name) = lower('%q') AND " |
| 4382 | "Lower(data_type) = 'features'", |
| 4383 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 4384 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4385 | sqlite3_free(pszSQL); |
| 4386 | } |
| 4387 | m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. = false; |
| 4388 | } |
| 4389 | |
| 4390 | /************************************************************************/ |
| 4391 | /* RecomputeExtent() */ |
| 4392 | /************************************************************************/ |
| 4393 | |
| 4394 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RecomputeExtentcxx . . $ OGRGeoPackageTableLayer#RecomputeExtent(49f6e7a06ebc5aa8).() |
| 4395 | { |
| 4396 | m_bExtentChangedcxx . . $ OGRGeoPackageTableLayer#m_bExtentChanged. = true; |
| 4397 | m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent..reset(); |
| 4398 | OGREnvelope sExtent; |
| 4399 | CPL_IGNORE_RET_VAL(GetExtentcxx . . $ OGRLayer#GetExtent(9e34be741bca56d4).(&sExtent, true)); |
| 4400 | } |
| 4401 | |
| 4402 | /************************************************************************/ |
| 4403 | /* TestCapability() */ |
| 4404 | /************************************************************************/ |
| 4405 | |
| 4406 | int OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::TestCapabilitycxx . . $ OGRGeoPackageTableLayer#TestCapability(78f035161ffa9fe2).(const char *pszCap) const |
| 4407 | { |
| 4408 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 4409 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 4410 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCSequentialWritecxx . . $ `ogr/ogr_core.h:978:9`!)) |
| 4411 | { |
| 4412 | return m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).(); |
| 4413 | } |
| 4414 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCCreateFieldcxx . . $ `ogr/ogr_core.h:990:9`!) || EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCDeleteFieldcxx . . $ `ogr/ogr_core.h:993:9`!) || |
| 4415 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCAlterFieldDefncxx . . $ `ogr/ogr_core.h:998:9`!) || |
| 4416 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCAlterGeomFieldDefncxx . . $ `ogr/ogr_core.h:1000:9`!) || |
| 4417 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCReorderFieldscxx . . $ `ogr/ogr_core.h:996:9`!) || EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCRenamecxx . . $ `ogr/ogr_core.h:1031:9`!)) |
| 4418 | { |
| 4419 | return m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() && m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.; |
| 4420 | } |
| 4421 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCDeleteFeaturecxx . . $ `ogr/ogr_core.h:1006:9`!) || |
| 4422 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCUpsertFeaturecxx . . $ `ogr/ogr_core.h:1008:9`!) || |
| 4423 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCUpdateFeaturecxx . . $ `ogr/ogr_core.h:1010:9`!) || EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCRandomWritecxx . . $ `ogr/ogr_core.h:980:9`!)) |
| 4424 | { |
| 4425 | return m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() && m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr; |
| 4426 | } |
| 4427 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCRandomReadcxx . . $ `ogr/ogr_core.h:977:9`!)) |
| 4428 | { |
| 4429 | return m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr; |
| 4430 | } |
| 4431 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCTransactionscxx . . $ `ogr/ogr_core.h:1003:9`!)) |
| 4432 | { |
| 4433 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 4434 | } |
| 4435 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 4436 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastFeatureCountcxx . . $ `ogr/ogr_core.h:983:9`!)) |
| 4437 | { |
| 4438 | return m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. == nullptr && m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. == nullptr && |
| 4439 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. >= 0; |
| 4440 | } |
| 4441 | #endif |
| 4442 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastSpatialFiltercxx . . $ `ogr/ogr_core.h:981:9`!)) |
| 4443 | { |
| 4444 | return HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).() || m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation.; |
| 4445 | } |
| 4446 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastSetNextByIndexcxx . . $ `ogr/ogr_core.h:1013:9`!)) |
| 4447 | { |
| 4448 | // Fast may not be that true on large layers, but better than the |
| 4449 | // default implementation for sure... |
| 4450 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 4451 | } |
| 4452 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastGetExtentcxx . . $ `ogr/ogr_core.h:986:9`!)) |
| 4453 | { |
| 4454 | return (m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. != nullptr); |
| 4455 | } |
| 4456 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCCurveGeometriescxx . . $ `ogr/ogr_core.h:1023:9`!)) |
| 4457 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 4458 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCMeasuredGeometriescxx . . $ `ogr/ogr_core.h:1025:9`!)) |
| 4459 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 4460 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCZGeometriescxx . . $ `ogr/ogr_core.h:1028:9`!)) |
| 4461 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 4462 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszCap, OLCFastGetExtent3Dcxx . . $ `ogr/ogr_core.h:988:9`!)) |
| 4463 | return TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 4464 | else |
| 4465 | { |
| 4466 | return OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#::TestCapabilitycxx . . $ OGRGeoPackageLayer#TestCapability(78f035161ffa9fe2).(pszCap); |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | /************************************************************************/ |
| 4471 | /* CreateSpatialIndexIfNecessary() */ |
| 4472 | /************************************************************************/ |
| 4473 | |
| 4474 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateSpatialIndexIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndexIfNecessary(49f6e7a06ebc5aa8).() |
| 4475 | { |
| 4476 | if (m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation.) |
| 4477 | { |
| 4478 | CreateSpatialIndexcxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndex(c5f7da30cbc0f4e9).(); |
| 4479 | } |
| 4480 | } |
| 4481 | |
| 4482 | /************************************************************************/ |
| 4483 | /* CreateSpatialIndex() */ |
| 4484 | /************************************************************************/ |
| 4485 | |
| 4486 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateSpatialIndexcxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndex(c5f7da30cbc0f4e9).(const char *pszTableName) |
| 4487 | { |
| 4488 | OGRErr err; |
| 4489 | |
| 4490 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 4491 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 4492 | |
| 4493 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("CreateSpatialIndex")) |
| 4494 | return false; |
| 4495 | |
| 4496 | if (m_bDropRTreeTablecxx . . $ OGRGeoPackageTableLayer#m_bDropRTreeTable.) |
| 4497 | { |
| 4498 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 4499 | "Cannot run CreateSpatialIndex() after non-completed deferred " |
| 4500 | "DropSpatialIndex()"); |
| 4501 | return false; |
| 4502 | } |
| 4503 | |
| 4504 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4505 | return false; |
| 4506 | |
| 4507 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 4508 | |
| 4509 | m_bDeferredSpatialIndexCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredSpatialIndexCreation. = false; |
| 4510 | |
| 4511 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr) |
| 4512 | return false; |
| 4513 | |
| 4514 | if (HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 4515 | { |
| 4516 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Spatial index already existing"); |
| 4517 | return false; |
| 4518 | } |
| 4519 | |
| 4520 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 0) |
| 4521 | { |
| 4522 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "No geometry column"); |
| 4523 | return false; |
| 4524 | } |
| 4525 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->CreateExtensionsTableIfNecessarycxx . . $ GDALGeoPackageDataset#CreateExtensionsTableIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4526 | return false; |
| 4527 | |
| 4528 | const char *pszT = (pszTableName) ? pszTableName : m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 4529 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 4530 | const char *pszI = GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).(); |
| 4531 | |
| 4532 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = "rtree_"; |
| 4533 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszT; |
| 4534 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += "_"; |
| 4535 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszC; |
| 4536 | m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree. = m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.; |
| 4537 | |
| 4538 | bool bPopulateFromThreadRTree = false; |
| 4539 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 4540 | { |
| 4541 | const bool bThreadHasFinished = m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..emptycxx . . $ cpl/ThreadSafeQueue#empty(50ce9a9e25b4a850).(); |
| 4542 | if (!m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries..empty()) |
| 4543 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..pushcxx . . $ cpl/ThreadSafeQueue#push(fe7a8a4d1eddb70).(stdcxx . . $ std/::move(m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.)); |
| 4544 | m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries. = stdcxx . . $ std/::vector<GPKGRTreeEntrycxx . . $ OGRGeoPackageTableLayer#GPKGRTreeEntry#>(); |
| 4545 | m_oQueueRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_oQueueRTreeEntries..pushcxx . . $ cpl/ThreadSafeQueue#push(77d9f17553126ecb).(m_aoRTreeEntriescxx . . $ OGRGeoPackageTableLayer#m_aoRTreeEntries.); |
| 4546 | if (!bThreadHasFinished) |
| 4547 | CPLDebug("GPKG", "Waiting for background RTree building to finish"); |
| 4548 | m_oThreadRTreecxx . . $ OGRGeoPackageTableLayer#m_oThreadRTree..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 4549 | if (!bThreadHasFinished) |
| 4550 | { |
| 4551 | CPLDebug("GPKG", "Background RTree building finished"); |
| 4552 | } |
| 4553 | m_bAllowedRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bAllowedRTreeThread. = false; |
| 4554 | m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted. = false; |
| 4555 | |
| 4556 | if (m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.) |
| 4557 | { |
| 4558 | sqlite3_close(m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle.); |
| 4559 | m_hAsyncDBHandlecxx . . $ OGRGeoPackageTableLayer#m_hAsyncDBHandle. = nullptr; |
| 4560 | } |
| 4561 | if (m_bErrorDuringRTreeThreadcxx . . $ OGRGeoPackageTableLayer#m_bErrorDuringRTreeThread.) |
| 4562 | { |
| 4563 | RemoveAsyncRTreeTempDBcxx . . $ OGRGeoPackageTableLayer#RemoveAsyncRTreeTempDB(49f6e7a06ebc5aa8).(); |
| 4564 | } |
| 4565 | else |
| 4566 | { |
| 4567 | bPopulateFromThreadRTree = true; |
| 4568 | } |
| 4569 | } |
| 4570 | |
| 4571 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).(); |
| 4572 | |
| 4573 | if (m_hRTreecxx . . $ OGRGeoPackageTableLayer#m_hRTree.) |
| 4574 | { |
| 4575 | if (!FlushInMemoryRTreecxx . . $ OGRGeoPackageTableLayer#FlushInMemoryRTree(dbc94f338baa5231).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str())) |
| 4576 | { |
| 4577 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 4578 | return false; |
| 4579 | } |
| 4580 | } |
| 4581 | else if (bPopulateFromThreadRTree) |
| 4582 | { |
| 4583 | /* Create virtual table */ |
| 4584 | char *pszSQL = sqlite3_mprintf("CREATE VIRTUAL TABLE \"%w\" USING " |
| 4585 | "rtree(id, minx, maxx, miny, maxy)", |
| 4586 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 4587 | err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4588 | sqlite3_free(pszSQL); |
| 4589 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4590 | { |
| 4591 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 4592 | return false; |
| 4593 | } |
| 4594 | |
| 4595 | pszSQL = sqlite3_mprintf( |
| 4596 | "DELETE FROM \"%w_node\";\n" |
| 4597 | "INSERT INTO \"%w_node\" SELECT * FROM \"%w\".my_rtree_node;\n" |
| 4598 | "INSERT INTO \"%w_rowid\" SELECT * FROM " |
| 4599 | "\"%w\".my_rtree_rowid;\n" |
| 4600 | "INSERT INTO \"%w_parent\" SELECT * FROM " |
| 4601 | "\"%w\".my_rtree_parent;\n", |
| 4602 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), |
| 4603 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), |
| 4604 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), |
| 4605 | m_osAsyncDBAttachNamecxx . . $ OGRGeoPackageTableLayer#m_osAsyncDBAttachName..c_str()); |
| 4606 | err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4607 | sqlite3_free(pszSQL); |
| 4608 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4609 | { |
| 4610 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 4611 | RemoveAsyncRTreeTempDBcxx . . $ OGRGeoPackageTableLayer#RemoveAsyncRTreeTempDB(49f6e7a06ebc5aa8).(); |
| 4612 | return false; |
| 4613 | } |
| 4614 | } |
| 4615 | else |
| 4616 | { |
| 4617 | /* Populate the RTree */ |
| 4618 | const size_t nMaxRAMUsageAllowed = GetMaxRAMUsageAllowedForRTreecxx . . $ GetMaxRAMUsageAllowedForRTree(f708dce9a8856c70).(); |
| 4619 | char *pszErrMsg = nullptr; |
| 4620 | |
| 4621 | struct ProgressCbkcxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndex(c5f7da30cbc0f4e9).ProgressCbk# |
| 4622 | { |
| 4623 | static bool progressCbkcxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndex(c5f7da30cbc0f4e9).ProgressCbk#progressCbk(b06ab6e061e76a7b).(const char *pszMessage, void *) |
| 4624 | { |
| 4625 | CPLDebug("GPKG", "%s", pszMessage); |
| 4626 | return true; |
| 4627 | } |
| 4628 | }; |
| 4629 | |
| 4630 | if (!gdal_sqlite_rtree_bl_from_feature_table( |
| 4631 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszT, pszI, pszC, m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), "id", |
| 4632 | "minx", "miny", "maxx", "maxy", nMaxRAMUsageAllowed, &pszErrMsg, |
| 4633 | ProgressCbkcxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndex(c5f7da30cbc0f4e9).ProgressCbk#::progressCbkcxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndex(c5f7da30cbc0f4e9).ProgressCbk#progressCbk(b06ab6e061e76a7b)., nullptr)) |
| 4634 | { |
| 4635 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 4636 | "gdal_sqlite_rtree_bl_from_feature_table() failed " |
| 4637 | "with %s", |
| 4638 | pszErrMsg ? pszErrMsg : "(null)"); |
| 4639 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 4640 | sqlite3_free(pszErrMsg); |
| 4641 | return false; |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | CPLString osSQL; |
| 4646 | |
| 4647 | /* Register the table in gpkg_extensions */ |
| 4648 | char *pszSQL = sqlite3_mprintf( |
| 4649 | "INSERT INTO gpkg_extensions " |
| 4650 | "(table_name,column_name,extension_name,definition,scope) " |
| 4651 | "VALUES ('%q', '%q', 'gpkg_rtree_index', " |
| 4652 | "'http://www.geopackage.org/spec120/#extension_rtree', 'write-only')", |
| 4653 | pszT, pszC); |
| 4654 | osSQL += pszSQL; |
| 4655 | sqlite3_free(pszSQL); |
| 4656 | |
| 4657 | /* Define Triggers to Maintain Spatial Index Values */ |
| 4658 | osSQL += ";" + ReturnSQLCreateSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLCreateSpatialIndexTriggers(91f1db05c53bff50).(pszTableName, nullptr); |
| 4659 | |
| 4660 | err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL); |
| 4661 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 4662 | { |
| 4663 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 4664 | if (bPopulateFromThreadRTree) |
| 4665 | { |
| 4666 | RemoveAsyncRTreeTempDBcxx . . $ OGRGeoPackageTableLayer#RemoveAsyncRTreeTempDB(49f6e7a06ebc5aa8).(); |
| 4667 | } |
| 4668 | return false; |
| 4669 | } |
| 4670 | |
| 4671 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 4672 | |
| 4673 | if (bPopulateFromThreadRTree) |
| 4674 | { |
| 4675 | RemoveAsyncRTreeTempDBcxx . . $ OGRGeoPackageTableLayer#RemoveAsyncRTreeTempDB(49f6e7a06ebc5aa8).(); |
| 4676 | } |
| 4677 | |
| 4678 | m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. = true; |
| 4679 | |
| 4680 | return true; |
| 4681 | } |
| 4682 | |
| 4683 | /************************************************************************/ |
| 4684 | /* WorkaroundUpdate1TriggerIssue() */ |
| 4685 | /************************************************************************/ |
| 4686 | |
| 4687 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::WorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#WorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).() |
| 4688 | { |
| 4689 | // Workaround issue of https://sqlite.org/forum/forumpost/8c8de6ff91 |
| 4690 | // Basically the official _update1 spatial index trigger doesn't work |
| 4691 | // with current versions of SQLite when invoked from an UPSERT statement. |
| 4692 | // In GeoPackage 1.4, the update6 and update7 triggers replace update1 |
| 4693 | |
| 4694 | if (m_bHasUpdate6And7Triggerscxx . . $ OGRGeoPackageTableLayer#m_bHasUpdate6And7Triggers. || m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 0) |
| 4695 | return; |
| 4696 | |
| 4697 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 4698 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 4699 | const char *pszI = GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).(); |
| 4700 | |
| 4701 | CPLString osRTreeName = "rtree_"; |
| 4702 | osRTreeName += pszT; |
| 4703 | osRTreeName += "_"; |
| 4704 | osRTreeName += pszC; |
| 4705 | |
| 4706 | // Check if update6 and update7 triggers are there |
| 4707 | { |
| 4708 | char *pszSQL = sqlite3_mprintf( |
| 4709 | "SELECT * FROM sqlite_master WHERE type = 'trigger' " |
| 4710 | "AND name IN ('%q', '%q')", |
| 4711 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update6").c_str(), |
| 4712 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update7").c_str()); |
| 4713 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4714 | sqlite3_free(pszSQL); |
| 4715 | if (oResult && oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 2) |
| 4716 | { |
| 4717 | m_bHasUpdate6And7Triggerscxx . . $ OGRGeoPackageTableLayer#m_bHasUpdate6And7Triggers. = true; |
| 4718 | return; |
| 4719 | } |
| 4720 | } |
| 4721 | |
| 4722 | char *pszSQL = |
| 4723 | sqlite3_mprintf("SELECT sql FROM sqlite_master WHERE type = 'trigger' " |
| 4724 | "AND name = '%q'", |
| 4725 | (m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. + "_update1").c_str()); |
| 4726 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4727 | sqlite3_free(pszSQL); |
| 4728 | if (oResult && oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() == 1) |
| 4729 | { |
| 4730 | const char *pszTriggerSQL = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, 0); |
| 4731 | if (pszTriggerSQL) |
| 4732 | { |
| 4733 | m_osUpdate1Triggercxx . . $ OGRGeoPackageTableLayer#m_osUpdate1Trigger. = pszTriggerSQL; |
| 4734 | } |
| 4735 | } |
| 4736 | if (m_osUpdate1Triggercxx . . $ OGRGeoPackageTableLayer#m_osUpdate1Trigger..empty()) |
| 4737 | return; |
| 4738 | |
| 4739 | m_bUpdate1TriggerDisabledcxx . . $ OGRGeoPackageTableLayer#m_bUpdate1TriggerDisabled. = true; |
| 4740 | |
| 4741 | pszSQL = |
| 4742 | sqlite3_mprintf("DROP TRIGGER \"%w_update1\"", osRTreeName.c_str()); |
| 4743 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4744 | sqlite3_free(pszSQL); |
| 4745 | |
| 4746 | pszSQL = sqlite3_mprintf( |
| 4747 | "CREATE TRIGGER \"%w_update6\" AFTER UPDATE OF \"%w\" " |
| 4748 | "ON \"%w\" " |
| 4749 | "WHEN OLD.\"%w\" = NEW.\"%w\" AND " |
| 4750 | "(NEW.\"%w\" NOTNULL AND NOT ST_IsEmpty(NEW.\"%w\")) AND " |
| 4751 | "(OLD.\"%w\" NOTNULL AND NOT ST_IsEmpty(OLD.\"%w\")) " |
| 4752 | "BEGIN " |
| 4753 | "UPDATE \"%w\" SET " |
| 4754 | "minx = ST_MinX(NEW.\"%w\"), maxx = ST_MaxX(NEW.\"%w\")," |
| 4755 | "miny = ST_MinY(NEW.\"%w\"), maxy = ST_MaxY(NEW.\"%w\") " |
| 4756 | "WHERE id = NEW.\"%w\";" |
| 4757 | "END", |
| 4758 | osRTreeName.c_str(), pszC, pszT, pszI, pszI, pszC, pszC, pszC, pszC, |
| 4759 | osRTreeName.c_str(), pszC, pszC, pszC, pszC, pszI); |
| 4760 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4761 | sqlite3_free(pszSQL); |
| 4762 | |
| 4763 | pszSQL = sqlite3_mprintf( |
| 4764 | "CREATE TRIGGER \"%w_update7\" AFTER UPDATE OF \"%w\" ON " |
| 4765 | "\"%w\" " |
| 4766 | "WHEN OLD.\"%w\" = NEW.\"%w\" AND " |
| 4767 | "(NEW.\"%w\" NOTNULL AND NOT ST_IsEmpty(NEW.\"%w\")) AND " |
| 4768 | "(OLD.\"%w\" ISNULL OR ST_IsEmpty(OLD.\"%w\")) " |
| 4769 | "BEGIN " |
| 4770 | "INSERT INTO \"%w\" VALUES (" |
| 4771 | "NEW.\"%w\"," |
| 4772 | "ST_MinX(NEW.\"%w\"), ST_MaxX(NEW.\"%w\")," |
| 4773 | "ST_MinY(NEW.\"%w\"), ST_MaxY(NEW.\"%w\")" |
| 4774 | "); " |
| 4775 | "END", |
| 4776 | osRTreeName.c_str(), pszC, pszT, pszI, pszI, pszC, pszC, pszC, pszC, |
| 4777 | osRTreeName.c_str(), pszI, pszC, pszC, pszC, pszC); |
| 4778 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4779 | sqlite3_free(pszSQL); |
| 4780 | } |
| 4781 | |
| 4782 | /************************************************************************/ |
| 4783 | /* RevertWorkaroundUpdate1TriggerIssue() */ |
| 4784 | /************************************************************************/ |
| 4785 | |
| 4786 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RevertWorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#RevertWorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).() |
| 4787 | { |
| 4788 | if (!m_bUpdate1TriggerDisabledcxx . . $ OGRGeoPackageTableLayer#m_bUpdate1TriggerDisabled.) |
| 4789 | return; |
| 4790 | m_bUpdate1TriggerDisabledcxx . . $ OGRGeoPackageTableLayer#m_bUpdate1TriggerDisabled. = false; |
| 4791 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(!m_bHasUpdate6And7Triggers); |
| 4792 | |
| 4793 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 4794 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 4795 | |
| 4796 | CPLString osRTreeName = "rtree_"; |
| 4797 | osRTreeName += pszT; |
| 4798 | osRTreeName += "_"; |
| 4799 | osRTreeName += pszC; |
| 4800 | |
| 4801 | char *pszSQL; |
| 4802 | |
| 4803 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), m_osUpdate1Triggercxx . . $ OGRGeoPackageTableLayer#m_osUpdate1Trigger..c_str()); |
| 4804 | m_osUpdate1Triggercxx . . $ OGRGeoPackageTableLayer#m_osUpdate1Trigger..clear(); |
| 4805 | |
| 4806 | pszSQL = |
| 4807 | sqlite3_mprintf("DROP TRIGGER \"%w_update6\"", osRTreeName.c_str()); |
| 4808 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4809 | sqlite3_free(pszSQL); |
| 4810 | |
| 4811 | pszSQL = |
| 4812 | sqlite3_mprintf("DROP TRIGGER \"%w_update7\"", osRTreeName.c_str()); |
| 4813 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 4814 | sqlite3_free(pszSQL); |
| 4815 | } |
| 4816 | |
| 4817 | /************************************************************************/ |
| 4818 | /* ReturnSQLCreateSpatialIndexTriggers() */ |
| 4819 | /************************************************************************/ |
| 4820 | |
| 4821 | CPLString OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ReturnSQLCreateSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLCreateSpatialIndexTriggers(91f1db05c53bff50).( |
| 4822 | const char *pszTableName, const char *pszGeomColName) |
| 4823 | { |
| 4824 | char *pszSQL; |
| 4825 | CPLString osSQL; |
| 4826 | |
| 4827 | const char *pszT = (pszTableName) ? pszTableName : m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 4828 | const char *pszC = (pszGeomColName) |
| 4829 | ? pszGeomColName |
| 4830 | : m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 4831 | const char *pszI = GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).(); |
| 4832 | |
| 4833 | CPLString osRTreeName = "rtree_"; |
| 4834 | osRTreeName += pszT; |
| 4835 | osRTreeName += "_"; |
| 4836 | osRTreeName += pszC; |
| 4837 | |
| 4838 | /* Conditions: Insertion of non-empty geometry |
| 4839 | Actions : Insert record into rtree */ |
| 4840 | pszSQL = sqlite3_mprintf( |
| 4841 | "CREATE TRIGGER \"%w_insert\" AFTER INSERT ON \"%w\" " |
| 4842 | "WHEN (new.\"%w\" NOT NULL AND NOT ST_IsEmpty(NEW.\"%w\")) " |
| 4843 | "BEGIN " |
| 4844 | "INSERT OR REPLACE INTO \"%w\" VALUES (" |
| 4845 | "NEW.\"%w\"," |
| 4846 | "ST_MinX(NEW.\"%w\"), ST_MaxX(NEW.\"%w\")," |
| 4847 | "ST_MinY(NEW.\"%w\"), ST_MaxY(NEW.\"%w\")" |
| 4848 | "); " |
| 4849 | "END", |
| 4850 | osRTreeName.c_str(), pszT, pszC, pszC, osRTreeName.c_str(), pszI, pszC, |
| 4851 | pszC, pszC, pszC); |
| 4852 | osSQL += pszSQL; |
| 4853 | sqlite3_free(pszSQL); |
| 4854 | |
| 4855 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_nApplicationIdcxx . . $ GDALGeoPackageDataset#m_nApplicationId. == GPKG_APPLICATION_IDcxx . . $ GPKG_APPLICATION_ID. && |
| 4856 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_nUserVersioncxx . . $ GDALGeoPackageDataset#m_nUserVersion. >= GPKG_1_4_VERSIONcxx . . $ GPKG_1_4_VERSION.) |
| 4857 | { |
| 4858 | /* Conditions: Update a non-empty geometry with another non-empty geometry |
| 4859 | Actions : Replace record from R-tree |
| 4860 | */ |
| 4861 | pszSQL = sqlite3_mprintf( |
| 4862 | "CREATE TRIGGER \"%w_update6\" AFTER UPDATE OF \"%w\" " |
| 4863 | "ON \"%w\" " |
| 4864 | "WHEN OLD.\"%w\" = NEW.\"%w\" AND " |
| 4865 | "(NEW.\"%w\" NOTNULL AND NOT ST_IsEmpty(NEW.\"%w\")) AND " |
| 4866 | "(OLD.\"%w\" NOTNULL AND NOT ST_IsEmpty(OLD.\"%w\")) " |
| 4867 | "BEGIN " |
| 4868 | "UPDATE \"%w\" SET " |
| 4869 | "minx = ST_MinX(NEW.\"%w\"), maxx = ST_MaxX(NEW.\"%w\")," |
| 4870 | "miny = ST_MinY(NEW.\"%w\"), maxy = ST_MaxY(NEW.\"%w\") " |
| 4871 | "WHERE id = NEW.\"%w\";" |
| 4872 | "END", |
| 4873 | osRTreeName.c_str(), pszC, pszT, pszI, pszI, pszC, pszC, pszC, pszC, |
| 4874 | osRTreeName.c_str(), pszC, pszC, pszC, pszC, pszI); |
| 4875 | osSQL += ";"; |
| 4876 | osSQL += pszSQL; |
| 4877 | sqlite3_free(pszSQL); |
| 4878 | |
| 4879 | /* Conditions: Update a null/empty geometry with a non-empty geometry |
| 4880 | Actions : Insert record into R-tree |
| 4881 | */ |
| 4882 | pszSQL = sqlite3_mprintf( |
| 4883 | "CREATE TRIGGER \"%w_update7\" AFTER UPDATE OF \"%w\" ON " |
| 4884 | "\"%w\" " |
| 4885 | "WHEN OLD.\"%w\" = NEW.\"%w\" AND " |
| 4886 | "(NEW.\"%w\" NOTNULL AND NOT ST_IsEmpty(NEW.\"%w\")) AND " |
| 4887 | "(OLD.\"%w\" ISNULL OR ST_IsEmpty(OLD.\"%w\")) " |
| 4888 | "BEGIN " |
| 4889 | "INSERT INTO \"%w\" VALUES (" |
| 4890 | "NEW.\"%w\"," |
| 4891 | "ST_MinX(NEW.\"%w\"), ST_MaxX(NEW.\"%w\")," |
| 4892 | "ST_MinY(NEW.\"%w\"), ST_MaxY(NEW.\"%w\")" |
| 4893 | "); " |
| 4894 | "END", |
| 4895 | osRTreeName.c_str(), pszC, pszT, pszI, pszI, pszC, pszC, pszC, pszC, |
| 4896 | osRTreeName.c_str(), pszI, pszC, pszC, pszC, pszC); |
| 4897 | osSQL += ";"; |
| 4898 | osSQL += pszSQL; |
| 4899 | sqlite3_free(pszSQL); |
| 4900 | } |
| 4901 | else |
| 4902 | { |
| 4903 | /* Conditions: Update of geometry column to non-empty geometry |
| 4904 | No row ID change |
| 4905 | Actions : Update record in rtree */ |
| 4906 | pszSQL = sqlite3_mprintf( |
| 4907 | "CREATE TRIGGER \"%w_update1\" AFTER UPDATE OF \"%w\" ON \"%w\" " |
| 4908 | "WHEN OLD.\"%w\" = NEW.\"%w\" AND " |
| 4909 | "(NEW.\"%w\" NOTNULL AND NOT ST_IsEmpty(NEW.\"%w\")) " |
| 4910 | "BEGIN " |
| 4911 | "INSERT OR REPLACE INTO \"%w\" VALUES (" |
| 4912 | "NEW.\"%w\"," |
| 4913 | "ST_MinX(NEW.\"%w\"), ST_MaxX(NEW.\"%w\")," |
| 4914 | "ST_MinY(NEW.\"%w\"), ST_MaxY(NEW.\"%w\")" |
| 4915 | "); " |
| 4916 | "END", |
| 4917 | osRTreeName.c_str(), pszC, pszT, pszI, pszI, pszC, pszC, |
| 4918 | osRTreeName.c_str(), pszI, pszC, pszC, pszC, pszC); |
| 4919 | osSQL += ";"; |
| 4920 | osSQL += pszSQL; |
| 4921 | sqlite3_free(pszSQL); |
| 4922 | } |
| 4923 | |
| 4924 | /* Conditions: Update of geometry column to empty geometry |
| 4925 | No row ID change |
| 4926 | Actions : Remove record from rtree */ |
| 4927 | pszSQL = sqlite3_mprintf( |
| 4928 | "CREATE TRIGGER \"%w_update2\" AFTER UPDATE OF \"%w\" ON \"%w\" " |
| 4929 | "WHEN OLD.\"%w\" = NEW.\"%w\" AND " |
| 4930 | "(NEW.\"%w\" ISNULL OR ST_IsEmpty(NEW.\"%w\")) " |
| 4931 | "BEGIN " |
| 4932 | "DELETE FROM \"%w\" WHERE id = OLD.\"%w\"; " |
| 4933 | "END", |
| 4934 | osRTreeName.c_str(), pszC, pszT, pszI, pszI, pszC, pszC, |
| 4935 | osRTreeName.c_str(), pszI); |
| 4936 | osSQL += ";"; |
| 4937 | osSQL += pszSQL; |
| 4938 | sqlite3_free(pszSQL); |
| 4939 | |
| 4940 | /* Conditions: Update of any column |
| 4941 | Row ID change |
| 4942 | Non-empty geometry |
| 4943 | Actions : Remove record from rtree for old <i> |
| 4944 | Insert record into rtree for new <i> */ |
| 4945 | pszSQL = |
| 4946 | sqlite3_mprintf("CREATE TRIGGER \"%w_%s\" AFTER UPDATE ON \"%w\" " |
| 4947 | "WHEN OLD.\"%w\" != NEW.\"%w\" AND " |
| 4948 | "(NEW.\"%w\" NOTNULL AND NOT ST_IsEmpty(NEW.\"%w\")) " |
| 4949 | "BEGIN " |
| 4950 | "DELETE FROM \"%w\" WHERE id = OLD.\"%w\"; " |
| 4951 | "INSERT OR REPLACE INTO \"%w\" VALUES (" |
| 4952 | "NEW.\"%w\"," |
| 4953 | "ST_MinX(NEW.\"%w\"), ST_MaxX(NEW.\"%w\")," |
| 4954 | "ST_MinY(NEW.\"%w\"), ST_MaxY(NEW.\"%w\")" |
| 4955 | "); " |
| 4956 | "END", |
| 4957 | osRTreeName.c_str(), |
| 4958 | (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_nApplicationIdcxx . . $ GDALGeoPackageDataset#m_nApplicationId. == GPKG_APPLICATION_IDcxx . . $ GPKG_APPLICATION_ID. && |
| 4959 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_nUserVersioncxx . . $ GDALGeoPackageDataset#m_nUserVersion. >= GPKG_1_4_VERSIONcxx . . $ GPKG_1_4_VERSION.) |
| 4960 | ? "update5" |
| 4961 | : "update3", |
| 4962 | pszT, pszI, pszI, pszC, pszC, osRTreeName.c_str(), pszI, |
| 4963 | osRTreeName.c_str(), pszI, pszC, pszC, pszC, pszC); |
| 4964 | osSQL += ";"; |
| 4965 | osSQL += pszSQL; |
| 4966 | sqlite3_free(pszSQL); |
| 4967 | |
| 4968 | /* Conditions: Update of any column |
| 4969 | Row ID change |
| 4970 | Empty geometry |
| 4971 | Actions : Remove record from rtree for old and new <i> */ |
| 4972 | pszSQL = sqlite3_mprintf( |
| 4973 | "CREATE TRIGGER \"%w_update4\" AFTER UPDATE ON \"%w\" " |
| 4974 | "WHEN OLD.\"%w\" != NEW.\"%w\" AND " |
| 4975 | "(NEW.\"%w\" ISNULL OR ST_IsEmpty(NEW.\"%w\")) " |
| 4976 | "BEGIN " |
| 4977 | "DELETE FROM \"%w\" WHERE id IN (OLD.\"%w\", NEW.\"%w\"); " |
| 4978 | "END", |
| 4979 | osRTreeName.c_str(), pszT, pszI, pszI, pszC, pszC, osRTreeName.c_str(), |
| 4980 | pszI, pszI); |
| 4981 | osSQL += ";"; |
| 4982 | osSQL += pszSQL; |
| 4983 | sqlite3_free(pszSQL); |
| 4984 | |
| 4985 | /* Conditions: Row deleted |
| 4986 | Actions : Remove record from rtree for old <i> */ |
| 4987 | pszSQL = sqlite3_mprintf( |
| 4988 | "CREATE TRIGGER \"%w_delete\" AFTER DELETE ON \"%w\" " |
| 4989 | "WHEN old.\"%w\" NOT NULL " |
| 4990 | "BEGIN " |
| 4991 | "DELETE FROM \"%w\" WHERE id = OLD.\"%w\"; " |
| 4992 | "END", |
| 4993 | osRTreeName.c_str(), pszT, pszC, osRTreeName.c_str(), pszI); |
| 4994 | osSQL += ";"; |
| 4995 | osSQL += pszSQL; |
| 4996 | sqlite3_free(pszSQL); |
| 4997 | |
| 4998 | return osSQL; |
| 4999 | } |
| 5000 | |
| 5001 | /************************************************************************/ |
| 5002 | /* CheckUnknownExtensions() */ |
| 5003 | /************************************************************************/ |
| 5004 | |
| 5005 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CheckUnknownExtensionscxx . . $ OGRGeoPackageTableLayer#CheckUnknownExtensions(49f6e7a06ebc5aa8).() |
| 5006 | { |
| 5007 | const stdcxx . . $ std/::mapcxx . . $ std/map#<CPLString, stdcxx . . $ std/::vector<GPKGExtensionDesccxx . . $ GPKGExtensionDesc#>> &oMap = |
| 5008 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUnknownExtensionsTableSpecificcxx . . $ GDALGeoPackageDataset#GetUnknownExtensionsTableSpecific(434d56754ab74caa).(); |
| 5009 | const auto oIter = oMap.findcxx . . $ std/map#find(7b3585bb5da8f7d).(CPLString(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).toupper()); |
| 5010 | if (oIter !=cxx . . $ std/`operator!=`(a84eb84a7a5e8237). oMap.endcxx . . $ std/map#end(b953fec338ad1a3b).()) |
| 5011 | { |
| 5012 | for (size_t i = 0; i < oIter->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second.size(); i++) |
| 5013 | { |
| 5014 | const char *pszExtName = oIter->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second[i].osExtensionNamecxx . . $ GPKGExtensionDesc#osExtensionName..c_str(); |
| 5015 | const char *pszDefinition = oIter->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second[i].osDefinitioncxx . . $ GPKGExtensionDesc#osDefinition..c_str(); |
| 5016 | const char *pszScope = oIter->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).second[i].osScopecxx . . $ GPKGExtensionDesc#osScope..c_str(); |
| 5017 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszScope, "write-only")) |
| 5018 | { |
| 5019 | CPLError( |
| 5020 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5021 | "Layer %s relies on the '%s' (%s) extension that should " |
| 5022 | "be implemented for safe write-support, but is not " |
| 5023 | "currently. " |
| 5024 | "Update of that layer are strongly discouraged to avoid " |
| 5025 | "corruption.", |
| 5026 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), pszExtName, pszDefinition); |
| 5027 | } |
| 5028 | else if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).() && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszScope, "read-write")) |
| 5029 | { |
| 5030 | CPLError( |
| 5031 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5032 | "Layer %s relies on the '%s' (%s) extension that should " |
| 5033 | "be implemented in order to read/write it safely, but is " |
| 5034 | "not currently. " |
| 5035 | "Some data may be missing while reading that layer, and " |
| 5036 | "updates are strongly discouraged.", |
| 5037 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), pszExtName, pszDefinition); |
| 5038 | } |
| 5039 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszScope, "read-write") && |
| 5040 | // None of the NGA extensions at |
| 5041 | // http://ngageoint.github.io/GeoPackage/docs/extensions/ |
| 5042 | // affect read-only scenarios |
| 5043 | !STARTS_WITHcxx . . $ `port/cpl_port.h:541:9`!(pszExtName, "nga_")) |
| 5044 | { |
| 5045 | CPLError( |
| 5046 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5047 | "Layer %s relies on the '%s' (%s) extension that should " |
| 5048 | "be implemented in order to read it safely, but is not " |
| 5049 | "currently. " |
| 5050 | "Some data may be missing while reading that layer.", |
| 5051 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), pszExtName, pszDefinition); |
| 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | /************************************************************************/ |
| 5058 | /* CreateGeometryExtensionIfNecessary() */ |
| 5059 | /************************************************************************/ |
| 5060 | |
| 5061 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateGeometryExtensionIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateGeometryExtensionIfNecessary(e63478674a9dea31).( |
| 5062 | const OGRGeometrycxx . . $ OGRGeometry# *poGeom) |
| 5063 | { |
| 5064 | bool bRet = true; |
| 5065 | if (poGeom != nullptr) |
| 5066 | { |
| 5067 | OGRwkbGeometryType eGType = wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(poGeom->getGeometryType()); |
| 5068 | if (eGType >= wkbGeometryCollection) |
| 5069 | { |
| 5070 | if (eGType > wkbGeometryCollection) |
| 5071 | CreateGeometryExtensionIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateGeometryExtensionIfNecessary(d700db20b643f27b).(eGType); |
| 5072 | const OGRGeometryCollectioncxx . . $ OGRGeometryCollection# *poGC = |
| 5073 | dynamic_cast<const OGRGeometryCollectioncxx . . $ OGRGeometryCollection# *>(poGeom); |
| 5074 | if (poGC != nullptr) |
| 5075 | { |
| 5076 | const int nSubGeoms = poGC->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).(); |
| 5077 | for (int i = 0; i < nSubGeoms; i++) |
| 5078 | { |
| 5079 | bRet &= CreateGeometryExtensionIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateGeometryExtensionIfNecessary(e63478674a9dea31).( |
| 5080 | poGC->getGeometryRefcxx . . $ OGRGeometryCollection#getGeometryRef(4b23861bde278833).(i)); |
| 5081 | } |
| 5082 | } |
| 5083 | } |
| 5084 | } |
| 5085 | return bRet; |
| 5086 | } |
| 5087 | |
| 5088 | /************************************************************************/ |
| 5089 | /* CreateGeometryExtensionIfNecessary() */ |
| 5090 | /************************************************************************/ |
| 5091 | |
| 5092 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::CreateGeometryExtensionIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateGeometryExtensionIfNecessary(d700db20b643f27b).( |
| 5093 | OGRwkbGeometryType eGType) |
| 5094 | { |
| 5095 | eGType = wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(eGType); |
| 5096 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(eGType > wkbGeometryCollection && eGType <= wkbTriangle); |
| 5097 | if (m_abHasGeometryExtensioncxx . . $ OGRGeoPackageTableLayer#m_abHasGeometryExtension.[eGType]) |
| 5098 | return true; |
| 5099 | |
| 5100 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->CreateExtensionsTableIfNecessarycxx . . $ GDALGeoPackageDataset#CreateExtensionsTableIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5101 | return false; |
| 5102 | |
| 5103 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 5104 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 5105 | const char *pszGeometryType = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetGeometryTypeStringcxx . . $ GDALGeoPackageDataset#GetGeometryTypeString(10f7d487d41f9e63).(eGType); |
| 5106 | |
| 5107 | // Check first if the extension isn't registered |
| 5108 | char *pszSQL = sqlite3_mprintf( |
| 5109 | "SELECT 1 FROM gpkg_extensions WHERE lower(table_name) = lower('%q') " |
| 5110 | "AND " |
| 5111 | "lower(column_name) = lower('%q') AND extension_name = 'gpkg_geom_%s'", |
| 5112 | pszT, pszC, pszGeometryType); |
| 5113 | const bool bExists = SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, nullptr) == 1; |
| 5114 | sqlite3_free(pszSQL); |
| 5115 | |
| 5116 | if (!bExists) |
| 5117 | { |
| 5118 | if (eGType == wkbPolyhedralSurface || eGType == wkbTIN || |
| 5119 | eGType == wkbTriangle) |
| 5120 | { |
| 5121 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5122 | "Registering non-standard gpkg_geom_%s extension", |
| 5123 | pszGeometryType); |
| 5124 | } |
| 5125 | |
| 5126 | /* Register the table in gpkg_extensions */ |
| 5127 | pszSQL = sqlite3_mprintf( |
| 5128 | "INSERT INTO gpkg_extensions " |
| 5129 | "(table_name,column_name,extension_name,definition,scope) " |
| 5130 | "VALUES ('%q', '%q', 'gpkg_geom_%s', " |
| 5131 | "'http://www.geopackage.org/spec120/#extension_geometry_types', " |
| 5132 | "'read-write')", |
| 5133 | pszT, pszC, pszGeometryType); |
| 5134 | OGRErr err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 5135 | sqlite3_free(pszSQL); |
| 5136 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5137 | return false; |
| 5138 | } |
| 5139 | |
| 5140 | m_abHasGeometryExtensioncxx . . $ OGRGeoPackageTableLayer#m_abHasGeometryExtension.[eGType] = true; |
| 5141 | return true; |
| 5142 | } |
| 5143 | |
| 5144 | /************************************************************************/ |
| 5145 | /* HasSpatialIndex() */ |
| 5146 | /************************************************************************/ |
| 5147 | |
| 5148 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).() const |
| 5149 | { |
| 5150 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 5151 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 5152 | if (m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. >= 0) |
| 5153 | return CPL_TO_BOOL(m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex.); |
| 5154 | m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. = false; |
| 5155 | |
| 5156 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr || |
| 5157 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).() == 0 || |
| 5158 | !m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasExtensionsTablecxx . . $ GDALGeoPackageDataset#HasExtensionsTable(c9857a73d68e59ba).()) |
| 5159 | return false; |
| 5160 | |
| 5161 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 5162 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 5163 | CPLString osRTreeName( |
| 5164 | CPLString("rtree_").append(pszT).append("_").append(pszC)); |
| 5165 | const stdcxx . . $ std/::mapcxx . . $ std/map#<CPLString, CPLString> &oMap = |
| 5166 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetNameTypeMapFromSQliteMastercxx . . $ GDALGeoPackageDataset#GetNameTypeMapFromSQliteMaster(dc17b9a7c39a0ee5).(); |
| 5167 | if (cplcxx . . $ cpl/::contains(oMap, CPLString(osRTreeName).toupper())) |
| 5168 | { |
| 5169 | m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. = true; |
| 5170 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = stdcxx . . $ std/::move(osRTreeName); |
| 5171 | m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree. = m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.; |
| 5172 | } |
| 5173 | |
| 5174 | // Add heuristics to try to detect corrupted RTree generated by GDAL 3.6.0 |
| 5175 | // Cf https://github.com/OSGeo/gdal/pull/6911 |
| 5176 | if (m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex.) |
| 5177 | { |
| 5178 | const auto nFC = |
| 5179 | const_cast<OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *>(this)->GetTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#GetTotalFeatureCount(a5d9f2bf8849668d).(); |
| 5180 | if (nFC >= atoicxx . . $ atoi(f5ecf3191ed0cd93).(CPLGetConfigOption( |
| 5181 | "OGR_GPKG_THRESHOLD_DETECT_BROKEN_RTREE", "100000"))) |
| 5182 | { |
| 5183 | CPLString osSQL = "SELECT 1 FROM \""; |
| 5184 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszT); |
| 5185 | osSQL += "\" WHERE \""; |
| 5186 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).( |
| 5187 | const_cast<OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *>(this)->GetFIDColumncxx . . $ OGRGeoPackageTableLayer#GetFIDColumn(a9f41ea0e82d88cf).()); |
| 5188 | osSQL += "\" = "; |
| 5189 | osSQL += CPLSPrintf(CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, nFC); |
| 5190 | osSQL += " AND \""; |
| 5191 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC); |
| 5192 | osSQL += "\" IS NOT NULL AND NOT ST_IsEmpty(\""; |
| 5193 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC); |
| 5194 | osSQL += "\")"; |
| 5195 | if (SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL, nullptr) == 1) |
| 5196 | { |
| 5197 | osSQL = "SELECT 1 FROM \""; |
| 5198 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.); |
| 5199 | osSQL += "\" WHERE id = "; |
| 5200 | osSQL += CPLSPrintf(CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, nFC); |
| 5201 | if (SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL, nullptr) == 0) |
| 5202 | { |
| 5203 | CPLError(CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5204 | "Spatial index (perhaps created with GDAL 3.6.0) " |
| 5205 | "of table %s is corrupted. Disabling its use. " |
| 5206 | "This file should be recreated or its spatial " |
| 5207 | "index recreated", |
| 5208 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5209 | m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. = false; |
| 5210 | } |
| 5211 | } |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | return CPL_TO_BOOL(m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex.); |
| 5216 | } |
| 5217 | |
| 5218 | /************************************************************************/ |
| 5219 | /* DropSpatialIndex() */ |
| 5220 | /************************************************************************/ |
| 5221 | |
| 5222 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DropSpatialIndexcxx . . $ OGRGeoPackageTableLayer#DropSpatialIndex(efaadfb7dc14930a).(bool bCalledFromSQLFunction) |
| 5223 | { |
| 5224 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 5225 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 5226 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("DropSpatialIndex")) |
| 5227 | return false; |
| 5228 | |
| 5229 | if (m_bDropRTreeTablecxx . . $ OGRGeoPackageTableLayer#m_bDropRTreeTable.) |
| 5230 | { |
| 5231 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5232 | "Cannot run DropSpatialIndex() after non-completed deferred " |
| 5233 | "DropSpatialIndex()"); |
| 5234 | return false; |
| 5235 | } |
| 5236 | |
| 5237 | if (!HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 5238 | { |
| 5239 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Spatial index not existing"); |
| 5240 | return false; |
| 5241 | } |
| 5242 | |
| 5243 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 5244 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 5245 | { |
| 5246 | char *pszSQL = sqlite3_mprintf( |
| 5247 | "DELETE FROM gpkg_extensions WHERE lower(table_name)=lower('%q') " |
| 5248 | "AND lower(column_name)=lower('%q') AND " |
| 5249 | "extension_name='gpkg_rtree_index'", |
| 5250 | pszT, pszC); |
| 5251 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 5252 | sqlite3_free(pszSQL); |
| 5253 | } |
| 5254 | |
| 5255 | if (bCalledFromSQLFunction) |
| 5256 | { |
| 5257 | /* We cannot drop a table from a SQLite function call, so we just */ |
| 5258 | /* memorize that we will have to delete the table later */ |
| 5259 | m_bDropRTreeTablecxx . . $ OGRGeoPackageTableLayer#m_bDropRTreeTable. = true; |
| 5260 | } |
| 5261 | else |
| 5262 | { |
| 5263 | char *pszSQL = |
| 5264 | sqlite3_mprintf("DROP TABLE \"%w\"", m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 5265 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 5266 | sqlite3_free(pszSQL); |
| 5267 | } |
| 5268 | |
| 5269 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->RemoveTableFromSQLiteMasterCachecxx . . $ GDALGeoPackageDataset#RemoveTableFromSQLiteMasterCache(85c52e162fed56f9).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.); |
| 5270 | |
| 5271 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), ReturnSQLDropSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLDropSpatialIndexTriggers(cdfd1e859161399b).().c_str()); |
| 5272 | |
| 5273 | m_bHasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#m_bHasSpatialIndex. = false; |
| 5274 | return true; |
| 5275 | } |
| 5276 | |
| 5277 | /************************************************************************/ |
| 5278 | /* RunDeferredDropRTreeTableIfNecessary() */ |
| 5279 | /************************************************************************/ |
| 5280 | |
| 5281 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RunDeferredDropRTreeTableIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredDropRTreeTableIfNecessary(c9857a73d68e59ba).() |
| 5282 | { |
| 5283 | bool ret = true; |
| 5284 | if (m_bDropRTreeTablecxx . . $ OGRGeoPackageTableLayer#m_bDropRTreeTable.) |
| 5285 | { |
| 5286 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 5287 | |
| 5288 | char *pszSQL = |
| 5289 | sqlite3_mprintf("DROP TABLE \"%w\"", m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 5290 | ret = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 5291 | sqlite3_free(pszSQL); |
| 5292 | m_bDropRTreeTablecxx . . $ OGRGeoPackageTableLayer#m_bDropRTreeTable. = false; |
| 5293 | } |
| 5294 | return ret; |
| 5295 | } |
| 5296 | |
| 5297 | /************************************************************************/ |
| 5298 | /* ReturnSQLDropSpatialIndexTriggers() */ |
| 5299 | /************************************************************************/ |
| 5300 | |
| 5301 | CPLString OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ReturnSQLDropSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLDropSpatialIndexTriggers(cdfd1e859161399b).() |
| 5302 | { |
| 5303 | char *pszSQL = sqlite3_mprintf( |
| 5304 | "DROP TRIGGER \"%w_insert\";" |
| 5305 | "DROP TRIGGER IF EXISTS \"%w_update1\";" // replaced by update6 and update7 in GPKG 1.4 |
| 5306 | "DROP TRIGGER \"%w_update2\";" |
| 5307 | "DROP TRIGGER IF EXISTS \"%w_update3\";" // replace by update5 in GPKG 1.4 |
| 5308 | "DROP TRIGGER \"%w_update4\";" |
| 5309 | "DROP TRIGGER IF EXISTS \"%w_update5\";" // replace update3 in GPKG 1.4 |
| 5310 | "DROP TRIGGER IF EXISTS \"%w_update6\";" // replace update1 in GPKG 1.4 |
| 5311 | "DROP TRIGGER IF EXISTS \"%w_update7\";" // replace update1 in GPKG 1.4 |
| 5312 | "DROP TRIGGER \"%w_delete\";", |
| 5313 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), |
| 5314 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), |
| 5315 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 5316 | CPLString osSQL(pszSQL); |
| 5317 | sqlite3_free(pszSQL); |
| 5318 | |
| 5319 | return osSQL; |
| 5320 | } |
| 5321 | |
| 5322 | /************************************************************************/ |
| 5323 | /* Rename() */ |
| 5324 | /************************************************************************/ |
| 5325 | |
| 5326 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::Renamecxx . . $ OGRGeoPackageTableLayer#Rename(5c4306d8553b3696).(const char *pszDstTableName) |
| 5327 | { |
| 5328 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 5329 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 5330 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("Rename")) |
| 5331 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 5332 | |
| 5333 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 5334 | SyncToDiskcxx . . $ OGRGeoPackageTableLayer#SyncToDisk(b126dc7c1de90089).(); |
| 5335 | |
| 5336 | char *pszSQL = sqlite3_mprintf( |
| 5337 | "SELECT 1 FROM sqlite_master WHERE lower(name) = lower('%q') " |
| 5338 | "AND type IN ('table', 'view')", |
| 5339 | pszDstTableName); |
| 5340 | const bool bAlreadyExists = |
| 5341 | SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, nullptr) == 1; |
| 5342 | sqlite3_free(pszSQL); |
| 5343 | if (bAlreadyExists) |
| 5344 | { |
| 5345 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Table %s already exists", |
| 5346 | pszDstTableName); |
| 5347 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 5348 | } |
| 5349 | |
| 5350 | // Temporary remove foreign key checks |
| 5351 | const GPKGTemporaryForeignKeyCheckDisablercxx . . $ GPKGTemporaryForeignKeyCheckDisabler# |
| 5352 | oGPKGTemporaryForeignKeyCheckDisablercxx . . $ GPKGTemporaryForeignKeyCheckDisabler#GPKGTemporaryForeignKeyCheckDisabler(708af067f9bb9c4a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.); |
| 5353 | |
| 5354 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5355 | { |
| 5356 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 5357 | } |
| 5358 | |
| 5359 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 5360 | DisableFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#DisableFeatureCountTriggers(b45ddcbc8423892c).(false); |
| 5361 | #endif |
| 5362 | |
| 5363 | CPLString osSQL; |
| 5364 | |
| 5365 | pszSQL = sqlite3_mprintf( |
| 5366 | "UPDATE gpkg_geometry_columns SET table_name = '%q' WHERE " |
| 5367 | "lower(table_name )= lower('%q');", |
| 5368 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5369 | osSQL += pszSQL; |
| 5370 | sqlite3_free(pszSQL); |
| 5371 | |
| 5372 | // Rename the identifier if it defaulted to the table name |
| 5373 | pszSQL = sqlite3_mprintf( |
| 5374 | "UPDATE gpkg_contents SET identifier = '%q' WHERE " |
| 5375 | "lower(table_name) = lower('%q') AND identifier = '%q';", |
| 5376 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5377 | osSQL += pszSQL; |
| 5378 | sqlite3_free(pszSQL); |
| 5379 | |
| 5380 | pszSQL = sqlite3_mprintf("UPDATE gpkg_contents SET table_name = '%q' WHERE " |
| 5381 | "lower(table_name )= lower('%q');", |
| 5382 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5383 | osSQL += pszSQL; |
| 5384 | sqlite3_free(pszSQL); |
| 5385 | |
| 5386 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasExtensionsTablecxx . . $ GDALGeoPackageDataset#HasExtensionsTable(c9857a73d68e59ba).()) |
| 5387 | { |
| 5388 | pszSQL = sqlite3_mprintf( |
| 5389 | "UPDATE gpkg_extensions SET table_name = '%q' WHERE " |
| 5390 | "lower(table_name )= lower('%q');", |
| 5391 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5392 | osSQL += pszSQL; |
| 5393 | sqlite3_free(pszSQL); |
| 5394 | } |
| 5395 | |
| 5396 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasMetadataTablescxx . . $ GDALGeoPackageDataset#HasMetadataTables(50ce9a9e25b4a850).()) |
| 5397 | { |
| 5398 | pszSQL = sqlite3_mprintf( |
| 5399 | "UPDATE gpkg_metadata_reference SET table_name = '%q' WHERE " |
| 5400 | "lower(table_name )= lower('%q');", |
| 5401 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5402 | osSQL += pszSQL; |
| 5403 | sqlite3_free(pszSQL); |
| 5404 | } |
| 5405 | |
| 5406 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasDataColumnsTablecxx . . $ GDALGeoPackageDataset#HasDataColumnsTable(50ce9a9e25b4a850).()) |
| 5407 | { |
| 5408 | pszSQL = sqlite3_mprintf( |
| 5409 | "UPDATE gpkg_data_columns SET table_name = '%q' WHERE " |
| 5410 | "lower(table_name )= lower('%q');", |
| 5411 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5412 | osSQL += pszSQL; |
| 5413 | sqlite3_free(pszSQL); |
| 5414 | } |
| 5415 | |
| 5416 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 5417 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 5418 | { |
| 5419 | pszSQL = sqlite3_mprintf( |
| 5420 | "UPDATE gpkg_ogr_contents SET table_name = '%q' WHERE " |
| 5421 | "lower(table_name )= lower('%q');", |
| 5422 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5423 | osSQL += pszSQL; |
| 5424 | sqlite3_free(pszSQL); |
| 5425 | } |
| 5426 | #endif |
| 5427 | |
| 5428 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasGpkgextRelationsTablecxx . . $ GDALGeoPackageDataset#HasGpkgextRelationsTable(50ce9a9e25b4a850).()) |
| 5429 | { |
| 5430 | pszSQL = sqlite3_mprintf( |
| 5431 | "UPDATE gpkgext_relations SET base_table_name = '%q' WHERE " |
| 5432 | "lower(base_table_name )= lower('%q');", |
| 5433 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5434 | osSQL += pszSQL; |
| 5435 | sqlite3_free(pszSQL); |
| 5436 | |
| 5437 | pszSQL = sqlite3_mprintf( |
| 5438 | "UPDATE gpkgext_relations SET related_table_name = '%q' WHERE " |
| 5439 | "lower(related_table_name )= lower('%q');", |
| 5440 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5441 | osSQL += pszSQL; |
| 5442 | ; |
| 5443 | sqlite3_free(pszSQL); |
| 5444 | |
| 5445 | pszSQL = sqlite3_mprintf( |
| 5446 | "UPDATE gpkgext_relations SET mapping_table_name = '%q' WHERE " |
| 5447 | "lower(mapping_table_name )= lower('%q');", |
| 5448 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5449 | osSQL += pszSQL; |
| 5450 | sqlite3_free(pszSQL); |
| 5451 | } |
| 5452 | |
| 5453 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasQGISLayerStylescxx . . $ GDALGeoPackageDataset#HasQGISLayerStyles(50ce9a9e25b4a850).()) |
| 5454 | { |
| 5455 | pszSQL = |
| 5456 | sqlite3_mprintf("UPDATE layer_styles SET f_table_name = '%q' WHERE " |
| 5457 | "f_table_name = '%q';", |
| 5458 | pszDstTableName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5459 | osSQL += pszSQL; |
| 5460 | sqlite3_free(pszSQL); |
| 5461 | } |
| 5462 | |
| 5463 | pszSQL = sqlite3_mprintf("ALTER TABLE \"%w\" RENAME TO \"%w\";", |
| 5464 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszDstTableName); |
| 5465 | osSQL += pszSQL; |
| 5466 | sqlite3_free(pszSQL); |
| 5467 | |
| 5468 | const bool bHasSpatialIndex = HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).(); |
| 5469 | CPLString osRTreeNameNew; |
| 5470 | if (bHasSpatialIndex) |
| 5471 | { |
| 5472 | osRTreeNameNew = "rtree_"; |
| 5473 | osRTreeNameNew += pszDstTableName; |
| 5474 | osRTreeNameNew += "_"; |
| 5475 | osRTreeNameNew += m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 5476 | |
| 5477 | osSQL += ReturnSQLDropSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLDropSpatialIndexTriggers(cdfd1e859161399b).(); |
| 5478 | osSQL += ';'; |
| 5479 | |
| 5480 | pszSQL = sqlite3_mprintf("ALTER TABLE \"%w\" RENAME TO \"%w\";", |
| 5481 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), osRTreeNameNew.c_str()); |
| 5482 | osSQL += pszSQL; |
| 5483 | sqlite3_free(pszSQL); |
| 5484 | |
| 5485 | osSQL += ReturnSQLCreateSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLCreateSpatialIndexTriggers(91f1db05c53bff50).(pszDstTableName, nullptr); |
| 5486 | } |
| 5487 | |
| 5488 | OGRErr eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL); |
| 5489 | |
| 5490 | // Check foreign key integrity |
| 5491 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5492 | { |
| 5493 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->PragmaCheckcxx . . $ OGRSQLiteBaseDataSource#PragmaCheck(f0be30763a490cce).("foreign_key_check", "", 0); |
| 5494 | } |
| 5495 | |
| 5496 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5497 | { |
| 5498 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 5499 | CreateFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#CreateFeatureCountTriggers(85c52e162fed56f9).(pszDstTableName); |
| 5500 | #endif |
| 5501 | |
| 5502 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 5503 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5504 | { |
| 5505 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->RemoveTableFromSQLiteMasterCachecxx . . $ GDALGeoPackageDataset#RemoveTableFromSQLiteMasterCache(85c52e162fed56f9).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5506 | |
| 5507 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5508 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName. = CPLStrdup(pszDstTableName); |
| 5509 | |
| 5510 | if (bHasSpatialIndex) |
| 5511 | { |
| 5512 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->RemoveTableFromSQLiteMasterCachecxx . . $ GDALGeoPackageDataset#RemoveTableFromSQLiteMasterCache(85c52e162fed56f9).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.); |
| 5513 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = stdcxx . . $ std/::move(osRTreeNameNew); |
| 5514 | } |
| 5515 | } |
| 5516 | } |
| 5517 | else |
| 5518 | { |
| 5519 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 5520 | } |
| 5521 | |
| 5522 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5523 | { |
| 5524 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ClearCachedRelationshipscxx . . $ GDALGeoPackageDataset#ClearCachedRelationships(49f6e7a06ebc5aa8).(); |
| 5525 | |
| 5526 | SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).(pszDstTableName); |
| 5527 | whileUnsealingcxx . . $ whileUnsealing(de07598ec200be45).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.)->cxx . . $ OGRFeatureDefn#TemporaryUnsealer#`operator->`(407fccde18759965).SetNamecxx . . $ OGRFeatureDefn#SetName(85c52e162fed56f9).(pszDstTableName); |
| 5528 | } |
| 5529 | |
| 5530 | return eErr; |
| 5531 | } |
| 5532 | |
| 5533 | /************************************************************************/ |
| 5534 | /* ISetSpatialFilter() */ |
| 5535 | /************************************************************************/ |
| 5536 | |
| 5537 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ISetSpatialFiltercxx . . $ OGRGeoPackageTableLayer#ISetSpatialFilter(896393ecef503097).(int /*iGeomField*/, |
| 5538 | const OGRGeometrycxx . . $ OGRGeometry# *poGeomIn) |
| 5539 | |
| 5540 | { |
| 5541 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 5542 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 5543 | if (InstallFiltercxx . . $ OGRLayer#InstallFilter(fed901b2566802ff).(poGeomIn)) |
| 5544 | { |
| 5545 | BuildWherecxx . . $ OGRGeoPackageTableLayer#BuildWhere(49f6e7a06ebc5aa8).(); |
| 5546 | |
| 5547 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 5548 | } |
| 5549 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 5550 | } |
| 5551 | |
| 5552 | /************************************************************************/ |
| 5553 | /* HasFastSpatialFilter() */ |
| 5554 | /************************************************************************/ |
| 5555 | |
| 5556 | bool OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::HasFastSpatialFiltercxx . . $ OGRGeoPackageTableLayer#HasFastSpatialFilter(83c267b20bac841a).(int m_iGeomColIn) |
| 5557 | { |
| 5558 | if (m_iGeomColIn < 0 || |
| 5559 | m_iGeomColIn >= m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 5560 | return false; |
| 5561 | return HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).(); |
| 5562 | } |
| 5563 | |
| 5564 | /************************************************************************/ |
| 5565 | /* GetSpatialWhere() */ |
| 5566 | /************************************************************************/ |
| 5567 | |
| 5568 | CPLString OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetSpatialWherecxx . . $ OGRGeoPackageTableLayer#GetSpatialWhere(ac3cefc8daf1e661).(int m_iGeomColIn, |
| 5569 | OGRGeometrycxx . . $ OGRGeometry# *poFilterGeom) |
| 5570 | { |
| 5571 | CPLString osSpatialWHERE; |
| 5572 | |
| 5573 | if (m_iGeomColIn < 0 || |
| 5574 | m_iGeomColIn >= m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 5575 | return osSpatialWHERE; |
| 5576 | |
| 5577 | if (poFilterGeom != nullptr) |
| 5578 | { |
| 5579 | OGREnvelope sEnvelope; |
| 5580 | |
| 5581 | poFilterGeom->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&sEnvelope); |
| 5582 | |
| 5583 | const char *pszC = |
| 5584 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(m_iGeomColIn)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 5585 | |
| 5586 | if (stdcxx . . $ std/::isinf(sEnvelope.MinX) && sEnvelope.MinX < 0 && |
| 5587 | stdcxx . . $ std/::isinf(sEnvelope.MinY) && sEnvelope.MinY < 0 && |
| 5588 | stdcxx . . $ std/::isinf(sEnvelope.MaxX) && sEnvelope.MaxX > 0 && |
| 5589 | stdcxx . . $ std/::isinf(sEnvelope.MaxY) && sEnvelope.MaxY > 0) |
| 5590 | { |
| 5591 | osSpatialWHERE.Printf( |
| 5592 | "(\"%s\" IS NOT NULL AND NOT ST_IsEmpty(\"%s\"))", |
| 5593 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC).c_str(), SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC).c_str()); |
| 5594 | return osSpatialWHERE; |
| 5595 | } |
| 5596 | |
| 5597 | bool bUseSpatialIndex = true; |
| 5598 | if (m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. && sEnvelope.MinX <= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinX && |
| 5599 | sEnvelope.MinY <= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinY && |
| 5600 | sEnvelope.MaxX >= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxX && |
| 5601 | sEnvelope.MaxY >= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxY) |
| 5602 | { |
| 5603 | // Selecting from spatial filter on whole extent can be rather |
| 5604 | // slow. So use function based filtering, just in case the |
| 5605 | // advertized global extent might be wrong. Otherwise we might |
| 5606 | // just discard completely the spatial filter. |
| 5607 | bUseSpatialIndex = false; |
| 5608 | } |
| 5609 | |
| 5610 | if (bUseSpatialIndex && HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 5611 | { |
| 5612 | osSpatialWHERE.Printf( |
| 5613 | "\"%s\" IN ( SELECT id FROM \"%s\" WHERE " |
| 5614 | "maxx >= %.12f AND minx <= %.12f AND " |
| 5615 | "maxy >= %.12f AND miny <= %.12f)", |
| 5616 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree.).c_str(), |
| 5617 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.).c_str(), sEnvelope.MinX - 1e-11, |
| 5618 | sEnvelope.MaxX + 1e-11, sEnvelope.MinY - 1e-11, |
| 5619 | sEnvelope.MaxY + 1e-11); |
| 5620 | } |
| 5621 | else |
| 5622 | { |
| 5623 | if (HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 5624 | { |
| 5625 | // If we do have a spatial index, and our filter contains the |
| 5626 | // bounding box of the RTree, then just filter on non-null |
| 5627 | // non-empty geometries. |
| 5628 | double minx, miny, maxx, maxy; |
| 5629 | if (GetExtentFromRTreecxx . . $ GetExtentFromRTree(a6706b96113a0024).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName., minx, |
| 5630 | miny, maxx, maxy) && |
| 5631 | sEnvelope.MinX <= minx && sEnvelope.MinY <= miny && |
| 5632 | sEnvelope.MaxX >= maxx && sEnvelope.MaxY >= maxy) |
| 5633 | { |
| 5634 | osSpatialWHERE.Printf( |
| 5635 | "(\"%s\" IS NOT NULL AND NOT ST_IsEmpty(\"%s\"))", |
| 5636 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC).c_str(), |
| 5637 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC).c_str()); |
| 5638 | return osSpatialWHERE; |
| 5639 | } |
| 5640 | } |
| 5641 | |
| 5642 | /* A bit inefficient but still faster than OGR filtering */ |
| 5643 | osSpatialWHERE.Printf( |
| 5644 | "ST_EnvelopesIntersects(\"%s\", %.12f, %.12f, %.12f, %.12f)", |
| 5645 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszC).c_str(), sEnvelope.MinX - 1e-11, |
| 5646 | sEnvelope.MinY - 1e-11, sEnvelope.MaxX + 1e-11, |
| 5647 | sEnvelope.MaxY + 1e-11); |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | return osSpatialWHERE; |
| 5652 | } |
| 5653 | |
| 5654 | /************************************************************************/ |
| 5655 | /* BuildWhere() */ |
| 5656 | /* */ |
| 5657 | /* Build the WHERE statement appropriate to the current set of */ |
| 5658 | /* criteria (spatial and attribute queries). */ |
| 5659 | /************************************************************************/ |
| 5660 | |
| 5661 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::BuildWherecxx . . $ OGRGeoPackageTableLayer#BuildWhere(49f6e7a06ebc5aa8).() |
| 5662 | |
| 5663 | { |
| 5664 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter. = ""; |
| 5665 | |
| 5666 | CPLString osSpatialWHERE = |
| 5667 | GetSpatialWherecxx . . $ OGRGeoPackageTableLayer#GetSpatialWhere(ac3cefc8daf1e661).(m_iGeomFieldFiltercxx . . $ OGRLayer#m_iGeomFieldFilter., m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom.); |
| 5668 | if (!osSpatialWHERE.empty()) |
| 5669 | { |
| 5670 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter. += osSpatialWHERE; |
| 5671 | } |
| 5672 | |
| 5673 | if (!osQuerycxx . . $ OGRGeoPackageTableLayer#osQuery..empty()) |
| 5674 | { |
| 5675 | if (m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty()) |
| 5676 | { |
| 5677 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter. += osQuerycxx . . $ OGRGeoPackageTableLayer#osQuery.; |
| 5678 | } |
| 5679 | else |
| 5680 | { |
| 5681 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter. += " AND ("; |
| 5682 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter. += osQuerycxx . . $ OGRGeoPackageTableLayer#osQuery.; |
| 5683 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter. += ")"; |
| 5684 | } |
| 5685 | } |
| 5686 | CPLDebug("GPKG", "Filter: %s", m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..c_str()); |
| 5687 | } |
| 5688 | |
| 5689 | /************************************************************************/ |
| 5690 | /* SetOpeningParameters() */ |
| 5691 | /************************************************************************/ |
| 5692 | |
| 5693 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetOpeningParameterscxx . . $ OGRGeoPackageTableLayer#SetOpeningParameters(b30d3aaecc52e8c1).( |
| 5694 | const char *pszTableName, const char *pszObjectType, bool bIsInGpkgContents, |
| 5695 | bool bIsSpatial, const char *pszGeomColName, const char *pszGeomType, |
| 5696 | bool bHasZ, bool bHasM) |
| 5697 | { |
| 5698 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 5699 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName. = CPLStrdup(pszTableName); |
| 5700 | m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. = EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszObjectType, "table"); |
| 5701 | m_bIsInGpkgContentscxx . . $ OGRGeoPackageTableLayer#m_bIsInGpkgContents. = bIsInGpkgContents; |
| 5702 | m_bIsSpatialcxx . . $ OGRGeoPackageTableLayer#m_bIsSpatial. = bIsSpatial; |
| 5703 | if (pszGeomType) |
| 5704 | { |
| 5705 | OGRwkbGeometryType eType = |
| 5706 | GPkgGeometryTypeToWKBcxx . . $ GPkgGeometryTypeToWKB(1208cc3a4d5c8a3c).(pszGeomType, bHasZ, bHasM); |
| 5707 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->SetGeomTypecxx . . $ OGRFeatureDefn#SetGeomType(f47ce3f1fe923726).(eType); |
| 5708 | if (eType != wkbNone) |
| 5709 | { |
| 5710 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->SetNamecxx . . $ OGRGeomFieldDefn#SetName(85c52e162fed56f9).(pszGeomColName); |
| 5711 | } |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | /************************************************************************/ |
| 5716 | /* SetCreationParameters() */ |
| 5717 | /************************************************************************/ |
| 5718 | |
| 5719 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetCreationParameterscxx . . $ OGRGeoPackageTableLayer#SetCreationParameters(1a37060f8d574f95).( |
| 5720 | OGRwkbGeometryType eGType, const char *pszGeomColumnName, int bGeomNullable, |
| 5721 | const OGRSpatialReferencecxx . . $ OGRSpatialReference# *poSRS, const char *pszSRID, |
| 5722 | const OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision# &oCoordPrec, bool bDiscardCoordLSB, |
| 5723 | bool bUndoDiscardCoordLSBOnReading, const char *pszFIDColumnName, |
| 5724 | const char *pszIdentifier, const char *pszDescription) |
| 5725 | { |
| 5726 | m_bIsSpatialcxx . . $ OGRGeoPackageTableLayer#m_bIsSpatial. = eGType != wkbNone; |
| 5727 | m_bIsInGpkgContentscxx . . $ OGRGeoPackageTableLayer#m_bIsInGpkgContents. = |
| 5728 | m_bIsSpatialcxx . . $ OGRGeoPackageTableLayer#m_bIsSpatial. || |
| 5729 | !m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasNonSpatialTablesNonRegisteredInGpkgContentscxx . . $ GDALGeoPackageDataset#HasNonSpatialTablesNonRegisteredInGpkgContents(50ce9a9e25b4a850).(); |
| 5730 | m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted. = true; |
| 5731 | m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. = true; |
| 5732 | m_bTableCreatedInTransactioncxx . . $ OGRGeoPackageTableLayer#m_bTableCreatedInTransaction. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).(); |
| 5733 | m_bHasTriedDetectingFID64cxx . . $ OGRGeoPackageTableLayer#m_bHasTriedDetectingFID64. = true; |
| 5734 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. = CPLStrdup(pszFIDColumnName); |
| 5735 | m_bUndoDiscardCoordLSBOnReadingcxx . . $ OGRGeoPackageLayer#m_bUndoDiscardCoordLSBOnReading. = bUndoDiscardCoordLSBOnReading; |
| 5736 | |
| 5737 | if (eGType != wkbNone) |
| 5738 | { |
| 5739 | m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. = wkbHasZcxx . . $ `ogr/ogr_core.h:581:9`!(eGType) ? 1 : 0; |
| 5740 | m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag. = wkbHasMcxx . . $ `ogr/ogr_core.h:589:9`!(eGType) ? 1 : 0; |
| 5741 | |
| 5742 | OGRSpatialReferenceRefCountedPtrcxx . . $ OGRSpatialReferenceRefCountedPtr# poGotSRScxx . . $ OGRRefCountedPtr#OGRRefCountedPtr(49f6e7a06ebc5aa8).; |
| 5743 | OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# oGeomFieldDefncxx . . $ OGRGeomFieldDefn#OGRGeomFieldDefn(465d6c96388e9b45).(pszGeomColumnName, eGType); |
| 5744 | |
| 5745 | oGeomFieldDefn.SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(poSRS); |
| 5746 | if (pszSRID) |
| 5747 | { |
| 5748 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = atoicxx . . $ atoi(f5ecf3191ed0cd93).(pszSRID); |
| 5749 | if (m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. == GDALGeoPackageDatasetcxx . . $ GDALGeoPackageDataset#::FIRST_CUSTOM_SRSIDcxx . . $ GDALGeoPackageDataset#FIRST_CUSTOM_SRSID. - 1) |
| 5750 | { |
| 5751 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSrsIdcxx . . $ GDALGeoPackageDataset#GetSrsId(8a145e066b724d94).(nullptr); |
| 5752 | oGeomFieldDefn.SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(nullptr); |
| 5753 | } |
| 5754 | else |
| 5755 | { |
| 5756 | poGotSRS =cxx . . $ OGRRefCountedPtr#`operator=`(75ecb2b9da62a289). |
| 5757 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSpatialRefcxx . . $ GDALGeoPackageDataset#GetSpatialRef(fc1cf25e62fcd527).(m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs., /* bFallbackToEPSG = */ false, |
| 5758 | /* bEmitErrorIfNotFound = */ false); |
| 5759 | if (poGotSRS) |
| 5760 | { |
| 5761 | oGeomFieldDefn.SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(poGotSRS.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 5762 | } |
| 5763 | else |
| 5764 | { |
| 5765 | bool bOK = false; |
| 5766 | auto poSRSTmp = |
| 5767 | OGRSpatialReferenceRefCountedPtrcxx . . $ OGRSpatialReferenceRefCountedPtr#::makeInstancecxx . . $ OGRRefCountedPtr#makeInstance(1adaeb8070080dba).(); |
| 5768 | if (m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. < 32767) |
| 5769 | { |
| 5770 | CPLErrorHandlerPusher oErrorHandler( |
| 5771 | CPLQuietErrorHandler); |
| 5772 | CPLErrorStateBackuper oBackuper; |
| 5773 | if (poSRSTmp->cxx . . $ OGRRefCountedPtrBase#`operator->`(5a2a78a048fb49a8).importFromEPSGcxx . . $ OGRSpatialReference#importFromEPSG(7864480464b09eea).(m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs.) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5774 | { |
| 5775 | bOK = true; |
| 5776 | poSRSTmp->cxx . . $ OGRRefCountedPtrBase#`operator->`(5a2a78a048fb49a8).SetAxisMappingStrategycxx . . $ OGRSpatialReference#SetAxisMappingStrategy(3d39f43974738d6a).( |
| 5777 | OAMS_TRADITIONAL_GIS_ORDER); |
| 5778 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSrsIdcxx . . $ GDALGeoPackageDataset#GetSrsId(8a145e066b724d94).(poSRSTmp.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 5779 | oGeomFieldDefn.SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(poSRSTmp.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 5780 | } |
| 5781 | } |
| 5782 | if (!bOK) |
| 5783 | { |
| 5784 | CPLError( |
| 5785 | CE_Warning, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 5786 | "No entry in gpkg_spatial_ref_sys matching SRID=%s", |
| 5787 | pszSRID); |
| 5788 | } |
| 5789 | } |
| 5790 | } |
| 5791 | } |
| 5792 | else |
| 5793 | { |
| 5794 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSrsIdcxx . . $ GDALGeoPackageDataset#GetSrsId(8a145e066b724d94).(poSRS); |
| 5795 | } |
| 5796 | oGeomFieldDefn.SetNullablecxx . . $ OGRGeomFieldDefn#SetNullable(d4f767463ce0a6b3).(bGeomNullable); |
| 5797 | oGeomFieldDefn.SetCoordinatePrecisioncxx . . $ OGRGeomFieldDefn#SetCoordinatePrecision(a66dcf8fa4d01368).(oCoordPrec); |
| 5798 | |
| 5799 | if (bDiscardCoordLSB) |
| 5800 | m_sBinaryPrecisioncxx . . $ OGRGeoPackageTableLayer#m_sBinaryPrecision..SetFromcxx . . $ OGRGeomCoordinateBinaryPrecision#SetFrom(a66dcf8fa4d01368).(oCoordPrec); |
| 5801 | |
| 5802 | // Save coordinate precision in gpkg_metadata/gpkg_metadata_reference |
| 5803 | if ((oCoordPrec.dfXYResolutioncxx . . $ OGRGeomCoordinatePrecision#dfXYResolution. != OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision#::UNKNOWNcxx . . $ OGRGeomCoordinatePrecision#UNKNOWN. || |
| 5804 | oCoordPrec.dfZResolutioncxx . . $ OGRGeomCoordinatePrecision#dfZResolution. != OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision#::UNKNOWNcxx . . $ OGRGeomCoordinatePrecision#UNKNOWN. || |
| 5805 | oCoordPrec.dfMResolutioncxx . . $ OGRGeomCoordinatePrecision#dfMResolution. != OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision#::UNKNOWNcxx . . $ OGRGeomCoordinatePrecision#UNKNOWN.) && |
| 5806 | (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasMetadataTablescxx . . $ GDALGeoPackageDataset#HasMetadataTables(50ce9a9e25b4a850).() || m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->CreateMetadataTablescxx . . $ GDALGeoPackageDataset#CreateMetadataTables(c9857a73d68e59ba).())) |
| 5807 | { |
| 5808 | stdcxx . . $ std/::string osCoordPrecision = "<CoordinatePrecision "; |
| 5809 | if (oCoordPrec.dfXYResolutioncxx . . $ OGRGeomCoordinatePrecision#dfXYResolution. != |
| 5810 | OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision#::UNKNOWNcxx . . $ OGRGeomCoordinatePrecision#UNKNOWN.) |
| 5811 | osCoordPrecision += CPLSPrintf(" xy_resolution=\"%g\"", |
| 5812 | oCoordPrec.dfXYResolutioncxx . . $ OGRGeomCoordinatePrecision#dfXYResolution.); |
| 5813 | if (oCoordPrec.dfZResolutioncxx . . $ OGRGeomCoordinatePrecision#dfZResolution. != OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision#::UNKNOWNcxx . . $ OGRGeomCoordinatePrecision#UNKNOWN.) |
| 5814 | osCoordPrecision += CPLSPrintf(" z_resolution=\"%g\"", |
| 5815 | oCoordPrec.dfZResolutioncxx . . $ OGRGeomCoordinatePrecision#dfZResolution.); |
| 5816 | if (oCoordPrec.dfMResolutioncxx . . $ OGRGeomCoordinatePrecision#dfMResolution. != OGRGeomCoordinatePrecisioncxx . . $ OGRGeomCoordinatePrecision#::UNKNOWNcxx . . $ OGRGeomCoordinatePrecision#UNKNOWN.) |
| 5817 | osCoordPrecision += CPLSPrintf(" m_resolution=\"%g\"", |
| 5818 | oCoordPrec.dfMResolutioncxx . . $ OGRGeomCoordinatePrecision#dfMResolution.); |
| 5819 | osCoordPrecision += CPLSPrintf(" discard_coord_lsb=\"%s\"", |
| 5820 | bDiscardCoordLSB ? "true" : "false"); |
| 5821 | osCoordPrecision += |
| 5822 | CPLSPrintf(" undo_discard_coord_lsb_on_reading=\"%s\"", |
| 5823 | m_bUndoDiscardCoordLSBOnReadingcxx . . $ OGRGeoPackageLayer#m_bUndoDiscardCoordLSBOnReading. ? "true" : "false"); |
| 5824 | osCoordPrecision += " />"; |
| 5825 | |
| 5826 | char *pszSQL = sqlite3_mprintf( |
| 5827 | "INSERT INTO gpkg_metadata " |
| 5828 | "(md_scope, md_standard_uri, mime_type, metadata) VALUES " |
| 5829 | "('dataset','http://gdal.org','text/xml','%q')", |
| 5830 | osCoordPrecision.c_str()); |
| 5831 | CPL_IGNORE_RET_VAL(SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL)); |
| 5832 | sqlite3_free(pszSQL); |
| 5833 | |
| 5834 | const sqlite_int64 nFID = |
| 5835 | sqlite3_last_insert_rowid(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 5836 | pszSQL = sqlite3_mprintf( |
| 5837 | "INSERT INTO gpkg_metadata_reference (reference_scope, " |
| 5838 | "table_name, column_name, timestamp, md_file_id) VALUES " |
| 5839 | "('column', '%q', '%q', %s, %d)", |
| 5840 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszGeomColumnName, |
| 5841 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentDateEscapedSQLcxx . . $ GDALGeoPackageDataset#GetCurrentDateEscapedSQL(efd28698952f529a).().c_str(), |
| 5842 | static_cast<int>(nFID)); |
| 5843 | CPL_IGNORE_RET_VAL(SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL)); |
| 5844 | sqlite3_free(pszSQL); |
| 5845 | } |
| 5846 | |
| 5847 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->AddGeomFieldDefncxx . . $ OGRFeatureDefn#AddGeomFieldDefn(9997450ff2bf2bb5).(&oGeomFieldDefn); |
| 5848 | } |
| 5849 | if (pszIdentifier) |
| 5850 | { |
| 5851 | m_osIdentifierLCOcxx . . $ OGRGeoPackageTableLayer#m_osIdentifierLCO. = pszIdentifier; |
| 5852 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).("IDENTIFIER", pszIdentifier); |
| 5853 | } |
| 5854 | if (pszDescription) |
| 5855 | { |
| 5856 | m_osDescriptionLCOcxx . . $ OGRGeoPackageTableLayer#m_osDescriptionLCO. = pszDescription; |
| 5857 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).("DESCRIPTION", pszDescription); |
| 5858 | } |
| 5859 | |
| 5860 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->Sealcxx . . $ OGRFeatureDefn#Seal(b45ddcbc8423892c).(/* bSealFields = */ true); |
| 5861 | } |
| 5862 | |
| 5863 | /************************************************************************/ |
| 5864 | /* RegisterGeometryColumn() */ |
| 5865 | /************************************************************************/ |
| 5866 | |
| 5867 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RegisterGeometryColumncxx . . $ OGRGeoPackageTableLayer#RegisterGeometryColumn(b126dc7c1de90089).() |
| 5868 | { |
| 5869 | OGRwkbGeometryType eGType = GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).(); |
| 5870 | const char *pszGeometryType = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetGeometryTypeStringcxx . . $ GDALGeoPackageDataset#GetGeometryTypeString(10f7d487d41f9e63).(eGType); |
| 5871 | /* Requirement 27: The z value in a gpkg_geometry_columns table row */ |
| 5872 | /* SHALL be one of 0 (none), 1 (mandatory), or 2 (optional) */ |
| 5873 | |
| 5874 | /* Update gpkg_geometry_columns with the table info */ |
| 5875 | char *pszSQL = |
| 5876 | sqlite3_mprintf("INSERT INTO gpkg_geometry_columns " |
| 5877 | "(table_name,column_name,geometry_type_name,srs_id,z,m)" |
| 5878 | " VALUES " |
| 5879 | "('%q','%q','%q',%d,%d,%d)", |
| 5880 | GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).(), GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).(), pszGeometryType, m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs., |
| 5881 | m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag., m_nMFlagcxx . . $ OGRGeoPackageTableLayer#m_nMFlag.); |
| 5882 | |
| 5883 | OGRErr err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 5884 | sqlite3_free(pszSQL); |
| 5885 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 5886 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 5887 | |
| 5888 | if (wkbFlattencxx . . $ `ogr/ogr_core.h:576:9`!(eGType) > wkbGeometryCollection) |
| 5889 | { |
| 5890 | CreateGeometryExtensionIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateGeometryExtensionIfNecessary(d700db20b643f27b).(eGType); |
| 5891 | } |
| 5892 | |
| 5893 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 5894 | } |
| 5895 | |
| 5896 | /************************************************************************/ |
| 5897 | /* GetColumnsOfCreateTable() */ |
| 5898 | /************************************************************************/ |
| 5899 | |
| 5900 | CPLString OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetColumnsOfCreateTablecxx . . $ OGRGeoPackageTableLayer#GetColumnsOfCreateTable(9590cd99db2695d5).( |
| 5901 | const stdcxx . . $ std/::vector<OGRFieldDefncxx . . $ OGRFieldDefn# *> &apoFields) |
| 5902 | { |
| 5903 | CPLString osSQL; |
| 5904 | |
| 5905 | char *pszSQL = nullptr; |
| 5906 | bool bNeedComma = false; |
| 5907 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr) |
| 5908 | { |
| 5909 | pszSQL = |
| 5910 | sqlite3_mprintf("\"%w\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL", |
| 5911 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 5912 | osSQL += pszSQL; |
| 5913 | sqlite3_free(pszSQL); |
| 5914 | bNeedComma = true; |
| 5915 | } |
| 5916 | |
| 5917 | const OGRwkbGeometryType eGType = GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).(); |
| 5918 | if (eGType != wkbNone) |
| 5919 | { |
| 5920 | if (bNeedComma) |
| 5921 | { |
| 5922 | osSQL += ", "; |
| 5923 | } |
| 5924 | bNeedComma = true; |
| 5925 | |
| 5926 | /* Requirement 25: The geometry_type_name value in a |
| 5927 | * gpkg_geometry_columns */ |
| 5928 | /* row SHALL be one of the uppercase geometry type names specified in */ |
| 5929 | /* Geometry Types (Normative). */ |
| 5930 | const char *pszGeometryType = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetGeometryTypeStringcxx . . $ GDALGeoPackageDataset#GetGeometryTypeString(10f7d487d41f9e63).(eGType); |
| 5931 | |
| 5932 | pszSQL = |
| 5933 | sqlite3_mprintf("\"%w\" %s", GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).(), pszGeometryType); |
| 5934 | osSQL += pszSQL; |
| 5935 | sqlite3_free(pszSQL); |
| 5936 | if (!m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->IsNullablecxx . . $ OGRGeomFieldDefn#IsNullable(455f465bc33b4cdf).()) |
| 5937 | { |
| 5938 | osSQL += " NOT NULL"; |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | for (size_t i = 0; i < apoFields.size(); i++) |
| 5943 | { |
| 5944 | OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = apoFields[i]; |
| 5945 | // Eg. when a geometry type is specified + an sql statement returns no |
| 5946 | // or NULL geometry values, the geom column is incorrectly treated as |
| 5947 | // an attribute column as well with the same name. Not ideal, but skip |
| 5948 | // this column here to avoid duplicate column name error. Issue: #6976. |
| 5949 | if ((eGType != wkbNone) && |
| 5950 | (EQUALcxx . . $ `port/cpl_port.h:532:9`!(poFieldDefn->GetNameRef(), GetGeometryColumn()))) |
| 5951 | { |
| 5952 | continue; |
| 5953 | } |
| 5954 | if (bNeedComma) |
| 5955 | { |
| 5956 | osSQL += ", "; |
| 5957 | } |
| 5958 | bNeedComma = true; |
| 5959 | |
| 5960 | pszSQL = sqlite3_mprintf("\"%w\" %s", poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 5961 | GPkgFieldFromOGRcxx . . $ GPkgFieldFromOGR(d1570bcf2edf7d6a).(poFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).(), |
| 5962 | poFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).(), |
| 5963 | poFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).())); |
| 5964 | osSQL += pszSQL; |
| 5965 | sqlite3_free(pszSQL); |
| 5966 | if (!poFieldDefn->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).()) |
| 5967 | { |
| 5968 | osSQL += " NOT NULL"; |
| 5969 | } |
| 5970 | if (poFieldDefn->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).()) |
| 5971 | { |
| 5972 | osSQL += " UNIQUE"; |
| 5973 | } |
| 5974 | const char *pszDefault = poFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(); |
| 5975 | if (pszDefault != nullptr && |
| 5976 | (!poFieldDefn->IsDefaultDriverSpecificcxx . . $ OGRFieldDefn#IsDefaultDriverSpecific(455f465bc33b4cdf).() || |
| 5977 | (pszDefault[0] == '(' && |
| 5978 | pszDefault[strlen(pszDefault) - 1] == ')' && |
| 5979 | (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(pszDefault + 1, "strftime") || |
| 5980 | STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(pszDefault + 1, " strftime"))))) |
| 5981 | { |
| 5982 | osSQL += " DEFAULT "; |
| 5983 | OGRField sField; |
| 5984 | if (poFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTDateTime && |
| 5985 | OGRParseDate(pszDefault, &sField, 0)) |
| 5986 | { |
| 5987 | char szBuffer[OGR_SIZEOF_ISO8601_DATETIME_BUFFERcxx . . $ `ogr/ogr_p.h:117:9`!]; |
| 5988 | OGRGetISO8601DateTimecxx . . $ OGRGetISO8601DateTime(2a8ec5ed4e656f20).(&sField, false, szBuffer); |
| 5989 | osSQL += szBuffer; |
| 5990 | } |
| 5991 | /* Make sure CURRENT_TIMESTAMP is translated into appropriate format |
| 5992 | * for GeoPackage */ |
| 5993 | else if (poFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTDateTime && |
| 5994 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszDefault, "CURRENT_TIMESTAMP")) |
| 5995 | { |
| 5996 | osSQL += "(strftime('%Y-%m-%dT%H:%M:%fZ','now'))"; |
| 5997 | } |
| 5998 | else |
| 5999 | { |
| 6000 | osSQL += poFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(); |
| 6001 | } |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | return osSQL; |
| 6006 | } |
| 6007 | |
| 6008 | /************************************************************************/ |
| 6009 | /* RunDeferredCreationIfNecessary() */ |
| 6010 | /************************************************************************/ |
| 6011 | |
| 6012 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() |
| 6013 | { |
| 6014 | if (!m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation.) |
| 6015 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 6016 | m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. = false; |
| 6017 | |
| 6018 | const char *pszLayerName = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetNamecxx . . $ OGRFeatureDefn#GetName(a9f41ea0e82d88cf).(); |
| 6019 | |
| 6020 | /* Create the table! */ |
| 6021 | CPLString osCommand; |
| 6022 | |
| 6023 | char *pszSQL = sqlite3_mprintf("CREATE TABLE \"%w\" ( ", pszLayerName); |
| 6024 | osCommand += pszSQL; |
| 6025 | sqlite3_free(pszSQL); |
| 6026 | |
| 6027 | stdcxx . . $ std/::vector<OGRFieldDefncxx . . $ OGRFieldDefn# *> apoFields; |
| 6028 | for (int i = 0; i < m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); i++) |
| 6029 | { |
| 6030 | if (i == m_iFIDAsRegularColumnIndexcxx . . $ OGRGeoPackageTableLayer#m_iFIDAsRegularColumnIndex.) |
| 6031 | continue; |
| 6032 | apoFields.push_back(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(i)); |
| 6033 | } |
| 6034 | |
| 6035 | osCommand += GetColumnsOfCreateTablecxx . . $ OGRGeoPackageTableLayer#GetColumnsOfCreateTable(9590cd99db2695d5).(apoFields); |
| 6036 | |
| 6037 | osCommand += ")"; |
| 6038 | |
| 6039 | #ifdef DEBUG |
| 6040 | CPLDebug("GPKG", "exec(%s)", osCommand.c_str()); |
| 6041 | #endif |
| 6042 | OGRErr err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osCommand.c_str()); |
| 6043 | if (OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! != err) |
| 6044 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6045 | |
| 6046 | for (auto &poField : apoFields) |
| 6047 | { |
| 6048 | if (!DoSpecialProcessingForColumnCreationcxx . . $ OGRGeoPackageTableLayer#DoSpecialProcessingForColumnCreation(6ac7e7c63d694732).(poField)) |
| 6049 | { |
| 6050 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | /* Update gpkg_contents with the table info */ |
| 6055 | const OGRwkbGeometryType eGType = GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).(); |
| 6056 | const bool bIsSpatial = (eGType != wkbNone); |
| 6057 | |
| 6058 | if (bIsSpatial || m_eASpatialVariantcxx . . $ OGRGeoPackageTableLayer#m_eASpatialVariant. == GPKG_ATTRIBUTEScxx . . $ GPKG_ATTRIBUTES.) |
| 6059 | { |
| 6060 | const char *pszIdentifier = GetMetadataItemcxx . . $ OGRGeoPackageTableLayer#GetMetadataItem(1320557f0feba62c).("IDENTIFIER"); |
| 6061 | if (pszIdentifier == nullptr) |
| 6062 | pszIdentifier = pszLayerName; |
| 6063 | const char *pszDescription = GetMetadataItemcxx . . $ OGRGeoPackageTableLayer#GetMetadataItem(1320557f0feba62c).("DESCRIPTION"); |
| 6064 | if (pszDescription == nullptr) |
| 6065 | pszDescription = ""; |
| 6066 | |
| 6067 | pszSQL = sqlite3_mprintf( |
| 6068 | "INSERT INTO gpkg_contents " |
| 6069 | "(table_name,data_type,identifier,description,last_change,srs_id) " |
| 6070 | "VALUES " |
| 6071 | "('%q','%q','%q','%q',%s,%d)", |
| 6072 | pszLayerName, (bIsSpatial ? "features" : "attributes"), |
| 6073 | pszIdentifier, pszDescription, |
| 6074 | GDALGeoPackageDatasetcxx . . $ GDALGeoPackageDataset#::GetCurrentDateEscapedSQLcxx . . $ GDALGeoPackageDataset#GetCurrentDateEscapedSQL(efd28698952f529a).().c_str(), m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs.); |
| 6075 | |
| 6076 | err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6077 | sqlite3_free(pszSQL); |
| 6078 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6079 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6080 | } |
| 6081 | |
| 6082 | if (bIsSpatial) |
| 6083 | { |
| 6084 | // Insert into gpkg_geometry_columns after gpkg_contents because of |
| 6085 | // foreign key constraints |
| 6086 | err = RegisterGeometryColumncxx . . $ OGRGeoPackageTableLayer#RegisterGeometryColumn(b126dc7c1de90089).(); |
| 6087 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6088 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6089 | } |
| 6090 | |
| 6091 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 6092 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 6093 | { |
| 6094 | pszSQL = sqlite3_mprintf("DELETE FROM gpkg_ogr_contents WHERE " |
| 6095 | "lower(table_name) = lower('%q')", |
| 6096 | pszLayerName); |
| 6097 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6098 | sqlite3_free(pszSQL); |
| 6099 | |
| 6100 | pszSQL = sqlite3_mprintf( |
| 6101 | "INSERT INTO gpkg_ogr_contents (table_name, feature_count) " |
| 6102 | "VALUES ('%q', 0)", |
| 6103 | pszLayerName); |
| 6104 | err = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6105 | sqlite3_free(pszSQL); |
| 6106 | if (err == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6107 | { |
| 6108 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = 0; |
| 6109 | m_bAddOGRFeatureCountTriggerscxx . . $ OGRGeoPackageTableLayer#m_bAddOGRFeatureCountTriggers. = true; |
| 6110 | } |
| 6111 | } |
| 6112 | #endif |
| 6113 | |
| 6114 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 6115 | |
| 6116 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 6117 | } |
| 6118 | |
| 6119 | /************************************************************************/ |
| 6120 | /* GetMetadata() */ |
| 6121 | /************************************************************************/ |
| 6122 | |
| 6123 | CSLConstListcxx . . $ CSLConstList# OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetMetadatacxx . . $ OGRGeoPackageTableLayer#GetMetadata(2103d2459cfb75c0).(const char *pszDomain) |
| 6124 | |
| 6125 | { |
| 6126 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 6127 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 6128 | if (!m_bHasTriedDetectingFID64cxx . . $ OGRGeoPackageTableLayer#m_bHasTriedDetectingFID64. && m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr) |
| 6129 | { |
| 6130 | m_bHasTriedDetectingFID64cxx . . $ OGRGeoPackageTableLayer#m_bHasTriedDetectingFID64. = true; |
| 6131 | |
| 6132 | /* -------------------------------------------------------------------- |
| 6133 | */ |
| 6134 | /* Find if the FID holds 64bit values */ |
| 6135 | /* -------------------------------------------------------------------- |
| 6136 | */ |
| 6137 | |
| 6138 | // Normally the fid should be AUTOINCREMENT, so check sqlite_sequence |
| 6139 | OGRErr err = OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 6140 | char *pszSQL = |
| 6141 | sqlite3_mprintf("SELECT seq FROM sqlite_sequence WHERE name = '%q'", |
| 6142 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6143 | CPLPushErrorHandler(CPLQuietErrorHandler); |
| 6144 | GIntBigcxx . . $ GIntBig# nMaxId = SQLGetInteger64cxx . . $ SQLGetInteger64(c8fc3d71eb4a6aab).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, &err); |
| 6145 | CPLPopErrorHandler(); |
| 6146 | sqlite3_free(pszSQL); |
| 6147 | if (err != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6148 | { |
| 6149 | CPLErrorReset(); |
| 6150 | |
| 6151 | // In case of error, fallback to taking the MAX of the FID |
| 6152 | pszSQL = sqlite3_mprintf("SELECT MAX(\"%w\") FROM \"%w\"", |
| 6153 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6154 | |
| 6155 | nMaxId = SQLGetInteger64cxx . . $ SQLGetInteger64(c8fc3d71eb4a6aab).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, nullptr); |
| 6156 | sqlite3_free(pszSQL); |
| 6157 | } |
| 6158 | if (nMaxId > INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) |
| 6159 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).(OLMD_FID64cxx . . $ `ogr/ogr_core.h:1089:9`!, "YES"); |
| 6160 | } |
| 6161 | |
| 6162 | if (m_bHasReadMetadataFromStoragecxx . . $ OGRGeoPackageTableLayer#m_bHasReadMetadataFromStorage.) |
| 6163 | return OGRLayercxx . . $ OGRLayer#::GetMetadatacxx . . $ GDALMajorObject#GetMetadata(2103d2459cfb75c0).(pszDomain); |
| 6164 | |
| 6165 | m_bHasReadMetadataFromStoragecxx . . $ OGRGeoPackageTableLayer#m_bHasReadMetadataFromStorage. = true; |
| 6166 | |
| 6167 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasMetadataTablescxx . . $ GDALGeoPackageDataset#HasMetadataTables(50ce9a9e25b4a850).()) |
| 6168 | return OGRLayercxx . . $ OGRLayer#::GetMetadatacxx . . $ GDALMajorObject#GetMetadata(2103d2459cfb75c0).(pszDomain); |
| 6169 | |
| 6170 | char *pszSQL = sqlite3_mprintf( |
| 6171 | "SELECT md.metadata, md.md_standard_uri, md.mime_type, " |
| 6172 | "mdr.reference_scope " |
| 6173 | "FROM gpkg_metadata md " |
| 6174 | "JOIN gpkg_metadata_reference mdr ON (md.id = mdr.md_file_id ) " |
| 6175 | "WHERE lower(mdr.table_name) = lower('%q') ORDER BY md.id " |
| 6176 | "LIMIT 1000", // to avoid denial of service |
| 6177 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6178 | |
| 6179 | auto oResult = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6180 | sqlite3_free(pszSQL); |
| 6181 | if (!oResult) |
| 6182 | { |
| 6183 | return OGRLayercxx . . $ OGRLayer#::GetMetadatacxx . . $ GDALMajorObject#GetMetadata(2103d2459cfb75c0).(pszDomain); |
| 6184 | } |
| 6185 | |
| 6186 | char **papszMetadata = CSLDuplicate(OGRLayercxx . . $ OGRLayer#::GetMetadatacxx . . $ GDALMajorObject#GetMetadata(2103d2459cfb75c0).()); |
| 6187 | |
| 6188 | /* GDAL metadata */ |
| 6189 | for (int i = 0; i < oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); i++) |
| 6190 | { |
| 6191 | const char *pszMetadata = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, i); |
| 6192 | const char *pszMDStandardURI = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, i); |
| 6193 | const char *pszMimeType = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, i); |
| 6194 | const char *pszReferenceScope = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(3, i); |
| 6195 | if (pszMetadata && pszMDStandardURI && pszMimeType && |
| 6196 | pszReferenceScope && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMDStandardURI, "http://gdal.org") && |
| 6197 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMimeType, "text/xml") && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszReferenceScope, "table")) |
| 6198 | { |
| 6199 | CPLXMLNodecxx . . $ CPLXMLNode# *psXMLNode = CPLParseXMLString(pszMetadata); |
| 6200 | if (psXMLNode) |
| 6201 | { |
| 6202 | GDALMultiDomainMetadatacxx . . $ GDALMultiDomainMetadata# oLocalMDMDcxx . . $ GDALMultiDomainMetadata#GDALMultiDomainMetadata(49f6e7a06ebc5aa8).; |
| 6203 | oLocalMDMD.XMLInitcxx . . $ GDALMultiDomainMetadata#XMLInit(c82e9931424fdd06).(psXMLNode, FALSEcxx . . $ `port/cpl_port.h:1180:9`!); |
| 6204 | |
| 6205 | papszMetadata = |
| 6206 | CSLMerge(papszMetadata, oLocalMDMD.GetMetadatacxx . . $ GDALMultiDomainMetadata#GetMetadata(9945f7050fb66ac).()); |
| 6207 | CSLConstListcxx . . $ CSLConstList# papszDomainList = oLocalMDMD.GetDomainListcxx . . $ GDALMultiDomainMetadata#GetDomainList(69503a37793e448d).(); |
| 6208 | CSLConstListcxx . . $ CSLConstList# papszIter = papszDomainList; |
| 6209 | while (papszIter && *papszIter) |
| 6210 | { |
| 6211 | if (!EQUALcxx . . $ `port/cpl_port.h:532:9`!(*papszIter, "")) |
| 6212 | oMDMDcxx . . $ GDALMajorObject#oMDMD..SetMetadatacxx . . $ GDALMultiDomainMetadata#SetMetadata(6c7b553169186fed).(oLocalMDMD.GetMetadatacxx . . $ GDALMultiDomainMetadata#GetMetadata(9945f7050fb66ac).(*papszIter), |
| 6213 | *papszIter); |
| 6214 | papszIter++; |
| 6215 | } |
| 6216 | |
| 6217 | CPLDestroyXMLNode(psXMLNode); |
| 6218 | } |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | OGRLayercxx . . $ OGRLayer#::SetMetadatacxx . . $ GDALMajorObject#SetMetadata(6c7b553169186fed).(papszMetadata); |
| 6223 | CSLDestroy(papszMetadata); |
| 6224 | papszMetadata = nullptr; |
| 6225 | |
| 6226 | /* Add non-GDAL metadata now */ |
| 6227 | int nNonGDALMDILocal = 1; |
| 6228 | for (int i = 0; i < oResult->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); i++) |
| 6229 | { |
| 6230 | const char *pszMetadata = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, i); |
| 6231 | const char *pszMDStandardURI = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, i); |
| 6232 | const char *pszMimeType = oResult->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, i); |
| 6233 | // const char* pszReferenceScope = oResult->GetValue(3, i); |
| 6234 | if (pszMetadata == nullptr || pszMDStandardURI == nullptr || |
| 6235 | pszMimeType == nullptr |
| 6236 | /* || pszReferenceScope == nullptr */) |
| 6237 | { |
| 6238 | // should not happen as there are NOT NULL constraints |
| 6239 | // But a database could lack such NOT NULL constraints or have |
| 6240 | // large values that would cause a memory allocation failure. |
| 6241 | continue; |
| 6242 | } |
| 6243 | // int bIsGPKGScope = EQUAL(pszReferenceScope, "geopackage"); |
| 6244 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMDStandardURI, "http://gdal.org") && |
| 6245 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMimeType, "text/xml")) |
| 6246 | continue; |
| 6247 | |
| 6248 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMDStandardURI, "http://gdal.org") && |
| 6249 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMimeType, "text/plain")) |
| 6250 | { |
| 6251 | if (STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(pszMetadata, "coordinate_epoch=")) |
| 6252 | { |
| 6253 | continue; |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | /*if( strcmp( pszMDStandardURI, "http://www.isotc211.org/2005/gmd" ) == |
| 6258 | 0 && strcmp( pszMimeType, "text/xml" ) == 0 ) |
| 6259 | { |
| 6260 | char* apszMD[2]; |
| 6261 | apszMD[0] = (char*)pszMetadata; |
| 6262 | apszMD[1] = NULL; |
| 6263 | oMDMD.SetMetadata(apszMD, "xml:MD_Metadata"); |
| 6264 | } |
| 6265 | else*/ |
| 6266 | { |
| 6267 | oMDMDcxx . . $ GDALMajorObject#oMDMD..SetMetadataItemcxx . . $ GDALMultiDomainMetadata#SetMetadataItem(216fc8eb9053a851).( |
| 6268 | CPLSPrintf("GPKG_METADATA_ITEM_%d", nNonGDALMDILocal), |
| 6269 | pszMetadata); |
| 6270 | nNonGDALMDILocal++; |
| 6271 | } |
| 6272 | } |
| 6273 | |
| 6274 | return OGRLayercxx . . $ OGRLayer#::GetMetadatacxx . . $ GDALMajorObject#GetMetadata(2103d2459cfb75c0).(pszDomain); |
| 6275 | } |
| 6276 | |
| 6277 | /************************************************************************/ |
| 6278 | /* GetMetadataItem() */ |
| 6279 | /************************************************************************/ |
| 6280 | |
| 6281 | const char *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetMetadataItemcxx . . $ OGRGeoPackageTableLayer#GetMetadataItem(1320557f0feba62c).(const char *pszName, |
| 6282 | const char *pszDomain) |
| 6283 | { |
| 6284 | return CSLFetchNameValue(GetMetadatacxx . . $ OGRGeoPackageTableLayer#GetMetadata(2103d2459cfb75c0).(pszDomain), pszName); |
| 6285 | } |
| 6286 | |
| 6287 | /************************************************************************/ |
| 6288 | /* GetMetadataDomainList() */ |
| 6289 | /************************************************************************/ |
| 6290 | |
| 6291 | char **OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetMetadataDomainListcxx . . $ OGRGeoPackageTableLayer#GetMetadataDomainList(de5739791ae7584).() |
| 6292 | { |
| 6293 | GetMetadatacxx . . $ OGRGeoPackageTableLayer#GetMetadata(2103d2459cfb75c0).(); |
| 6294 | return OGRLayercxx . . $ OGRLayer#::GetMetadataDomainListcxx . . $ GDALMajorObject#GetMetadataDomainList(de5739791ae7584).(); |
| 6295 | } |
| 6296 | |
| 6297 | /************************************************************************/ |
| 6298 | /* SetMetadata() */ |
| 6299 | /************************************************************************/ |
| 6300 | |
| 6301 | CPLErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetMetadatacxx . . $ OGRGeoPackageTableLayer#SetMetadata(6c7b553169186fed).(CSLConstListcxx . . $ CSLConstList# papszMetadata, |
| 6302 | const char *pszDomain) |
| 6303 | { |
| 6304 | GetMetadatacxx . . $ OGRGeoPackageTableLayer#GetMetadata(2103d2459cfb75c0).(); /* force loading from storage if needed */ |
| 6305 | CPLErr eErr = OGRLayercxx . . $ OGRLayer#::SetMetadatacxx . . $ GDALMajorObject#SetMetadata(6c7b553169186fed).(papszMetadata, pszDomain); |
| 6306 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SetMetadataDirtycxx . . $ GDALGeoPackageDataset#SetMetadataDirty(49f6e7a06ebc5aa8).(); |
| 6307 | if (pszDomain == nullptr || EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszDomain, "")) |
| 6308 | { |
| 6309 | if (!m_osIdentifierLCOcxx . . $ OGRGeoPackageTableLayer#m_osIdentifierLCO..empty()) |
| 6310 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).("IDENTIFIER", m_osIdentifierLCOcxx . . $ OGRGeoPackageTableLayer#m_osIdentifierLCO.); |
| 6311 | if (!m_osDescriptionLCOcxx . . $ OGRGeoPackageTableLayer#m_osDescriptionLCO..empty()) |
| 6312 | OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).("DESCRIPTION", m_osDescriptionLCOcxx . . $ OGRGeoPackageTableLayer#m_osDescriptionLCO.); |
| 6313 | } |
| 6314 | return eErr; |
| 6315 | } |
| 6316 | |
| 6317 | /************************************************************************/ |
| 6318 | /* SetMetadataItem() */ |
| 6319 | /************************************************************************/ |
| 6320 | |
| 6321 | CPLErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::SetMetadataItemcxx . . $ OGRGeoPackageTableLayer#SetMetadataItem(216fc8eb9053a851).(const char *pszName, |
| 6322 | const char *pszValue, |
| 6323 | const char *pszDomain) |
| 6324 | { |
| 6325 | GetMetadatacxx . . $ OGRGeoPackageTableLayer#GetMetadata(2103d2459cfb75c0).(); /* force loading from storage if needed */ |
| 6326 | if (!m_osIdentifierLCOcxx . . $ OGRGeoPackageTableLayer#m_osIdentifierLCO..empty() && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszName, "IDENTIFIER") && |
| 6327 | (pszDomain == nullptr || EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszDomain, ""))) |
| 6328 | return CE_None; |
| 6329 | if (!m_osDescriptionLCOcxx . . $ OGRGeoPackageTableLayer#m_osDescriptionLCO..empty() && EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszName, "DESCRIPTION") && |
| 6330 | (pszDomain == nullptr || EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszDomain, ""))) |
| 6331 | return CE_None; |
| 6332 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SetMetadataDirtycxx . . $ GDALGeoPackageDataset#SetMetadataDirty(49f6e7a06ebc5aa8).(); |
| 6333 | return OGRLayercxx . . $ OGRLayer#::SetMetadataItemcxx . . $ GDALMajorObject#SetMetadataItem(216fc8eb9053a851).(pszName, pszValue, pszDomain); |
| 6334 | } |
| 6335 | |
| 6336 | /************************************************************************/ |
| 6337 | /* RecreateTable() */ |
| 6338 | /************************************************************************/ |
| 6339 | |
| 6340 | OGRErr |
| 6341 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RecreateTablecxx . . $ OGRGeoPackageTableLayer#RecreateTable(10f17c25c9837c63).(const CPLString &osColumnsForCreate, |
| 6342 | const CPLString &osFieldListForSelect) |
| 6343 | { |
| 6344 | /* -------------------------------------------------------------------- */ |
| 6345 | /* Save existing related triggers and index */ |
| 6346 | /* -------------------------------------------------------------------- */ |
| 6347 | sqlite3 *hDB = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 6348 | |
| 6349 | char *pszSQL = sqlite3_mprintf( |
| 6350 | "SELECT sql FROM sqlite_master WHERE type IN ('trigger','index') " |
| 6351 | "AND lower(tbl_name)=lower('%q') LIMIT 10000", |
| 6352 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6353 | OGRErr eErr = OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 6354 | auto oTriggers = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(hDB, pszSQL); |
| 6355 | sqlite3_free(pszSQL); |
| 6356 | |
| 6357 | /* -------------------------------------------------------------------- */ |
| 6358 | /* Make a temporary table with new content. */ |
| 6359 | /* -------------------------------------------------------------------- */ |
| 6360 | if (oTriggers) |
| 6361 | { |
| 6362 | pszSQL = sqlite3_mprintf("CREATE TABLE \"%w_ogr_tmp\" (%s)", |
| 6363 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., osColumnsForCreate.c_str()); |
| 6364 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6365 | sqlite3_free(pszSQL); |
| 6366 | } |
| 6367 | else |
| 6368 | { |
| 6369 | eErr = OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6370 | } |
| 6371 | |
| 6372 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6373 | { |
| 6374 | pszSQL = sqlite3_mprintf( |
| 6375 | "INSERT INTO \"%w_ogr_tmp\" SELECT %s FROM \"%w\"", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., |
| 6376 | osFieldListForSelect.c_str(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6377 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6378 | sqlite3_free(pszSQL); |
| 6379 | } |
| 6380 | |
| 6381 | /* -------------------------------------------------------------------- */ |
| 6382 | /* Drop the original table */ |
| 6383 | /* -------------------------------------------------------------------- */ |
| 6384 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6385 | { |
| 6386 | pszSQL = sqlite3_mprintf("DROP TABLE \"%w\"", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6387 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6388 | sqlite3_free(pszSQL); |
| 6389 | } |
| 6390 | |
| 6391 | /* -------------------------------------------------------------------- */ |
| 6392 | /* Rename temporary table as new table */ |
| 6393 | /* -------------------------------------------------------------------- */ |
| 6394 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6395 | { |
| 6396 | pszSQL = sqlite3_mprintf("ALTER TABLE \"%w_ogr_tmp\" RENAME TO \"%w\"", |
| 6397 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6398 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6399 | sqlite3_free(pszSQL); |
| 6400 | } |
| 6401 | |
| 6402 | /* -------------------------------------------------------------------- */ |
| 6403 | /* Recreate existing related tables, triggers and index */ |
| 6404 | /* -------------------------------------------------------------------- */ |
| 6405 | for (int i = 0; |
| 6406 | oTriggers && i < oTriggers->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() && eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; i++) |
| 6407 | { |
| 6408 | const char *pszSQLTriggerIdx = oTriggers->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, i); |
| 6409 | if (pszSQLTriggerIdx != nullptr && *pszSQLTriggerIdx != '\0') |
| 6410 | { |
| 6411 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQLTriggerIdx); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | return eErr; |
| 6416 | } |
| 6417 | |
| 6418 | /************************************************************************/ |
| 6419 | /* BuildSelectFieldList() */ |
| 6420 | /************************************************************************/ |
| 6421 | |
| 6422 | CPLString OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::BuildSelectFieldListcxx . . $ OGRGeoPackageTableLayer#BuildSelectFieldList(9590cd99db2695d5).( |
| 6423 | const stdcxx . . $ std/::vector<OGRFieldDefncxx . . $ OGRFieldDefn# *> &apoFields) |
| 6424 | { |
| 6425 | CPLString osFieldListForSelect; |
| 6426 | |
| 6427 | char *pszSQL = nullptr; |
| 6428 | bool bNeedComma = false; |
| 6429 | |
| 6430 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. != nullptr) |
| 6431 | { |
| 6432 | pszSQL = sqlite3_mprintf("\"%w\"", m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 6433 | osFieldListForSelect += pszSQL; |
| 6434 | sqlite3_free(pszSQL); |
| 6435 | bNeedComma = true; |
| 6436 | } |
| 6437 | |
| 6438 | if (GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).() != wkbNone) |
| 6439 | { |
| 6440 | if (bNeedComma) |
| 6441 | { |
| 6442 | osFieldListForSelect += ", "; |
| 6443 | } |
| 6444 | bNeedComma = true; |
| 6445 | |
| 6446 | pszSQL = sqlite3_mprintf("\"%w\"", GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).()); |
| 6447 | osFieldListForSelect += pszSQL; |
| 6448 | sqlite3_free(pszSQL); |
| 6449 | } |
| 6450 | |
| 6451 | for (size_t iField = 0; iField < apoFields.size(); iField++) |
| 6452 | { |
| 6453 | if (bNeedComma) |
| 6454 | { |
| 6455 | osFieldListForSelect += ", "; |
| 6456 | } |
| 6457 | bNeedComma = true; |
| 6458 | |
| 6459 | OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = apoFields[iField]; |
| 6460 | pszSQL = sqlite3_mprintf("\"%w\"", poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 6461 | osFieldListForSelect += pszSQL; |
| 6462 | sqlite3_free(pszSQL); |
| 6463 | } |
| 6464 | |
| 6465 | return osFieldListForSelect; |
| 6466 | } |
| 6467 | |
| 6468 | /************************************************************************/ |
| 6469 | /* DeleteField() */ |
| 6470 | /************************************************************************/ |
| 6471 | |
| 6472 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::DeleteFieldcxx . . $ OGRGeoPackageTableLayer#DeleteField(7864480464b09eea).(int iFieldToDelete) |
| 6473 | { |
| 6474 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 6475 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 6476 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("DeleteField")) |
| 6477 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6478 | |
| 6479 | if (iFieldToDelete < 0 || |
| 6480 | iFieldToDelete >= m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).()) |
| 6481 | { |
| 6482 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Invalid field index"); |
| 6483 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6484 | } |
| 6485 | |
| 6486 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 6487 | RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).(); |
| 6488 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 6489 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6490 | |
| 6491 | const char *pszFieldName = |
| 6492 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iFieldToDelete)->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 6493 | |
| 6494 | /* -------------------------------------------------------------------- */ |
| 6495 | /* Drop any iterator since we change the DB structure */ |
| 6496 | /* -------------------------------------------------------------------- */ |
| 6497 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ResetReadingAllLayerscxx . . $ GDALGeoPackageDataset#ResetReadingAllLayers(49f6e7a06ebc5aa8).(); |
| 6498 | |
| 6499 | // Temporary remove foreign key checks |
| 6500 | const GPKGTemporaryForeignKeyCheckDisablercxx . . $ GPKGTemporaryForeignKeyCheckDisabler# |
| 6501 | oGPKGTemporaryForeignKeyCheckDisablercxx . . $ GPKGTemporaryForeignKeyCheckDisabler#GPKGTemporaryForeignKeyCheckDisabler(708af067f9bb9c4a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.); |
| 6502 | |
| 6503 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentSavepointcxx . . $ OGRSQLiteBaseDataSource#GetCurrentSavepoint(219584694fe2b248).().empty() && |
| 6504 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6505 | { |
| 6506 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6507 | } |
| 6508 | |
| 6509 | // ALTER TABLE ... DROP COLUMN ... was first implemented in 3.35.0 but |
| 6510 | // there was bug fixes related to it until 3.35.5 |
| 6511 | #if SQLITE_VERSION_NUMBERcxx . . $ `<external>/2400532043262193228/sqlite3.h:150:9`! >= 3035005L |
| 6512 | OGRErr eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).( |
| 6513 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), CPLString() |
| 6514 | .Printf("ALTER TABLE \"%s\" DROP COLUMN \"%s\"", |
| 6515 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 6516 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(pszFieldName).c_str()) |
| 6517 | .c_str()); |
| 6518 | #else |
| 6519 | /* -------------------------------------------------------------------- */ |
| 6520 | /* Recreate table in a transaction */ |
| 6521 | /* Build list of old fields, and the list of new fields. */ |
| 6522 | /* -------------------------------------------------------------------- */ |
| 6523 | std::vector<OGRFieldDefn *> apoFields; |
| 6524 | for (int iField = 0; iField < m_poFeatureDefn->GetFieldCount(); iField++) |
| 6525 | { |
| 6526 | if (iField == iFieldToDelete) |
| 6527 | continue; |
| 6528 | |
| 6529 | OGRFieldDefn *poFieldDefn = m_poFeatureDefn->GetFieldDefn(iField); |
| 6530 | apoFields.push_back(poFieldDefn); |
| 6531 | } |
| 6532 | |
| 6533 | CPLString osFieldListForSelect(BuildSelectFieldList(apoFields)); |
| 6534 | CPLString osColumnsForCreate(GetColumnsOfCreateTable(apoFields)); |
| 6535 | |
| 6536 | OGRErr eErr = RecreateTable(osColumnsForCreate, osFieldListForSelect); |
| 6537 | #endif |
| 6538 | |
| 6539 | /* -------------------------------------------------------------------- */ |
| 6540 | /* Update gpkg_extensions if needed. */ |
| 6541 | /* -------------------------------------------------------------------- */ |
| 6542 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasExtensionsTablecxx . . $ GDALGeoPackageDataset#HasExtensionsTable(c9857a73d68e59ba).()) |
| 6543 | { |
| 6544 | char *pszSQL = sqlite3_mprintf("DELETE FROM gpkg_extensions WHERE " |
| 6545 | "lower(table_name) = lower('%q') AND " |
| 6546 | "lower(column_name) = lower('%q')", |
| 6547 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszFieldName); |
| 6548 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6549 | sqlite3_free(pszSQL); |
| 6550 | } |
| 6551 | |
| 6552 | /* -------------------------------------------------------------------- */ |
| 6553 | /* Update gpkg_data_columns if needed. */ |
| 6554 | /* -------------------------------------------------------------------- */ |
| 6555 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasDataColumnsTablecxx . . $ GDALGeoPackageDataset#HasDataColumnsTable(50ce9a9e25b4a850).()) |
| 6556 | { |
| 6557 | char *pszSQL = sqlite3_mprintf("DELETE FROM gpkg_data_columns WHERE " |
| 6558 | "lower(table_name) = lower('%q') AND " |
| 6559 | "lower(column_name) = lower('%q')", |
| 6560 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszFieldName); |
| 6561 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6562 | sqlite3_free(pszSQL); |
| 6563 | } |
| 6564 | |
| 6565 | /* -------------------------------------------------------------------- */ |
| 6566 | /* Update gpkg_metadata_reference if needed. */ |
| 6567 | /* -------------------------------------------------------------------- */ |
| 6568 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasMetadataTablescxx . . $ GDALGeoPackageDataset#HasMetadataTables(50ce9a9e25b4a850).()) |
| 6569 | { |
| 6570 | { |
| 6571 | // Delete from gpkg_metadata metadata records that are only |
| 6572 | // referenced by the column we are about to drop |
| 6573 | char *pszSQL = sqlite3_mprintf( |
| 6574 | "DELETE FROM gpkg_metadata WHERE id IN (" |
| 6575 | "SELECT DISTINCT md_file_id FROM " |
| 6576 | "gpkg_metadata_reference WHERE " |
| 6577 | "lower(table_name) = lower('%q') " |
| 6578 | "AND lower(column_name) = lower('%q') " |
| 6579 | "AND md_parent_id is NULL) " |
| 6580 | "AND id NOT IN (" |
| 6581 | "SELECT DISTINCT md_file_id FROM gpkg_metadata_reference WHERE " |
| 6582 | "md_file_id IN (" |
| 6583 | "SELECT DISTINCT md_file_id FROM " |
| 6584 | "gpkg_metadata_reference WHERE " |
| 6585 | "lower(table_name) = lower('%q') " |
| 6586 | "AND lower(column_name) = lower('%q') " |
| 6587 | "AND md_parent_id is NULL) " |
| 6588 | "AND (" |
| 6589 | "lower(table_name) <> lower('%q') " |
| 6590 | "OR column_name IS NULL " |
| 6591 | "OR lower(column_name) <> lower('%q')))", |
| 6592 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszFieldName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszFieldName, |
| 6593 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszFieldName); |
| 6594 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6595 | sqlite3_free(pszSQL); |
| 6596 | } |
| 6597 | |
| 6598 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6599 | { |
| 6600 | char *pszSQL = |
| 6601 | sqlite3_mprintf("DELETE FROM gpkg_metadata_reference WHERE " |
| 6602 | "lower(table_name) = lower('%q') AND " |
| 6603 | "lower(column_name) = lower('%q')", |
| 6604 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszFieldName); |
| 6605 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 6606 | sqlite3_free(pszSQL); |
| 6607 | } |
| 6608 | } |
| 6609 | |
| 6610 | /* -------------------------------------------------------------------- */ |
| 6611 | /* Check foreign key integrity if enforcement of foreign keys */ |
| 6612 | /* constraint is enabled. */ |
| 6613 | /* -------------------------------------------------------------------- */ |
| 6614 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && |
| 6615 | SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "PRAGMA foreign_keys", nullptr)) |
| 6616 | { |
| 6617 | CPLDebug("GPKG", "Running PRAGMA foreign_key_check"); |
| 6618 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->PragmaCheckcxx . . $ OGRSQLiteBaseDataSource#PragmaCheck(f0be30763a490cce).("foreign_key_check", "", 0); |
| 6619 | } |
| 6620 | |
| 6621 | /* -------------------------------------------------------------------- */ |
| 6622 | /* Finish */ |
| 6623 | /* -------------------------------------------------------------------- */ |
| 6624 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6625 | { |
| 6626 | |
| 6627 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentSavepointcxx . . $ OGRSQLiteBaseDataSource#GetCurrentSavepoint(219584694fe2b248).().empty()) |
| 6628 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 6629 | |
| 6630 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6631 | { |
| 6632 | |
| 6633 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).()) |
| 6634 | { |
| 6635 | auto poFieldDefn{whileUnsealingcxx . . $ whileUnsealing(de07598ec200be45).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.) |
| 6636 | ->cxx . . $ OGRFeatureDefn#TemporaryUnsealer#`operator->`(407fccde18759965).StealFieldDefncxx . . $ OGRFeatureDefn#StealFieldDefn(d6bc6377e2bca395).(iFieldToDelete)}; |
| 6637 | if (poFieldDefn) |
| 6638 | { |
| 6639 | m_apoFieldDefnChangescxx . . $ OGRLayer#m_apoFieldDefnChanges..emplace_back( |
| 6640 | stdcxx . . $ std/::move(poFieldDefn), iFieldToDelete, |
| 6641 | FieldChangeTypecxx . . $ OGRLayer#FieldChangeType#::DELETE_FIELDcxx . . $ OGRLayer#FieldChangeType#DELETE_FIELD., |
| 6642 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentSavepointcxx . . $ OGRSQLiteBaseDataSource#GetCurrentSavepoint(219584694fe2b248).()); |
| 6643 | } |
| 6644 | else |
| 6645 | { |
| 6646 | eErr = OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6647 | } |
| 6648 | } |
| 6649 | else |
| 6650 | { |
| 6651 | eErr = whileUnsealingcxx . . $ whileUnsealing(de07598ec200be45).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.) |
| 6652 | ->cxx . . $ OGRFeatureDefn#TemporaryUnsealer#`operator->`(407fccde18759965).DeleteFieldDefncxx . . $ OGRFeatureDefn#DeleteFieldDefn(7864480464b09eea).(iFieldToDelete); |
| 6653 | } |
| 6654 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 6655 | } |
| 6656 | } |
| 6657 | else if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentSavepointcxx . . $ OGRSQLiteBaseDataSource#GetCurrentSavepoint(219584694fe2b248).().empty()) |
| 6658 | { |
| 6659 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 6660 | } |
| 6661 | |
| 6662 | return eErr; |
| 6663 | } |
| 6664 | |
| 6665 | /************************************************************************/ |
| 6666 | /* RenameFieldInAuxiliaryTables() */ |
| 6667 | /************************************************************************/ |
| 6668 | |
| 6669 | OGRErr |
| 6670 | OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::RenameFieldInAuxiliaryTablescxx . . $ OGRGeoPackageTableLayer#RenameFieldInAuxiliaryTables(5ae29d726ae57f88).(const char *pszOldName, |
| 6671 | const char *pszNewName) |
| 6672 | { |
| 6673 | OGRErr eErr = OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 6674 | sqlite3 *hDB = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 6675 | |
| 6676 | /* -------------------------------------------------------------------- */ |
| 6677 | /* Update gpkg_extensions if needed. */ |
| 6678 | /* -------------------------------------------------------------------- */ |
| 6679 | if (/* eErr == OGRERR_NONE && */ m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasExtensionsTablecxx . . $ GDALGeoPackageDataset#HasExtensionsTable(c9857a73d68e59ba).()) |
| 6680 | { |
| 6681 | char *pszSQL = sqlite3_mprintf( |
| 6682 | "UPDATE gpkg_extensions SET column_name = '%q' WHERE " |
| 6683 | "lower(table_name) = lower('%q') AND lower(column_name) = " |
| 6684 | "lower('%q')", |
| 6685 | pszNewName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszOldName); |
| 6686 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6687 | sqlite3_free(pszSQL); |
| 6688 | } |
| 6689 | |
| 6690 | /* -------------------------------------------------------------------- */ |
| 6691 | /* Update gpkg_data_columns if needed. */ |
| 6692 | /* -------------------------------------------------------------------- */ |
| 6693 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasDataColumnsTablecxx . . $ GDALGeoPackageDataset#HasDataColumnsTable(50ce9a9e25b4a850).()) |
| 6694 | { |
| 6695 | char *pszSQL = sqlite3_mprintf( |
| 6696 | "UPDATE gpkg_data_columns SET column_name = '%q' WHERE " |
| 6697 | "lower(table_name) = lower('%q') AND lower(column_name) = " |
| 6698 | "lower('%q')", |
| 6699 | pszNewName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszOldName); |
| 6700 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6701 | sqlite3_free(pszSQL); |
| 6702 | } |
| 6703 | |
| 6704 | /* -------------------------------------------------------------------- */ |
| 6705 | /* Update gpkg_metadata_reference if needed. */ |
| 6706 | /* -------------------------------------------------------------------- */ |
| 6707 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasMetadataTablescxx . . $ GDALGeoPackageDataset#HasMetadataTables(50ce9a9e25b4a850).()) |
| 6708 | { |
| 6709 | char *pszSQL = sqlite3_mprintf( |
| 6710 | "UPDATE gpkg_metadata_reference SET column_name = '%q' WHERE " |
| 6711 | "lower(table_name) = lower('%q') AND lower(column_name) = " |
| 6712 | "lower('%q')", |
| 6713 | pszNewName, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszOldName); |
| 6714 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6715 | sqlite3_free(pszSQL); |
| 6716 | } |
| 6717 | |
| 6718 | return eErr; |
| 6719 | } |
| 6720 | |
| 6721 | /************************************************************************/ |
| 6722 | /* AlterFieldDefn() */ |
| 6723 | /************************************************************************/ |
| 6724 | |
| 6725 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::AlterFieldDefncxx . . $ OGRGeoPackageTableLayer#AlterFieldDefn(a8f2b8f690332f80).(int iFieldToAlter, |
| 6726 | OGRFieldDefncxx . . $ OGRFieldDefn# *poNewFieldDefn, |
| 6727 | int nFlagsIn) |
| 6728 | { |
| 6729 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 6730 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 6731 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("AlterFieldDefn")) |
| 6732 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6733 | |
| 6734 | if (iFieldToAlter < 0 || iFieldToAlter >= m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).()) |
| 6735 | { |
| 6736 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Invalid field index"); |
| 6737 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6738 | } |
| 6739 | |
| 6740 | /* -------------------------------------------------------------------- */ |
| 6741 | /* Deferred actions, reset state. */ |
| 6742 | /* -------------------------------------------------------------------- */ |
| 6743 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 6744 | RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).(); |
| 6745 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 6746 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 6747 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 6748 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6749 | |
| 6750 | /* -------------------------------------------------------------------- */ |
| 6751 | /* Check that the new column name is not a duplicate. */ |
| 6752 | /* -------------------------------------------------------------------- */ |
| 6753 | |
| 6754 | OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefnToAlter = |
| 6755 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iFieldToAlter); |
| 6756 | const CPLString osOldColName(poFieldDefnToAlter->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 6757 | const CPLString osNewColName((nFlagsIn & ALTER_NAME_FLAGcxx . . $ `ogr/ogr_core.h:652:9`!) |
| 6758 | ? CPLString(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) |
| 6759 | : osOldColName); |
| 6760 | |
| 6761 | const bool bRenameCol = |
| 6762 | (nFlagsIn & ALTER_NAME_FLAGcxx . . $ `ogr/ogr_core.h:652:9`!) && |
| 6763 | strcmp(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), osOldColName) != 0; |
| 6764 | if (bRenameCol) |
| 6765 | { |
| 6766 | if ((m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. && |
| 6767 | strcmp(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.) == 0) || |
| 6768 | (GetGeomTypecxx . . $ OGRGeoPackageTableLayer#GetGeomType(5a40c54c5ff210ce).() != wkbNone && |
| 6769 | strcmp(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 6770 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) == 0) || |
| 6771 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldIndexcxx . . $ OGRFeatureDefn#GetFieldIndex(78f035161ffa9fe2).(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) >= 0) |
| 6772 | { |
| 6773 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 6774 | "Field name %s is already used for another field", |
| 6775 | poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 6776 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | /* -------------------------------------------------------------------- */ |
| 6781 | /* Build the modified field definition from the flags. */ |
| 6782 | /* -------------------------------------------------------------------- */ |
| 6783 | OGRFieldDefncxx . . $ OGRFieldDefn# oTmpFieldDefncxx . . $ OGRFieldDefn#OGRFieldDefn(f8bad7d30df65bbb).(poFieldDefnToAlter); |
| 6784 | bool bUseRewriteSchemaMethod = (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_nSoftTransactionLevelcxx . . $ OGRSQLiteBaseDataSource#m_nSoftTransactionLevel. == 0); |
| 6785 | int nActualFlags = 0; |
| 6786 | if (bRenameCol) |
| 6787 | { |
| 6788 | nActualFlags |= ALTER_NAME_FLAGcxx . . $ `ogr/ogr_core.h:652:9`!; |
| 6789 | oTmpFieldDefn.SetNamecxx . . $ OGRFieldDefn#SetName(85c52e162fed56f9).(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 6790 | } |
| 6791 | if ((nFlagsIn & ALTER_TYPE_FLAGcxx . . $ `ogr/ogr_core.h:657:9`!) != 0 && |
| 6792 | (poFieldDefnToAlter->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() != poNewFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() || |
| 6793 | poFieldDefnToAlter->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).() != poNewFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).())) |
| 6794 | { |
| 6795 | nActualFlags |= ALTER_TYPE_FLAGcxx . . $ `ogr/ogr_core.h:657:9`!; |
| 6796 | oTmpFieldDefn.SetSubTypecxx . . $ OGRFieldDefn#SetSubType(89cba9d8fed1b3f9).(OFSTNone); |
| 6797 | oTmpFieldDefn.SetTypecxx . . $ OGRFieldDefn#SetType(cc683e085121359d).(poNewFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).()); |
| 6798 | oTmpFieldDefn.SetSubTypecxx . . $ OGRFieldDefn#SetSubType(89cba9d8fed1b3f9).(poNewFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).()); |
| 6799 | } |
| 6800 | if ((nFlagsIn & ALTER_WIDTH_PRECISION_FLAGcxx . . $ `ogr/ogr_core.h:662:9`!) != 0 && |
| 6801 | (poFieldDefnToAlter->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).() != poNewFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).() || |
| 6802 | poFieldDefnToAlter->GetPrecisioncxx . . $ OGRFieldDefn#GetPrecision(455f465bc33b4cdf).() != poNewFieldDefn->GetPrecisioncxx . . $ OGRFieldDefn#GetPrecision(455f465bc33b4cdf).())) |
| 6803 | { |
| 6804 | nActualFlags |= ALTER_WIDTH_PRECISION_FLAGcxx . . $ `ogr/ogr_core.h:662:9`!; |
| 6805 | oTmpFieldDefn.SetWidthcxx . . $ OGRFieldDefn#SetWidth(d4f767463ce0a6b3).(poNewFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).()); |
| 6806 | oTmpFieldDefn.SetPrecisioncxx . . $ OGRFieldDefn#SetPrecision(d4f767463ce0a6b3).(poNewFieldDefn->GetPrecisioncxx . . $ OGRFieldDefn#GetPrecision(455f465bc33b4cdf).()); |
| 6807 | } |
| 6808 | if ((nFlagsIn & ALTER_NULLABLE_FLAGcxx . . $ `ogr/ogr_core.h:667:9`!) != 0 && |
| 6809 | poFieldDefnToAlter->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).() != poNewFieldDefn->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).()) |
| 6810 | { |
| 6811 | nActualFlags |= ALTER_NULLABLE_FLAGcxx . . $ `ogr/ogr_core.h:667:9`!; |
| 6812 | bUseRewriteSchemaMethod = false; |
| 6813 | oTmpFieldDefn.SetNullablecxx . . $ OGRFieldDefn#SetNullable(d4f767463ce0a6b3).(poNewFieldDefn->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).()); |
| 6814 | } |
| 6815 | if ((nFlagsIn & ALTER_DEFAULT_FLAGcxx . . $ `ogr/ogr_core.h:672:9`!) != 0 && |
| 6816 | !((poFieldDefnToAlter->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).() == nullptr && |
| 6817 | poNewFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).() == nullptr) || |
| 6818 | (poFieldDefnToAlter->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).() != nullptr && |
| 6819 | poNewFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).() != nullptr && |
| 6820 | strcmp(poFieldDefnToAlter->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).(), |
| 6821 | poNewFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).()) == 0))) |
| 6822 | { |
| 6823 | nActualFlags |= ALTER_DEFAULT_FLAGcxx . . $ `ogr/ogr_core.h:672:9`!; |
| 6824 | oTmpFieldDefn.SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).(poNewFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).()); |
| 6825 | } |
| 6826 | if ((nFlagsIn & ALTER_UNIQUE_FLAGcxx . . $ `ogr/ogr_core.h:678:9`!) != 0 && |
| 6827 | poFieldDefnToAlter->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).() != poNewFieldDefn->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).()) |
| 6828 | { |
| 6829 | nActualFlags |= ALTER_UNIQUE_FLAGcxx . . $ `ogr/ogr_core.h:678:9`!; |
| 6830 | bUseRewriteSchemaMethod = false; |
| 6831 | oTmpFieldDefn.SetUniquecxx . . $ OGRFieldDefn#SetUnique(d4f767463ce0a6b3).(poNewFieldDefn->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).()); |
| 6832 | } |
| 6833 | if ((nFlagsIn & ALTER_DOMAIN_FLAGcxx . . $ `ogr/ogr_core.h:684:9`!) != 0 && |
| 6834 | poFieldDefnToAlter->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).() != poNewFieldDefn->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).()) |
| 6835 | { |
| 6836 | nActualFlags |= ALTER_DOMAIN_FLAGcxx . . $ `ogr/ogr_core.h:684:9`!; |
| 6837 | oTmpFieldDefn.SetDomainNamecxx . . $ OGRFieldDefn#SetDomainName(9c546c94e5fcce4e).(poNewFieldDefn->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).()); |
| 6838 | } |
| 6839 | if ((nFlagsIn & ALTER_ALTERNATIVE_NAME_FLAGcxx . . $ `ogr/ogr_core.h:690:9`!) != 0 && |
| 6840 | strcmp(poFieldDefnToAlter->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).(), |
| 6841 | poNewFieldDefn->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).()) != 0) |
| 6842 | { |
| 6843 | nActualFlags |= ALTER_ALTERNATIVE_NAME_FLAGcxx . . $ `ogr/ogr_core.h:690:9`!; |
| 6844 | oTmpFieldDefn.SetAlternativeNamecxx . . $ OGRFieldDefn#SetAlternativeName(85c52e162fed56f9).( |
| 6845 | poNewFieldDefn->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).()); |
| 6846 | } |
| 6847 | if ((nFlagsIn & ALTER_COMMENT_FLAGcxx . . $ `ogr/ogr_core.h:696:9`!) != 0 && |
| 6848 | poFieldDefnToAlter->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).() != poNewFieldDefn->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).()) |
| 6849 | { |
| 6850 | nActualFlags |= ALTER_COMMENT_FLAGcxx . . $ `ogr/ogr_core.h:696:9`!; |
| 6851 | oTmpFieldDefn.SetCommentcxx . . $ OGRFieldDefn#SetComment(9c546c94e5fcce4e).(poNewFieldDefn->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).()); |
| 6852 | } |
| 6853 | |
| 6854 | /* -------------------------------------------------------------------- */ |
| 6855 | /* Build list of old fields, and the list of new fields. */ |
| 6856 | /* -------------------------------------------------------------------- */ |
| 6857 | stdcxx . . $ std/::vector<OGRFieldDefncxx . . $ OGRFieldDefn# *> apoFields; |
| 6858 | stdcxx . . $ std/::vector<OGRFieldDefncxx . . $ OGRFieldDefn# *> apoFieldsOld; |
| 6859 | for (int iField = 0; iField < m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); iField++) |
| 6860 | { |
| 6861 | OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn; |
| 6862 | if (iField == iFieldToAlter) |
| 6863 | { |
| 6864 | poFieldDefn = &oTmpFieldDefn; |
| 6865 | } |
| 6866 | else |
| 6867 | { |
| 6868 | poFieldDefn = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iField); |
| 6869 | } |
| 6870 | apoFields.push_back(poFieldDefn); |
| 6871 | apoFieldsOld.push_back(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(iField)); |
| 6872 | } |
| 6873 | |
| 6874 | const CPLString osColumnsForCreate(GetColumnsOfCreateTablecxx . . $ OGRGeoPackageTableLayer#GetColumnsOfCreateTable(9590cd99db2695d5).(apoFields)); |
| 6875 | |
| 6876 | /* -------------------------------------------------------------------- */ |
| 6877 | /* Drop any iterator since we change the DB structure */ |
| 6878 | /* -------------------------------------------------------------------- */ |
| 6879 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ResetReadingAllLayerscxx . . $ GDALGeoPackageDataset#ResetReadingAllLayers(49f6e7a06ebc5aa8).(); |
| 6880 | |
| 6881 | const bool bUseRenameColumn = (nActualFlags == ALTER_NAME_FLAGcxx . . $ `ogr/ogr_core.h:652:9`!); |
| 6882 | if (bUseRenameColumn) |
| 6883 | bUseRewriteSchemaMethod = false; |
| 6884 | |
| 6885 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6886 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6887 | |
| 6888 | sqlite3 *hDB = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 6889 | OGRErr eErr = OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 6890 | |
| 6891 | /* -------------------------------------------------------------------- */ |
| 6892 | /* Drop triggers and index that look like to be related to the */ |
| 6893 | /* column if renaming. We re-install some indexes afterwards. */ |
| 6894 | /* -------------------------------------------------------------------- */ |
| 6895 | stdcxx . . $ std/::unique_ptr<SQLResultcxx . . $ SQLResult#> oTriggers; |
| 6896 | // cppcheck-suppress knownConditionTrueFalse |
| 6897 | if (bRenameCol && !bUseRenameColumn) |
| 6898 | { |
| 6899 | char *pszSQL = sqlite3_mprintf( |
| 6900 | "SELECT name, type, sql FROM sqlite_master WHERE " |
| 6901 | "type IN ('trigger','index') " |
| 6902 | "AND lower(tbl_name)=lower('%q') AND sql LIKE '%%%q%%' LIMIT 10000", |
| 6903 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(osOldColName).c_str()); |
| 6904 | oTriggers = SQLQuerycxx . . $ SQLQuery(e5e1a1095e2c7b24).(hDB, pszSQL); |
| 6905 | sqlite3_free(pszSQL); |
| 6906 | |
| 6907 | if (!oTriggers) |
| 6908 | { |
| 6909 | eErr = OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 6910 | } |
| 6911 | |
| 6912 | for (int i = 0; oTriggers && i < oTriggers->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).(); i++) |
| 6913 | { |
| 6914 | pszSQL = |
| 6915 | sqlite3_mprintf("DROP %s \"%w\"", oTriggers->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(1, i), |
| 6916 | oTriggers->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(0, i)); |
| 6917 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6918 | sqlite3_free(pszSQL); |
| 6919 | } |
| 6920 | } |
| 6921 | |
| 6922 | if (bUseRenameColumn) |
| 6923 | { |
| 6924 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6925 | { |
| 6926 | CPLDebug("GPKG", "Running ALTER TABLE RENAME COLUMN"); |
| 6927 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).( |
| 6928 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), |
| 6929 | CPLString() |
| 6930 | .Printf("ALTER TABLE \"%s\" RENAME COLUMN \"%s\" TO \"%s\"", |
| 6931 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 6932 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(osOldColName).c_str(), |
| 6933 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(osNewColName).c_str()) |
| 6934 | .c_str()); |
| 6935 | } |
| 6936 | } |
| 6937 | else if (!bUseRewriteSchemaMethod) |
| 6938 | { |
| 6939 | /* -------------------------------------------------------------------- |
| 6940 | */ |
| 6941 | /* If we are within a transaction, we cannot use the method */ |
| 6942 | /* that consists in altering the database in a raw way. */ |
| 6943 | /* -------------------------------------------------------------------- |
| 6944 | */ |
| 6945 | const CPLString osFieldListForSelect( |
| 6946 | BuildSelectFieldListcxx . . $ OGRGeoPackageTableLayer#BuildSelectFieldList(9590cd99db2695d5).(apoFieldsOld)); |
| 6947 | |
| 6948 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6949 | { |
| 6950 | eErr = RecreateTablecxx . . $ OGRGeoPackageTableLayer#RecreateTable(10f17c25c9837c63).(osColumnsForCreate, osFieldListForSelect); |
| 6951 | } |
| 6952 | } |
| 6953 | else |
| 6954 | { |
| 6955 | /* -------------------------------------------------------------------- |
| 6956 | */ |
| 6957 | /* Rewrite schema in a transaction by altering the database */ |
| 6958 | /* schema in a rather raw way, as described at bottom of */ |
| 6959 | /* https://www.sqlite.org/lang_altertable.html */ |
| 6960 | /* -------------------------------------------------------------------- |
| 6961 | */ |
| 6962 | |
| 6963 | /* -------------------------------------------------------------------- |
| 6964 | */ |
| 6965 | /* Collect schema version number. */ |
| 6966 | /* -------------------------------------------------------------------- |
| 6967 | */ |
| 6968 | int nSchemaVersion = SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(hDB, "PRAGMA schema_version", &eErr); |
| 6969 | |
| 6970 | /* -------------------------------------------------------------------- |
| 6971 | */ |
| 6972 | /* Turn on writable schema. */ |
| 6973 | /* -------------------------------------------------------------------- |
| 6974 | */ |
| 6975 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6976 | { |
| 6977 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->PragmaCheckcxx . . $ OGRSQLiteBaseDataSource#PragmaCheck(f0be30763a490cce).("writable_schema=ON", "", 0); |
| 6978 | } |
| 6979 | |
| 6980 | /* -------------------------------------------------------------------- |
| 6981 | */ |
| 6982 | /* Rewrite CREATE TABLE statement. */ |
| 6983 | /* -------------------------------------------------------------------- |
| 6984 | */ |
| 6985 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 6986 | { |
| 6987 | char *psSQLCreateTable = |
| 6988 | sqlite3_mprintf("CREATE TABLE \"%w\" (%s)", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., |
| 6989 | osColumnsForCreate.c_str()); |
| 6990 | char *pszSQL = sqlite3_mprintf("UPDATE sqlite_master SET sql='%q' " |
| 6991 | "WHERE type='table' AND name='%q'", |
| 6992 | psSQLCreateTable, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 6993 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 6994 | sqlite3_free(psSQLCreateTable); |
| 6995 | sqlite3_free(pszSQL); |
| 6996 | } |
| 6997 | |
| 6998 | /* -------------------------------------------------------------------- |
| 6999 | */ |
| 7000 | /* Increment schema number. */ |
| 7001 | /* -------------------------------------------------------------------- |
| 7002 | */ |
| 7003 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7004 | { |
| 7005 | char *pszSQL = sqlite3_mprintf("PRAGMA schema_version = %d", |
| 7006 | nSchemaVersion + 1); |
| 7007 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 7008 | sqlite3_free(pszSQL); |
| 7009 | } |
| 7010 | |
| 7011 | /* -------------------------------------------------------------------- |
| 7012 | */ |
| 7013 | /* Turn off writable schema. */ |
| 7014 | /* -------------------------------------------------------------------- |
| 7015 | */ |
| 7016 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7017 | { |
| 7018 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->PragmaCheckcxx . . $ OGRSQLiteBaseDataSource#PragmaCheck(f0be30763a490cce).("writable_schema=OFF", "", 0); |
| 7019 | } |
| 7020 | } |
| 7021 | |
| 7022 | /* -------------------------------------------------------------------- */ |
| 7023 | /* Update auxiliary tables */ |
| 7024 | /* -------------------------------------------------------------------- */ |
| 7025 | if (bRenameCol && eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7026 | { |
| 7027 | eErr = RenameFieldInAuxiliaryTablescxx . . $ OGRGeoPackageTableLayer#RenameFieldInAuxiliaryTables(5ae29d726ae57f88).(osOldColName.c_str(), |
| 7028 | poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7029 | } |
| 7030 | |
| 7031 | /* -------------------------------------------------------------------- */ |
| 7032 | /* Update gpkgext_relations if needed. */ |
| 7033 | /* -------------------------------------------------------------------- */ |
| 7034 | if (bRenameCol && eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasGpkgextRelationsTablecxx . . $ GDALGeoPackageDataset#HasGpkgextRelationsTable(50ce9a9e25b4a850).()) |
| 7035 | { |
| 7036 | char *pszSQL = sqlite3_mprintf( |
| 7037 | "UPDATE gpkgext_relations SET base_primary_column = '%q' WHERE " |
| 7038 | "lower(base_table_name) = lower('%q') AND " |
| 7039 | "lower(base_primary_column) = lower('%q')", |
| 7040 | poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., osOldColName.c_str()); |
| 7041 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 7042 | sqlite3_free(pszSQL); |
| 7043 | |
| 7044 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7045 | { |
| 7046 | pszSQL = |
| 7047 | sqlite3_mprintf("UPDATE gpkgext_relations SET " |
| 7048 | "related_primary_column = '%q' WHERE " |
| 7049 | "lower(related_table_name) = lower('%q') AND " |
| 7050 | "lower(related_primary_column) = lower('%q')", |
| 7051 | poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., |
| 7052 | osOldColName.c_str()); |
| 7053 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, pszSQL); |
| 7054 | sqlite3_free(pszSQL); |
| 7055 | } |
| 7056 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ClearCachedRelationshipscxx . . $ GDALGeoPackageDataset#ClearCachedRelationships(49f6e7a06ebc5aa8).(); |
| 7057 | } |
| 7058 | |
| 7059 | /* -------------------------------------------------------------------- */ |
| 7060 | /* Run integrity check only if explicitly required. */ |
| 7061 | /* -------------------------------------------------------------------- */ |
| 7062 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && |
| 7063 | CPLTestBool(CPLGetConfigOption("OGR_GPKG_INTEGRITY_CHECK", "NO"))) |
| 7064 | { |
| 7065 | CPLDebug("GPKG", "Running PRAGMA integrity_check"); |
| 7066 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->PragmaCheckcxx . . $ OGRSQLiteBaseDataSource#PragmaCheck(f0be30763a490cce).("integrity_check", "ok", 1); |
| 7067 | } |
| 7068 | |
| 7069 | /* -------------------------------------------------------------------- */ |
| 7070 | /* Otherwise check foreign key integrity if enforcement of foreign */ |
| 7071 | /* kets constraint is enabled. */ |
| 7072 | /* -------------------------------------------------------------------- */ |
| 7073 | else if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && |
| 7074 | SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "PRAGMA foreign_keys", nullptr)) |
| 7075 | { |
| 7076 | CPLDebug("GPKG", "Running PRAGMA foreign_key_check"); |
| 7077 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->PragmaCheckcxx . . $ OGRSQLiteBaseDataSource#PragmaCheck(f0be30763a490cce).("foreign_key_check", "", 0); |
| 7078 | } |
| 7079 | |
| 7080 | /* -------------------------------------------------------------------- */ |
| 7081 | /* Finish */ |
| 7082 | /* -------------------------------------------------------------------- */ |
| 7083 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7084 | { |
| 7085 | |
| 7086 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 7087 | |
| 7088 | // We need to force database reopening due to schema change |
| 7089 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && bUseRewriteSchemaMethod && |
| 7090 | !m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ReOpenDBcxx . . $ GDALGeoPackageDataset#ReOpenDB(c9857a73d68e59ba).()) |
| 7091 | { |
| 7092 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Cannot reopen database"); |
| 7093 | eErr = OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7094 | } |
| 7095 | hDB = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 7096 | |
| 7097 | /* -------------------------------------------------------------------- |
| 7098 | */ |
| 7099 | /* Recreate indices. */ |
| 7100 | /* -------------------------------------------------------------------- |
| 7101 | */ |
| 7102 | for (int i = 0; |
| 7103 | oTriggers && i < oTriggers->RowCountcxx . . $ SQLResult#RowCount(455f465bc33b4cdf).() && eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; i++) |
| 7104 | { |
| 7105 | if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(oTriggers->GetValue(1, i), "index")) |
| 7106 | { |
| 7107 | CPLString osSQL(oTriggers->GetValuecxx . . $ SQLResult#GetValue(30d1c21db0e2fae7).(2, i)); |
| 7108 | // CREATE INDEX idx_name ON table_name(column_name) |
| 7109 | char **papszTokens = SQLTokenizecxx . . $ SQLTokenize(9945f7050fb66ac).(osSQL); |
| 7110 | if (CSLCount(papszTokens) == 8 && |
| 7111 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(papszTokens[0], "CREATE") && |
| 7112 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(papszTokens[1], "INDEX") && |
| 7113 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(papszTokens[3], "ON") && EQUALcxx . . $ `port/cpl_port.h:532:9`!(papszTokens[5], "(") && |
| 7114 | EQUALcxx . . $ `port/cpl_port.h:532:9`!(papszTokens[7], ")")) |
| 7115 | { |
| 7116 | osSQL = "CREATE INDEX "; |
| 7117 | osSQL += papszTokens[2]; |
| 7118 | osSQL += " ON "; |
| 7119 | osSQL += papszTokens[4]; |
| 7120 | osSQL += "(\""; |
| 7121 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(osNewColName); |
| 7122 | osSQL += "\")"; |
| 7123 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(hDB, osSQL); |
| 7124 | } |
| 7125 | CSLDestroy(papszTokens); |
| 7126 | } |
| 7127 | } |
| 7128 | |
| 7129 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7130 | { |
| 7131 | |
| 7132 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->IsInTransactioncxx . . $ GDALGeoPackageDataset#IsInTransaction(50ce9a9e25b4a850).()) |
| 7133 | { |
| 7134 | m_apoFieldDefnChangescxx . . $ OGRLayer#m_apoFieldDefnChanges..emplace_back( |
| 7135 | stdcxx . . $ std/::make_unique<OGRFieldDefncxx . . $ OGRFieldDefn#>(poFieldDefnToAlter), |
| 7136 | iFieldToAlter, FieldChangeTypecxx . . $ OGRLayer#FieldChangeType#::ALTER_FIELDcxx . . $ OGRLayer#FieldChangeType#ALTER_FIELD., |
| 7137 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetCurrentSavepointcxx . . $ OGRSQLiteBaseDataSource#GetCurrentSavepoint(219584694fe2b248).()); |
| 7138 | } |
| 7139 | |
| 7140 | auto oTemporaryUnsealer(poFieldDefnToAlter->GetTemporaryUnsealercxx . . $ OGRFieldDefn#GetTemporaryUnsealer(17429115ba7a6544).()); |
| 7141 | bool bNeedsEntryInGpkgDataColumns = false; |
| 7142 | |
| 7143 | // field type |
| 7144 | if (nActualFlags & ALTER_TYPE_FLAGcxx . . $ `ogr/ogr_core.h:657:9`!) |
| 7145 | { |
| 7146 | poFieldDefnToAlter->SetSubTypecxx . . $ OGRFieldDefn#SetSubType(89cba9d8fed1b3f9).(OFSTNone); |
| 7147 | poFieldDefnToAlter->SetTypecxx . . $ OGRFieldDefn#SetType(cc683e085121359d).(poNewFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).()); |
| 7148 | poFieldDefnToAlter->SetSubTypecxx . . $ OGRFieldDefn#SetSubType(89cba9d8fed1b3f9).(poNewFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).()); |
| 7149 | } |
| 7150 | if (poFieldDefnToAlter->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).() == OFTString && |
| 7151 | poFieldDefnToAlter->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).() == OFSTJSON) |
| 7152 | { |
| 7153 | bNeedsEntryInGpkgDataColumns = true; |
| 7154 | } |
| 7155 | |
| 7156 | // name |
| 7157 | if (nActualFlags & ALTER_NAME_FLAGcxx . . $ `ogr/ogr_core.h:652:9`!) |
| 7158 | { |
| 7159 | poFieldDefnToAlter->SetNamecxx . . $ OGRFieldDefn#SetName(85c52e162fed56f9).(poNewFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7160 | } |
| 7161 | |
| 7162 | // width/precision |
| 7163 | if (nActualFlags & ALTER_WIDTH_PRECISION_FLAGcxx . . $ `ogr/ogr_core.h:662:9`!) |
| 7164 | { |
| 7165 | poFieldDefnToAlter->SetWidthcxx . . $ OGRFieldDefn#SetWidth(d4f767463ce0a6b3).(poNewFieldDefn->GetWidthcxx . . $ OGRFieldDefn#GetWidth(455f465bc33b4cdf).()); |
| 7166 | poFieldDefnToAlter->SetPrecisioncxx . . $ OGRFieldDefn#SetPrecision(d4f767463ce0a6b3).( |
| 7167 | poNewFieldDefn->GetPrecisioncxx . . $ OGRFieldDefn#GetPrecision(455f465bc33b4cdf).()); |
| 7168 | } |
| 7169 | |
| 7170 | // constraints |
| 7171 | if (nActualFlags & ALTER_NULLABLE_FLAGcxx . . $ `ogr/ogr_core.h:667:9`!) |
| 7172 | poFieldDefnToAlter->SetNullablecxx . . $ OGRFieldDefn#SetNullable(d4f767463ce0a6b3).(poNewFieldDefn->IsNullablecxx . . $ OGRFieldDefn#IsNullable(455f465bc33b4cdf).()); |
| 7173 | if (nActualFlags & ALTER_DEFAULT_FLAGcxx . . $ `ogr/ogr_core.h:672:9`!) |
| 7174 | poFieldDefnToAlter->SetDefaultcxx . . $ OGRFieldDefn#SetDefault(85c52e162fed56f9).(poNewFieldDefn->GetDefaultcxx . . $ OGRFieldDefn#GetDefault(a9f41ea0e82d88cf).()); |
| 7175 | if (nActualFlags & ALTER_UNIQUE_FLAGcxx . . $ `ogr/ogr_core.h:678:9`!) |
| 7176 | poFieldDefnToAlter->SetUniquecxx . . $ OGRFieldDefn#SetUnique(d4f767463ce0a6b3).(poNewFieldDefn->IsUniquecxx . . $ OGRFieldDefn#IsUnique(455f465bc33b4cdf).()); |
| 7177 | |
| 7178 | // domain |
| 7179 | if ((nActualFlags & ALTER_DOMAIN_FLAGcxx . . $ `ogr/ogr_core.h:684:9`!) && |
| 7180 | poFieldDefnToAlter->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).() != |
| 7181 | poNewFieldDefn->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).()) |
| 7182 | { |
| 7183 | poFieldDefnToAlter->SetDomainNamecxx . . $ OGRFieldDefn#SetDomainName(9c546c94e5fcce4e).( |
| 7184 | poNewFieldDefn->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).()); |
| 7185 | } |
| 7186 | if (!poFieldDefnToAlter->GetDomainNamecxx . . $ OGRFieldDefn#GetDomainName(f4fff0029955a25f).().empty()) |
| 7187 | { |
| 7188 | bNeedsEntryInGpkgDataColumns = true; |
| 7189 | } |
| 7190 | |
| 7191 | // alternative name |
| 7192 | if ((nActualFlags & ALTER_ALTERNATIVE_NAME_FLAGcxx . . $ `ogr/ogr_core.h:690:9`!) && |
| 7193 | strcmp(poFieldDefnToAlter->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).(), |
| 7194 | poNewFieldDefn->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).()) != 0) |
| 7195 | { |
| 7196 | poFieldDefnToAlter->SetAlternativeNamecxx . . $ OGRFieldDefn#SetAlternativeName(85c52e162fed56f9).( |
| 7197 | poNewFieldDefn->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).()); |
| 7198 | } |
| 7199 | if (!stdcxx . . $ std/::string(poFieldDefnToAlter->GetAlternativeNameRefcxx . . $ OGRFieldDefn#GetAlternativeNameRef(a9f41ea0e82d88cf).()) |
| 7200 | .empty()) |
| 7201 | { |
| 7202 | bNeedsEntryInGpkgDataColumns = true; |
| 7203 | } |
| 7204 | |
| 7205 | // comment |
| 7206 | if ((nActualFlags & ALTER_COMMENT_FLAGcxx . . $ `ogr/ogr_core.h:696:9`!) && |
| 7207 | poFieldDefnToAlter->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).() != |
| 7208 | poNewFieldDefn->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).()) |
| 7209 | { |
| 7210 | poFieldDefnToAlter->SetCommentcxx . . $ OGRFieldDefn#SetComment(9c546c94e5fcce4e).(poNewFieldDefn->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).()); |
| 7211 | } |
| 7212 | if (!poFieldDefnToAlter->GetCommentcxx . . $ OGRFieldDefn#GetComment(f4fff0029955a25f).().empty()) |
| 7213 | { |
| 7214 | bNeedsEntryInGpkgDataColumns = true; |
| 7215 | } |
| 7216 | |
| 7217 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->HasDataColumnsTablecxx . . $ GDALGeoPackageDataset#HasDataColumnsTable(50ce9a9e25b4a850).()) |
| 7218 | { |
| 7219 | char *pszSQL = sqlite3_mprintf( |
| 7220 | "DELETE FROM gpkg_data_columns WHERE " |
| 7221 | "lower(table_name) = lower('%q') AND " |
| 7222 | "lower(column_name) = lower('%q')", |
| 7223 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., poFieldDefnToAlter->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7224 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 7225 | sqlite3_free(pszSQL); |
| 7226 | } |
| 7227 | |
| 7228 | if (bNeedsEntryInGpkgDataColumns) |
| 7229 | { |
| 7230 | if (!DoSpecialProcessingForColumnCreationcxx . . $ OGRGeoPackageTableLayer#DoSpecialProcessingForColumnCreation(6ac7e7c63d694732).(poFieldDefnToAlter)) |
| 7231 | eErr = OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7232 | } |
| 7233 | |
| 7234 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 7235 | } |
| 7236 | } |
| 7237 | else |
| 7238 | { |
| 7239 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7240 | } |
| 7241 | |
| 7242 | return eErr; |
| 7243 | } |
| 7244 | |
| 7245 | /************************************************************************/ |
| 7246 | /* AlterGeomFieldDefn() */ |
| 7247 | /************************************************************************/ |
| 7248 | |
| 7249 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::AlterGeomFieldDefncxx . . $ OGRGeoPackageTableLayer#AlterGeomFieldDefn(d8b8c4969ca6e664).( |
| 7250 | int iGeomFieldToAlter, const OGRGeomFieldDefncxx . . $ OGRGeomFieldDefn# *poNewGeomFieldDefn, |
| 7251 | int nFlagsIn) |
| 7252 | { |
| 7253 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 7254 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 7255 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("AlterGeomFieldDefn")) |
| 7256 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7257 | |
| 7258 | if (iGeomFieldToAlter < 0 || |
| 7259 | iGeomFieldToAlter >= m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).()) |
| 7260 | { |
| 7261 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Invalid field index"); |
| 7262 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7263 | } |
| 7264 | |
| 7265 | /* -------------------------------------------------------------------- */ |
| 7266 | /* Deferred actions, reset state. */ |
| 7267 | /* -------------------------------------------------------------------- */ |
| 7268 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 7269 | RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).(); |
| 7270 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 7271 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 7272 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 7273 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7274 | RevertWorkaroundUpdate1TriggerIssuecxx . . $ OGRGeoPackageTableLayer#RevertWorkaroundUpdate1TriggerIssue(49f6e7a06ebc5aa8).(); |
| 7275 | |
| 7276 | /* -------------------------------------------------------------------- */ |
| 7277 | /* Drop any iterator since we change the DB structure */ |
| 7278 | /* -------------------------------------------------------------------- */ |
| 7279 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ResetReadingAllLayerscxx . . $ GDALGeoPackageDataset#ResetReadingAllLayers(49f6e7a06ebc5aa8).(); |
| 7280 | |
| 7281 | auto poGeomFieldDefn = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(iGeomFieldToAlter); |
| 7282 | auto oTemporaryUnsealer(poGeomFieldDefn->GetTemporaryUnsealercxx . . $ OGRGeomFieldDefn#GetTemporaryUnsealer(5cb304fa2ae19270).()); |
| 7283 | |
| 7284 | if (nFlagsIn & ALTER_GEOM_FIELD_DEFN_TYPE_FLAGcxx . . $ `ogr/ogr_core.h:716:9`!) |
| 7285 | { |
| 7286 | // could be potentially done. Requires rewriting the CREATE TABLE |
| 7287 | // statement |
| 7288 | if (poGeomFieldDefn->GetTypecxx . . $ OGRGeomFieldDefn#GetType(5a40c54c5ff210ce).() != poNewGeomFieldDefn->GetTypecxx . . $ OGRGeomFieldDefn#GetType(5a40c54c5ff210ce).()) |
| 7289 | { |
| 7290 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, |
| 7291 | "Altering the geometry field type is not currently " |
| 7292 | "supported for " |
| 7293 | "GeoPackage"); |
| 7294 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7295 | } |
| 7296 | } |
| 7297 | |
| 7298 | if (nFlagsIn & ALTER_GEOM_FIELD_DEFN_NULLABLE_FLAGcxx . . $ `ogr/ogr_core.h:722:9`!) |
| 7299 | { |
| 7300 | // could be potentially done. Requires rewriting the CREATE TABLE |
| 7301 | // statement |
| 7302 | if (poGeomFieldDefn->IsNullablecxx . . $ OGRGeomFieldDefn#IsNullable(455f465bc33b4cdf).() != poNewGeomFieldDefn->IsNullablecxx . . $ OGRGeomFieldDefn#IsNullable(455f465bc33b4cdf).()) |
| 7303 | { |
| 7304 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, |
| 7305 | "Altering the nullable state of the geometry field " |
| 7306 | "is not currently supported for GeoPackage"); |
| 7307 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7308 | } |
| 7309 | } |
| 7310 | |
| 7311 | if ((nFlagsIn & ALTER_GEOM_FIELD_DEFN_NAME_FLAGcxx . . $ `ogr/ogr_core.h:710:9`!) != 0 && |
| 7312 | strcmp(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 7313 | poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()) != 0) |
| 7314 | { |
| 7315 | const bool bHasSpatialIndex = HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).(); |
| 7316 | |
| 7317 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7318 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7319 | |
| 7320 | // Rename geometry field |
| 7321 | auto eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).( |
| 7322 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), |
| 7323 | CPLString() |
| 7324 | .Printf("ALTER TABLE \"%s\" RENAME COLUMN \"%s\" TO \"%s\"", |
| 7325 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 7326 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 7327 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str()) |
| 7328 | .c_str()); |
| 7329 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7330 | { |
| 7331 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7332 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7333 | } |
| 7334 | |
| 7335 | // Update gpkg_geometry_columns |
| 7336 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).( |
| 7337 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), |
| 7338 | CPLString() |
| 7339 | .Printf( |
| 7340 | "UPDATE gpkg_geometry_columns SET column_name = '%s' " |
| 7341 | "WHERE lower(table_name) = lower('%s') " |
| 7342 | "AND lower(column_name) = lower('%s')", |
| 7343 | SQLEscapeLiteralcxx . . $ SQLEscapeLiteral(a9d72c988d85d6d8).(poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 7344 | SQLEscapeLiteralcxx . . $ SQLEscapeLiteral(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 7345 | SQLEscapeLiteralcxx . . $ SQLEscapeLiteral(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str()) |
| 7346 | .c_str()); |
| 7347 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7348 | { |
| 7349 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7350 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7351 | } |
| 7352 | |
| 7353 | // Update auxiliary tables |
| 7354 | eErr = RenameFieldInAuxiliaryTablescxx . . $ OGRGeoPackageTableLayer#RenameFieldInAuxiliaryTables(5ae29d726ae57f88).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), |
| 7355 | poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7356 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7357 | { |
| 7358 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7359 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7360 | } |
| 7361 | |
| 7362 | stdcxx . . $ std/::string osNewRTreeName; |
| 7363 | if (bHasSpatialIndex) |
| 7364 | { |
| 7365 | osNewRTreeName = "rtree_"; |
| 7366 | osNewRTreeName += m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 7367 | osNewRTreeName += "_"; |
| 7368 | osNewRTreeName += poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 7369 | |
| 7370 | // Rename spatial index tables (not strictly needed, but for |
| 7371 | // consistency) |
| 7372 | eErr = |
| 7373 | SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), |
| 7374 | CPLString().Printf( |
| 7375 | "ALTER TABLE \"%s\" RENAME TO \"%s\"", |
| 7376 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()).c_str(), |
| 7377 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(osNewRTreeName.c_str()).c_str())); |
| 7378 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7379 | { |
| 7380 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7381 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7382 | } |
| 7383 | |
| 7384 | // Finally rename triggers (not strictly needed, but for |
| 7385 | // consistency) |
| 7386 | stdcxx . . $ std/::string osTriggerSQL; |
| 7387 | osTriggerSQL = ReturnSQLDropSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLDropSpatialIndexTriggers(cdfd1e859161399b).(); |
| 7388 | osTriggerSQL += ";"; |
| 7389 | osTriggerSQL += ReturnSQLCreateSpatialIndexTriggerscxx . . $ OGRGeoPackageTableLayer#ReturnSQLCreateSpatialIndexTriggers(91f1db05c53bff50).( |
| 7390 | nullptr, poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7391 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osTriggerSQL.c_str()); |
| 7392 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7393 | { |
| 7394 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7395 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 7400 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7401 | { |
| 7402 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7403 | } |
| 7404 | |
| 7405 | poGeomFieldDefn->SetNamecxx . . $ OGRGeomFieldDefn#SetName(85c52e162fed56f9).(poNewGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7406 | |
| 7407 | if (bHasSpatialIndex) |
| 7408 | { |
| 7409 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = osNewRTreeName; |
| 7410 | } |
| 7411 | } |
| 7412 | |
| 7413 | if ((nFlagsIn & ALTER_GEOM_FIELD_DEFN_SRS_FLAGcxx . . $ `ogr/ogr_core.h:728:9`!) != 0 || |
| 7414 | (nFlagsIn & ALTER_GEOM_FIELD_DEFN_SRS_COORD_EPOCH_FLAGcxx . . $ `ogr/ogr_core.h:734:9`!) != 0) |
| 7415 | { |
| 7416 | const auto poOldSRS = poGeomFieldDefn->GetSpatialRefcxx . . $ OGRGeomFieldDefn#GetSpatialRef(8a5496c2eeefaeaf).(); |
| 7417 | const auto poNewSRSRef = poNewGeomFieldDefn->GetSpatialRefcxx . . $ OGRGeomFieldDefn#GetSpatialRef(8a5496c2eeefaeaf).(); |
| 7418 | |
| 7419 | OGRSpatialReferenceRefCountedPtrcxx . . $ OGRSpatialReferenceRefCountedPtr# poNewSRScxx . . $ OGRRefCountedPtr#OGRRefCountedPtr(49f6e7a06ebc5aa8).; |
| 7420 | if ((nFlagsIn & ALTER_GEOM_FIELD_DEFN_SRS_FLAGcxx . . $ `ogr/ogr_core.h:728:9`!) != 0) |
| 7421 | { |
| 7422 | if (poNewSRSRef != nullptr) |
| 7423 | { |
| 7424 | poNewSRS =cxx . . $ OGRRefCountedPtr#`operator=`(75ecb2b9da62a289). |
| 7425 | OGRSpatialReferenceRefCountedPtrcxx . . $ OGRSpatialReferenceRefCountedPtr#::makeClonecxx . . $ OGRRefCountedPtr#makeClone(52807447ccd2a8c8).(poNewSRSRef); |
| 7426 | if ((nFlagsIn & ALTER_GEOM_FIELD_DEFN_SRS_COORD_EPOCH_FLAGcxx . . $ `ogr/ogr_core.h:734:9`!) == |
| 7427 | 0) |
| 7428 | { |
| 7429 | if (poOldSRS) |
| 7430 | poNewSRS->cxx . . $ OGRRefCountedPtrBase#`operator->`(5a2a78a048fb49a8).SetCoordinateEpochcxx . . $ OGRSpatialReference#SetCoordinateEpoch(ba8836b59fb42830).( |
| 7431 | poOldSRS->GetCoordinateEpochcxx . . $ OGRSpatialReference#GetCoordinateEpoch(21b6c25e127938e2).()); |
| 7432 | } |
| 7433 | } |
| 7434 | } |
| 7435 | else if ((nFlagsIn & ALTER_GEOM_FIELD_DEFN_SRS_COORD_EPOCH_FLAGcxx . . $ `ogr/ogr_core.h:734:9`!) != 0) |
| 7436 | { |
| 7437 | if (poOldSRS != nullptr) |
| 7438 | { |
| 7439 | poNewSRS =cxx . . $ OGRRefCountedPtr#`operator=`(75ecb2b9da62a289). |
| 7440 | OGRSpatialReferenceRefCountedPtrcxx . . $ OGRSpatialReferenceRefCountedPtr#::makeClonecxx . . $ OGRRefCountedPtr#makeClone(52807447ccd2a8c8).(poOldSRS); |
| 7441 | if (poNewSRSRef) |
| 7442 | poNewSRS->cxx . . $ OGRRefCountedPtrBase#`operator->`(5a2a78a048fb49a8).SetCoordinateEpochcxx . . $ OGRSpatialReference#SetCoordinateEpoch(ba8836b59fb42830).( |
| 7443 | poNewSRSRef->GetCoordinateEpochcxx . . $ OGRSpatialReference#GetCoordinateEpoch(21b6c25e127938e2).()); |
| 7444 | } |
| 7445 | } |
| 7446 | |
| 7447 | const char *const apszOptions[] = { |
| 7448 | "IGNORE_DATA_AXIS_TO_SRS_AXIS_MAPPING=YES", nullptr}; |
| 7449 | if ((poOldSRS == nullptr && poNewSRS !=cxx . . $ `operator!=`(b69b34e3f1dbec43). nullptr) || |
| 7450 | (poOldSRS != nullptr && poNewSRS ==cxx . . $ `operator==`(b69b34e3f1dbec43). nullptr) || |
| 7451 | (poOldSRS != nullptr && poNewSRS !=cxx . . $ `operator!=`(b69b34e3f1dbec43). nullptr && |
| 7452 | !poOldSRS->IsSamecxx . . $ OGRSpatialReference#IsSame(237d09acedc929c6).(poNewSRS.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).(), apszOptions))) |
| 7453 | { |
| 7454 | // Temporary remove foreign key checks |
| 7455 | const GPKGTemporaryForeignKeyCheckDisablercxx . . $ GPKGTemporaryForeignKeyCheckDisabler# |
| 7456 | oGPKGTemporaryForeignKeyCheckDisablercxx . . $ GPKGTemporaryForeignKeyCheckDisabler#GPKGTemporaryForeignKeyCheckDisabler(708af067f9bb9c4a).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.); |
| 7457 | |
| 7458 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7459 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7460 | |
| 7461 | const int nNewSRID = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetSrsIdcxx . . $ GDALGeoPackageDataset#GetSrsId(8a145e066b724d94).(poNewSRS.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 7462 | |
| 7463 | // Replace the old SRID by the new ones in geometry blobs |
| 7464 | int32_t nNewSRID_LSB = nNewSRID; |
| 7465 | CPL_LSBPTR32cxx . . $ `port/cpl_port.h:761:9`!(&nNewSRID_LSB); |
| 7466 | GBytecxx . . $ GByte# abySRID_LSB[5] = {0, 0, 0, 0}; |
| 7467 | memcpy(abySRID_LSB, &nNewSRID_LSB, 4); |
| 7468 | char *pszSRID_LSB_HEX = CPLBinaryToHex(4, abySRID_LSB); |
| 7469 | |
| 7470 | int32_t nNewSRID_MSB = nNewSRID; |
| 7471 | CPL_MSBPTR32cxx . . $ `port/cpl_port.h:765:9`!(&nNewSRID_MSB); |
| 7472 | GBytecxx . . $ GByte# abySRID_MSB[5] = {0, 0, 0, 0}; |
| 7473 | memcpy(abySRID_MSB, &nNewSRID_MSB, 4); |
| 7474 | char *pszSRID_MSB_HEX = CPLBinaryToHex(4, abySRID_MSB); |
| 7475 | |
| 7476 | // Black magic below... |
| 7477 | // the substr(hex(...) IN ('0','2',...'E') checks if bit 0 of the |
| 7478 | // 4th byte is 0 and use that to decide how to replace the old SRID |
| 7479 | // by the new one. |
| 7480 | CPLString osSQL; |
| 7481 | osSQL.Printf( |
| 7482 | "UPDATE \"%s\" SET \"%s\" = " |
| 7483 | "CAST(substr(\"%s\", 1, 4) || " |
| 7484 | "(CASE WHEN substr(hex(substr(\"%s\", 4, 1)),2) IN " |
| 7485 | "('0','2','4','6','8','A','C','E') " |
| 7486 | "THEN x'%s' ELSE x'%s' END) || substr(\"%s\", 9) AS BLOB) " |
| 7487 | "WHERE \"%s\" IS NOT NULL", |
| 7488 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.).c_str(), |
| 7489 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 7490 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 7491 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 7492 | pszSRID_MSB_HEX, pszSRID_LSB_HEX, |
| 7493 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str(), |
| 7494 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()).c_str()); |
| 7495 | OGRErr eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL.c_str()); |
| 7496 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszSRID_MSB_HEX); |
| 7497 | CPLFreecxx . . $ `port/cpl_conv.h:97:9`!(pszSRID_LSB_HEX); |
| 7498 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7499 | { |
| 7500 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7501 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7502 | } |
| 7503 | |
| 7504 | char *pszSQL = sqlite3_mprintf( |
| 7505 | "UPDATE gpkg_contents SET srs_id = %d WHERE table_name = '%q'", |
| 7506 | nNewSRID, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 7507 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 7508 | sqlite3_free(pszSQL); |
| 7509 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7510 | { |
| 7511 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7512 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7513 | } |
| 7514 | |
| 7515 | pszSQL = sqlite3_mprintf( |
| 7516 | "UPDATE gpkg_geometry_columns SET srs_id = %d WHERE " |
| 7517 | "table_name = '%q' AND column_name = '%q'", |
| 7518 | nNewSRID, m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., poGeomFieldDefn->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 7519 | eErr = SQLCommandcxx . . $ SQLCommand(6b988785095e19f6).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL); |
| 7520 | sqlite3_free(pszSQL); |
| 7521 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7522 | { |
| 7523 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7524 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7525 | } |
| 7526 | |
| 7527 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7528 | { |
| 7529 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7530 | } |
| 7531 | |
| 7532 | m_iSrscxx . . $ OGRGeoPackageTableLayer#m_iSrs. = nNewSRID; |
| 7533 | poGeomFieldDefn->SetSpatialRefcxx . . $ OGRGeomFieldDefn#SetSpatialRef(9ff39b79387a6086).(poNewSRS.getcxx . . $ OGRRefCountedPtrBase#get(5a2a78a048fb49a8).()); |
| 7534 | } |
| 7535 | } |
| 7536 | |
| 7537 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 7538 | } |
| 7539 | |
| 7540 | /************************************************************************/ |
| 7541 | /* ReorderFields() */ |
| 7542 | /************************************************************************/ |
| 7543 | |
| 7544 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::ReorderFieldscxx . . $ OGRGeoPackageTableLayer#ReorderFields(a5f7824ee4986326).(int *panMap) |
| 7545 | { |
| 7546 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 7547 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 7548 | if (!CheckUpdatableTablecxx . . $ OGRGeoPackageTableLayer#CheckUpdatableTable(c5f7da30cbc0f4e9).("ReorderFields")) |
| 7549 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7550 | |
| 7551 | if (m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).() == 0) |
| 7552 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 7553 | |
| 7554 | OGRErr eErr = OGRCheckPermutationcxx . . $ OGRCheckPermutation(8a3c03cab1458944).(panMap, m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).()); |
| 7555 | if (eErr != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7556 | return eErr; |
| 7557 | |
| 7558 | /* -------------------------------------------------------------------- */ |
| 7559 | /* Deferred actions, reset state. */ |
| 7560 | /* -------------------------------------------------------------------- */ |
| 7561 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 7562 | RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).(); |
| 7563 | if (m_bThreadRTreeStartedcxx . . $ OGRGeoPackageTableLayer#m_bThreadRTreeStarted.) |
| 7564 | CancelAsyncRTreecxx . . $ OGRGeoPackageTableLayer#CancelAsyncRTree(49f6e7a06ebc5aa8).(); |
| 7565 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 7566 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7567 | |
| 7568 | /* -------------------------------------------------------------------- */ |
| 7569 | /* Drop any iterator since we change the DB structure */ |
| 7570 | /* -------------------------------------------------------------------- */ |
| 7571 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->ResetReadingAllLayerscxx . . $ GDALGeoPackageDataset#ResetReadingAllLayers(49f6e7a06ebc5aa8).(); |
| 7572 | |
| 7573 | /* -------------------------------------------------------------------- */ |
| 7574 | /* Build list of old fields, and the list of new fields. */ |
| 7575 | /* -------------------------------------------------------------------- */ |
| 7576 | stdcxx . . $ std/::vector<OGRFieldDefncxx . . $ OGRFieldDefn# *> apoFields; |
| 7577 | for (int iField = 0; iField < m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); iField++) |
| 7578 | { |
| 7579 | OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = |
| 7580 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(panMap[iField]); |
| 7581 | apoFields.push_back(poFieldDefn); |
| 7582 | } |
| 7583 | |
| 7584 | const CPLString osFieldListForSelect(BuildSelectFieldListcxx . . $ OGRGeoPackageTableLayer#BuildSelectFieldList(9590cd99db2695d5).(apoFields)); |
| 7585 | const CPLString osColumnsForCreate(GetColumnsOfCreateTablecxx . . $ OGRGeoPackageTableLayer#GetColumnsOfCreateTable(9590cd99db2695d5).(apoFields)); |
| 7586 | |
| 7587 | /* -------------------------------------------------------------------- */ |
| 7588 | /* Recreate table in a transaction */ |
| 7589 | /* -------------------------------------------------------------------- */ |
| 7590 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7591 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7592 | |
| 7593 | eErr = RecreateTablecxx . . $ OGRGeoPackageTableLayer#RecreateTable(10f17c25c9837c63).(osColumnsForCreate, osFieldListForSelect); |
| 7594 | |
| 7595 | /* -------------------------------------------------------------------- */ |
| 7596 | /* Finish */ |
| 7597 | /* -------------------------------------------------------------------- */ |
| 7598 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7599 | { |
| 7600 | eErr = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 7601 | |
| 7602 | if (eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7603 | { |
| 7604 | eErr = whileUnsealingcxx . . $ whileUnsealing(de07598ec200be45).(m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.)->cxx . . $ OGRFeatureDefn#TemporaryUnsealer#`operator->`(407fccde18759965).ReorderFieldDefnscxx . . $ OGRFeatureDefn#ReorderFieldDefns(3b3ea59173561418).(panMap); |
| 7605 | } |
| 7606 | |
| 7607 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 7608 | } |
| 7609 | else |
| 7610 | { |
| 7611 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 7612 | } |
| 7613 | |
| 7614 | return eErr; |
| 7615 | } |
| 7616 | |
| 7617 | /************************************************************************/ |
| 7618 | /* OGR_GPKG_GeometryTypeAggregate() */ |
| 7619 | /************************************************************************/ |
| 7620 | |
| 7621 | namespacecxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/ |
| 7622 | { |
| 7623 | struct GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext# |
| 7624 | { |
| 7625 | sqlite3 *m_hDBcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_hDB. = nullptr; |
| 7626 | int m_nFlagscxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_nFlags. = 0; |
| 7627 | bool m_bIsGeometryTypeAggregateInterruptedcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_bIsGeometryTypeAggregateInterrupted. = false; |
| 7628 | stdcxx . . $ std/::mapcxx . . $ std/map#<OGRwkbGeometryType, int64_t> m_oMapCountcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oMapCount.{cxx . . $ std/map#map(49f6e7a06ebc5aa8).}; |
| 7629 | stdcxx . . $ std/::setcxx . . $ std/set#<OGRwkbGeometryType> m_oSetNotNullcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oSetNotNull.{cxx . . $ std/set#set(49f6e7a06ebc5aa8).}; |
| 7630 | |
| 7631 | explicit GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#GeometryTypeAggregateContext(48938a91fc3b8242).(sqlite3 *hDB, int nFlags) |
| 7632 | : m_hDBcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_hDB.(hDB), m_nFlagscxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_nFlags.(nFlags) |
| 7633 | { |
| 7634 | } |
| 7635 | |
| 7636 | GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#GeometryTypeAggregateContext(8a5abf6c7a18c637).(const GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext# &) = delete; |
| 7637 | GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext# & |
| 7638 | operatorcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#`operator=`(c6872ac74eb5e4e4).=(const GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext# &) = delete; |
| 7639 | |
| 7640 | void SetGeometryTypeAggregateInterruptedcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#SetGeometryTypeAggregateInterrupted(b45ddcbc8423892c).(bool b) |
| 7641 | { |
| 7642 | m_bIsGeometryTypeAggregateInterruptedcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_bIsGeometryTypeAggregateInterrupted. = b; |
| 7643 | if (b) |
| 7644 | sqlite3_interrupt(m_hDBcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_hDB.); |
| 7645 | } |
| 7646 | }; |
| 7647 | |
| 7648 | } // namespace |
| 7649 | |
| 7650 | static void OGR_GPKG_GeometryTypeAggregate_Stepcxx . . $ OGR_GPKG_GeometryTypeAggregate_Step(77c4cd3acce4959d).(sqlite3_context *pContext, |
| 7651 | int /*argc*/, |
| 7652 | sqlite3_value **argv) |
| 7653 | { |
| 7654 | const GBytecxx . . $ GByte# *pabyBLOB = |
| 7655 | reinterpret_cast<const GBytecxx . . $ GByte# *>(sqlite3_value_blob(argv[0])); |
| 7656 | |
| 7657 | auto poContext = static_cast<GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext# *>( |
| 7658 | sqlite3_user_data(pContext)); |
| 7659 | |
| 7660 | OGRwkbGeometryType eGeometryType = wkbNone; |
| 7661 | OGRErr err = OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 7662 | if (pabyBLOB != nullptr) |
| 7663 | { |
| 7664 | GPkgHeadercxx . . $ GPkgHeader# sHeader; |
| 7665 | const int nBLOBLen = sqlite3_value_bytes(argv[0]); |
| 7666 | if (GPkgHeaderFromWKBcxx . . $ GPkgHeaderFromWKB(5dfb47f6cfa574ea).(pabyBLOB, nBLOBLen, &sHeader) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && |
| 7667 | static_cast<size_t>(nBLOBLen) >= sHeader.nHeaderLencxx . . $ $anonymous_type_2b740b2c8f9610bf_0#nHeaderLen. + 5) |
| 7668 | { |
| 7669 | err = OGRReadWKBGeometryTypecxx . . $ OGRReadWKBGeometryType(4582966460571395).(pabyBLOB + sHeader.nHeaderLencxx . . $ $anonymous_type_2b740b2c8f9610bf_0#nHeaderLen., |
| 7670 | wkbVariantIso, &eGeometryType); |
| 7671 | if (eGeometryType == wkbGeometryCollection25D && |
| 7672 | (poContext->m_nFlagscxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_nFlags. & OGR_GGT_GEOMCOLLECTIONZ_TINZcxx . . $ `ogr/ogr_api.h:642:9`!) != 0) |
| 7673 | { |
| 7674 | auto poGeom = stdcxx . . $ std/::unique_ptr<OGRGeometrycxx . . $ OGRGeometry#>( |
| 7675 | GPkgGeometryToOGRcxx . . $ GPkgGeometryToOGR(2f7e6b0f464fc578).(pabyBLOB, nBLOBLen, nullptr)); |
| 7676 | if (poGeom) |
| 7677 | { |
| 7678 | const auto poGC = poGeom->toGeometryCollectioncxx . . $ OGRGeometry#toGeometryCollection(2dc35bba37476a41).(); |
| 7679 | if (poGC->getNumGeometriescxx . . $ OGRGeometryCollection#getNumGeometries(455f465bc33b4cdf).() > 0) |
| 7680 | { |
| 7681 | auto eSubGeomType = |
| 7682 | poGC->getGeometryRefcxx . . $ OGRGeometryCollection#getGeometryRef(ea443ccec24c6360).(0)->getGeometryTypecxx . . $ OGRGeometry#getGeometryType(5a40c54c5ff210ce).(); |
| 7683 | if (eSubGeomType == wkbTINZ) |
| 7684 | eGeometryType = wkbTINZ; |
| 7685 | } |
| 7686 | } |
| 7687 | } |
| 7688 | } |
| 7689 | } |
| 7690 | else |
| 7691 | { |
| 7692 | // NULL geometry |
| 7693 | err = OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 7694 | } |
| 7695 | if (err == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7696 | { |
| 7697 | ++poContext->m_oMapCountcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oMapCount.[cxx . . $ std/map#`operator[]`(bbd415b616967878).eGeometryType]; |
| 7698 | if (eGeometryType != wkbNone && |
| 7699 | (poContext->m_nFlagscxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_nFlags. & OGR_GGT_STOP_IF_MIXEDcxx . . $ `ogr/ogr_api.h:639:9`!) != 0) |
| 7700 | { |
| 7701 | poContext->m_oSetNotNullcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oSetNotNull..insertcxx . . $ std/set#insert(411a10a755068dfe).(eGeometryType); |
| 7702 | if (poContext->m_oSetNotNullcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oSetNotNull..sizecxx . . $ std/set#size(fa801f5ac5d26b4e).() == 2) |
| 7703 | { |
| 7704 | poContext->SetGeometryTypeAggregateInterruptedcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#SetGeometryTypeAggregateInterrupted(b45ddcbc8423892c).(true); |
| 7705 | } |
| 7706 | } |
| 7707 | } |
| 7708 | } |
| 7709 | |
| 7710 | static void OGR_GPKG_GeometryTypeAggregate_Finalizecxx . . $ OGR_GPKG_GeometryTypeAggregate_Finalize(e5276f5e0ac5ec48).(sqlite3_context *) |
| 7711 | { |
| 7712 | } |
| 7713 | |
| 7714 | /************************************************************************/ |
| 7715 | /* GetGeometryTypes() */ |
| 7716 | /************************************************************************/ |
| 7717 | |
| 7718 | OGRGeometryTypeCounter *OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetGeometryTypescxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).( |
| 7719 | int iGeomField, int nFlagsGGT, int &nEntryCountOut, |
| 7720 | GDALProgressFunc pfnProgress, void *pProgressData) |
| 7721 | { |
| 7722 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *poDefn = GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 7723 | |
| 7724 | /* -------------------------------------------------------------------- */ |
| 7725 | /* Deferred actions, reset state. */ |
| 7726 | /* -------------------------------------------------------------------- */ |
| 7727 | RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).(); |
| 7728 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 7729 | { |
| 7730 | nEntryCountOut = 0; |
| 7731 | return nullptr; |
| 7732 | } |
| 7733 | |
| 7734 | const int nGeomFieldCount = poDefn->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).(); |
| 7735 | if (iGeomField < 0 || iGeomField >= nGeomFieldCount) |
| 7736 | { |
| 7737 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Invalid value for iGeomField"); |
| 7738 | nEntryCountOut = 0; |
| 7739 | return nullptr; |
| 7740 | } |
| 7741 | |
| 7742 | #ifdef SQLITE_HAS_PROGRESS_HANDLERcxx . . $ `<built-in>:489:9`! |
| 7743 | struct CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# |
| 7744 | { |
| 7745 | sqlite3 *m_hDBcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_hDB. = nullptr; |
| 7746 | GDALProgressFunc m_pfnProgresscxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pfnProgress. = nullptr; |
| 7747 | void *m_pProgressDatacxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pProgressData. = nullptr; |
| 7748 | |
| 7749 | CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#CancelCallback(c64908482a37b681).(sqlite3 *hDB, GDALProgressFunc pfnProgressIn, |
| 7750 | void *pProgressDataIn) |
| 7751 | : m_hDBcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_hDB.(hDB), |
| 7752 | m_pfnProgresscxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pfnProgress.(pfnProgressIn != GDALDummyProgress ? pfnProgressIn |
| 7753 | : nullptr), |
| 7754 | m_pProgressDatacxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pProgressData.(pProgressDataIn) |
| 7755 | { |
| 7756 | if (m_pfnProgresscxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pfnProgress.) |
| 7757 | { |
| 7758 | // If changing that value, update |
| 7759 | // ogr_gpkg.py::test_ogr_gpkg_get_geometry_types |
| 7760 | constexpr int COUNT_VM_INSTRUCTIONS = 1000; |
| 7761 | sqlite3_progress_handler(m_hDBcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_hDB., COUNT_VM_INSTRUCTIONS, |
| 7762 | ProgressHandlercxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#ProgressHandler(dedf1e9b1c614a07)., this); |
| 7763 | } |
| 7764 | } |
| 7765 | |
| 7766 | ~cxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#`~CancelCallback`(ced63f7c635d850d).CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#() |
| 7767 | { |
| 7768 | if (m_pfnProgresscxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pfnProgress.) |
| 7769 | { |
| 7770 | sqlite3_progress_handler(m_hDBcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_hDB., 0, nullptr, nullptr); |
| 7771 | } |
| 7772 | } |
| 7773 | |
| 7774 | CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#CancelCallback(f6e659f4166d4cbe).(const CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# &) = delete; |
| 7775 | CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# &operatorcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#`operator=`(39f68bb6c61c571).=(const CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# &) = delete; |
| 7776 | |
| 7777 | static int ProgressHandlercxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#ProgressHandler(dedf1e9b1c614a07).(void *pData) |
| 7778 | { |
| 7779 | CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# *psCancelCallback = |
| 7780 | static_cast<CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# *>(pData); |
| 7781 | return psCancelCallback->m_pfnProgresscxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pfnProgress. != nullptr && |
| 7782 | psCancelCallback->m_pfnProgresscxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pfnProgress.( |
| 7783 | 0.0, "", psCancelCallback->m_pProgressDatacxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#m_pProgressData.) |
| 7784 | ? 0 |
| 7785 | : 1; |
| 7786 | } |
| 7787 | }; |
| 7788 | |
| 7789 | CancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback# oCancelCallbackcxx . . $ OGRGeoPackageTableLayer#GetGeometryTypes(2bc72d86a0ce2bcf).CancelCallback#CancelCallback(c64908482a37b681).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pfnProgress, pProgressData); |
| 7790 | #else |
| 7791 | CPL_IGNORE_RET_VAL(pfnProgress); |
| 7792 | CPL_IGNORE_RET_VAL(pProgressData); |
| 7793 | #endif |
| 7794 | |
| 7795 | // For internal use only |
| 7796 | |
| 7797 | GeometryTypeAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext# sContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#GeometryTypeAggregateContext(48938a91fc3b8242).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., nFlagsGGT); |
| 7798 | |
| 7799 | CPLString osFuncName; |
| 7800 | osFuncName.Printf("OGR_GPKG_GeometryTypeAggregate_INTERNAL_%p", &sContext); |
| 7801 | |
| 7802 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., osFuncName.c_str(), 1, SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`!, |
| 7803 | &sContext, nullptr, |
| 7804 | OGR_GPKG_GeometryTypeAggregate_Stepcxx . . $ OGR_GPKG_GeometryTypeAggregate_Step(77c4cd3acce4959d)., |
| 7805 | OGR_GPKG_GeometryTypeAggregate_Finalizecxx . . $ OGR_GPKG_GeometryTypeAggregate_Finalize(e5276f5e0ac5ec48).); |
| 7806 | |
| 7807 | // Using this aggregate function is slightly faster than using |
| 7808 | // sqlite3_step() to loop over each geometry blob (650 ms vs 750ms on a 1.6 |
| 7809 | // GB db with 3.3 million features) |
| 7810 | char *pszSQL = sqlite3_mprintf( |
| 7811 | "SELECT %s(\"%w\") FROM \"%w\"%s", osFuncName.c_str(), |
| 7812 | poDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(iGeomField)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., |
| 7813 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty() ? "" : (" WHERE " + m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter.).c_str()); |
| 7814 | char *pszErrMsg = nullptr; |
| 7815 | const int rc = |
| 7816 | sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, nullptr, &(pszErrMsg)); |
| 7817 | |
| 7818 | // Delete function |
| 7819 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osFuncName.c_str(), 1, SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`!, |
| 7820 | nullptr, nullptr, nullptr, nullptr); |
| 7821 | |
| 7822 | if (rc != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`! && !sContext.m_bIsGeometryTypeAggregateInterruptedcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_bIsGeometryTypeAggregateInterrupted.) |
| 7823 | { |
| 7824 | if (rc != SQLITE_INTERRUPTcxx . . $ `<external>/2400532043262193228/sqlite3.h:459:9`!) |
| 7825 | { |
| 7826 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "sqlite3_exec(%s) failed: %s", |
| 7827 | pszSQL, pszErrMsg); |
| 7828 | } |
| 7829 | sqlite3_free(pszErrMsg); |
| 7830 | sqlite3_free(pszSQL); |
| 7831 | nEntryCountOut = 0; |
| 7832 | return nullptr; |
| 7833 | } |
| 7834 | sqlite3_free(pszErrMsg); |
| 7835 | sqlite3_free(pszSQL); |
| 7836 | |
| 7837 | // Format result |
| 7838 | nEntryCountOut = static_cast<int>(sContext.m_oMapCountcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oMapCount..sizecxx . . $ std/map#size(a08d7b23eb6940f6).()); |
| 7839 | OGRGeometryTypeCounter *pasRet = static_cast<OGRGeometryTypeCounter *>( |
| 7840 | CPLCalloc(1 + nEntryCountOut, sizeof(OGRGeometryTypeCounter))); |
| 7841 | int i = 0; |
| 7842 | for (const auto &sEntry : sContext.m_oMapCountcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryTypeAggregateContext#m_oMapCount.) |
| 7843 | { |
| 7844 | pasRet[i].eGeomType = sEntry.first; |
| 7845 | pasRet[i].nCount = sEntry.second; |
| 7846 | ++i; |
| 7847 | } |
| 7848 | return pasRet; |
| 7849 | } |
| 7850 | |
| 7851 | /************************************************************************/ |
| 7852 | /* OGR_GPKG_FillArrowArray_Step() */ |
| 7853 | /************************************************************************/ |
| 7854 | |
| 7855 | void OGR_GPKG_FillArrowArray_Stepcxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).(sqlite3_context *pContext, int /*argc*/, |
| 7856 | sqlite3_value **argv); |
| 7857 | |
| 7858 | void OGR_GPKG_FillArrowArray_Stepcxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).(sqlite3_context *pContext, int /*argc*/, |
| 7859 | sqlite3_value **argv) |
| 7860 | { |
| 7861 | auto psFillArrowArray = static_cast<OGRGPKGTableLayerFillArrowArraycxx . . $ OGRGPKGTableLayerFillArrowArray# *>( |
| 7862 | sqlite3_user_data(pContext)); |
| 7863 | |
| 7864 | // To be called under psFillArrowArray->oMutex |
| 7865 | const auto SubmitBatchToCaller = |
| 7866 | [psFillArrowArray](stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> &oLock) |
| 7867 | { |
| 7868 | psFillArrowArray->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->Shrinkcxx . . $ OGRArrowArrayHelper#Shrink(d4f767463ce0a6b3).(psFillArrowArray->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows.); |
| 7869 | psFillArrowArray->bThreadReadycxx . . $ OGRGPKGTableLayerFillArrowArray#bThreadReady. = true; |
| 7870 | psFillArrowArray->oCVcxx . . $ OGRGPKGTableLayerFillArrowArray#oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 7871 | while (psFillArrowArray->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. > 0) |
| 7872 | { |
| 7873 | psFillArrowArray->oCVcxx . . $ OGRGPKGTableLayerFillArrowArray#oCV..waitcxx . . $ std/condition_variable#wait(f38159257778c065).(oLock); |
| 7874 | } |
| 7875 | }; |
| 7876 | |
| 7877 | const auto DealWithTooBigArray = |
| 7878 | [&SubmitBatchToCaller, psFillArrowArray](int iFeat) |
| 7879 | { |
| 7880 | CPLDebug("GPKG", |
| 7881 | "OGR_GPKG_FillArrowArray_Step(): premature " |
| 7882 | "notification of %d features to consumer due " |
| 7883 | "to too big array", |
| 7884 | iFeat); |
| 7885 | if (psFillArrowArray->bAsynchronousModecxx . . $ OGRGPKGTableLayerFillArrowArray#bAsynchronousMode.) |
| 7886 | { |
| 7887 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(psFillArrowArray->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 7888 | psFillArrowArray->bMemoryLimitReachedcxx . . $ OGRGPKGTableLayerFillArrowArray#bMemoryLimitReached. = true; |
| 7889 | SubmitBatchToCaller(cxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).$anonymous_type_0#`operator()`(181fa2d66b23228c).oLock); |
| 7890 | } |
| 7891 | else |
| 7892 | { |
| 7893 | { |
| 7894 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(psFillArrowArray->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 7895 | psFillArrowArray->bMemoryLimitReachedcxx . . $ OGRGPKGTableLayerFillArrowArray#bMemoryLimitReached. = true; |
| 7896 | } |
| 7897 | sqlite3_interrupt(psFillArrowArray->hDBcxx . . $ OGRGPKGTableLayerFillArrowArray#hDB.); |
| 7898 | } |
| 7899 | }; |
| 7900 | |
| 7901 | { |
| 7902 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(psFillArrowArray->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 7903 | if (psFillArrowArray->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. >= |
| 7904 | psFillArrowArray->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_nMaxBatchSizecxx . . $ OGRArrowArrayHelper#m_nMaxBatchSize.) |
| 7905 | { |
| 7906 | if (psFillArrowArray->bAsynchronousModecxx . . $ OGRGPKGTableLayerFillArrowArray#bAsynchronousMode.) |
| 7907 | { |
| 7908 | SubmitBatchToCaller(cxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).$anonymous_type_0#`operator()`(181fa2d66b23228c).oLock); |
| 7909 | // Note that psFillArrowArray->psHelper.get() will generally now be |
| 7910 | // different from before the wait() |
| 7911 | } |
| 7912 | else |
| 7913 | { |
| 7914 | // should not happen ! |
| 7915 | psFillArrowArray->osErrorMsgcxx . . $ OGRGPKGTableLayerFillArrowArray#osErrorMsg. = "OGR_GPKG_FillArrowArray_Step() " |
| 7916 | "got more rows than expected!"; |
| 7917 | sqlite3_interrupt(psFillArrowArray->hDBcxx . . $ OGRGPKGTableLayerFillArrowArray#hDB.); |
| 7918 | psFillArrowArray->bErrorOccurredcxx . . $ OGRGPKGTableLayerFillArrowArray#bErrorOccurred. = true; |
| 7919 | return; |
| 7920 | } |
| 7921 | } |
| 7922 | if (psFillArrowArray->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. < 0) |
| 7923 | return; |
| 7924 | } |
| 7925 | |
| 7926 | if (psFillArrowArray->nMemLimitcxx . . $ OGRGPKGTableLayerFillArrowArray#nMemLimit. == 0) |
| 7927 | psFillArrowArray->nMemLimitcxx . . $ OGRGPKGTableLayerFillArrowArray#nMemLimit. = OGRArrowArrayHelpercxx . . $ OGRArrowArrayHelper#::GetMemLimitcxx . . $ OGRArrowArrayHelper#GetMemLimit(db52760e79bf9054).(); |
| 7928 | const auto nMemLimit = psFillArrowArray->nMemLimitcxx . . $ OGRGPKGTableLayerFillArrowArray#nMemLimit.; |
| 7929 | const int SQLITE_MAX_FUNCTION_ARG = |
| 7930 | sqlite3_limit(psFillArrowArray->hDBcxx . . $ OGRGPKGTableLayerFillArrowArray#hDB., SQLITE_LIMIT_FUNCTION_ARGcxx . . $ `<external>/2400532043262193228/sqlite3.h:4415:9`!, -1); |
| 7931 | const bool bDateTimeAsString = psFillArrowArray->bDateTimeAsStringcxx . . $ OGRGPKGTableLayerFillArrowArray#bDateTimeAsString.; |
| 7932 | begin: |
| 7933 | int iFeat; |
| 7934 | OGRArrowArrayHelpercxx . . $ OGRArrowArrayHelper# *psHelper; |
| 7935 | { |
| 7936 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(psFillArrowArray->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 7937 | iFeat = psFillArrowArray->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows.; |
| 7938 | psHelper = psFillArrowArray->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper..get(); |
| 7939 | } |
| 7940 | int iCol = 0; |
| 7941 | const int iFieldStart = sqlite3_value_int(argv[iCol]); |
| 7942 | ++iCol; |
| 7943 | int iField = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, iFieldStart); |
| 7944 | |
| 7945 | GIntBigcxx . . $ GIntBig# nFID; |
| 7946 | if (iFieldStart < 0) |
| 7947 | { |
| 7948 | nFID = sqlite3_value_int64(argv[iCol]); |
| 7949 | iCol++; |
| 7950 | if (psHelper->m_panFIDValuescxx . . $ OGRArrowArrayHelper#m_panFIDValues.) |
| 7951 | { |
| 7952 | psHelper->m_panFIDValuescxx . . $ OGRArrowArrayHelper#m_panFIDValues.[iFeat] = nFID; |
| 7953 | } |
| 7954 | psFillArrowArray->nCurFIDcxx . . $ OGRGPKGTableLayerFillArrowArray#nCurFID. = nFID; |
| 7955 | } |
| 7956 | else |
| 7957 | { |
| 7958 | nFID = psFillArrowArray->nCurFIDcxx . . $ OGRGPKGTableLayerFillArrowArray#nCurFID.; |
| 7959 | } |
| 7960 | |
| 7961 | if (iFieldStart < 0 && !psHelper->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField..empty() && |
| 7962 | psHelper->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField.[0] >= 0) |
| 7963 | { |
| 7964 | const int iArrowField = psHelper->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField.[0]; |
| 7965 | auto psArray = psHelper->m_out_arraycxx . . $ OGRArrowArrayHelper#m_out_array.->children[iArrowField]; |
| 7966 | size_t nWKBSize = 0; |
| 7967 | const int nSqlite3ColType = sqlite3_value_type(argv[iCol]); |
| 7968 | if (nSqlite3ColType == SQLITE_BLOBcxx . . $ `<external>/2400532043262193228/sqlite3.h:5358:9`!) |
| 7969 | { |
| 7970 | GPkgHeadercxx . . $ GPkgHeader# oHeader; |
| 7971 | memset(&oHeader, 0, sizeof(oHeader)); |
| 7972 | |
| 7973 | const GBytecxx . . $ GByte# *pabyWkb = nullptr; |
| 7974 | const int nBlobSize = sqlite3_value_bytes(argv[iCol]); |
| 7975 | // coverity[tainted_data_return] |
| 7976 | const GBytecxx . . $ GByte# *pabyBlob = |
| 7977 | static_cast<const GBytecxx . . $ GByte# *>(sqlite3_value_blob(argv[iCol])); |
| 7978 | stdcxx . . $ std/::vector<GBytecxx . . $ GByte#> abyWkb; |
| 7979 | if (nBlobSize >= 8 && pabyBlob && pabyBlob[0] == 'G' && |
| 7980 | pabyBlob[1] == 'P') |
| 7981 | { |
| 7982 | if (psFillArrowArray->poLayercxx . . $ OGRGPKGTableLayerFillArrowArray#poLayer.->m_bUndoDiscardCoordLSBOnReadingcxx . . $ OGRGeoPackageLayer#m_bUndoDiscardCoordLSBOnReading.) |
| 7983 | { |
| 7984 | OGRGeometrycxx . . $ OGRGeometry# *poGeomPtr = |
| 7985 | GPkgGeometryToOGRcxx . . $ GPkgGeometryToOGR(2f7e6b0f464fc578).(pabyBlob, nBlobSize, nullptr); |
| 7986 | if (poGeomPtr) |
| 7987 | { |
| 7988 | poGeomPtr->roundCoordinatescxx . . $ OGRGeometry#roundCoordinates(a66dcf8fa4d01368).( |
| 7989 | psFillArrowArray->poFeatureDefncxx . . $ OGRGPKGTableLayerFillArrowArray#poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0) |
| 7990 | ->GetCoordinatePrecisioncxx . . $ OGRGeomFieldDefn#GetCoordinatePrecision(4cbff8bea018030e).()); |
| 7991 | nWKBSize = poGeomPtr->WkbSizecxx . . $ OGRGeometry#WkbSize(fe4d2d262d4164a8).(); |
| 7992 | abyWkb.resize(nWKBSize); |
| 7993 | if (poGeomPtr->exportToWkbcxx . . $ OGRGeometry#exportToWkb(cfa90e51281e04c0).(wkbNDR, abyWkb.data(), |
| 7994 | wkbVariantIso) != |
| 7995 | OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 7996 | { |
| 7997 | nWKBSize = 0; |
| 7998 | } |
| 7999 | else |
| 8000 | { |
| 8001 | pabyWkb = abyWkb.data(); |
| 8002 | } |
| 8003 | delete poGeomPtr; |
| 8004 | } |
| 8005 | } |
| 8006 | else |
| 8007 | { |
| 8008 | /* Read header */ |
| 8009 | OGRErr err = |
| 8010 | GPkgHeaderFromWKBcxx . . $ GPkgHeaderFromWKB(5dfb47f6cfa574ea).(pabyBlob, nBlobSize, &oHeader); |
| 8011 | if (err == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 8012 | { |
| 8013 | /* WKB pointer */ |
| 8014 | pabyWkb = pabyBlob + oHeader.nHeaderLencxx . . $ $anonymous_type_2b740b2c8f9610bf_0#nHeaderLen.; |
| 8015 | nWKBSize = nBlobSize - oHeader.nHeaderLencxx . . $ $anonymous_type_2b740b2c8f9610bf_0#nHeaderLen.; |
| 8016 | } |
| 8017 | } |
| 8018 | } |
| 8019 | else if (nBlobSize > 0 && pabyBlob) |
| 8020 | { |
| 8021 | // Try also spatialite geometry blobs, although that is |
| 8022 | // not really expected... |
| 8023 | OGRGeometrycxx . . $ OGRGeometry# *poGeomPtr = nullptr; |
| 8024 | if (OGRSQLiteImportSpatiaLiteGeometrycxx . . $ OGRSQLiteImportSpatiaLiteGeometry(5f689a382454ef53).( |
| 8025 | pabyBlob, nBlobSize, &poGeomPtr) != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 8026 | { |
| 8027 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 8028 | "Unable to read geometry"); |
| 8029 | } |
| 8030 | else |
| 8031 | { |
| 8032 | nWKBSize = poGeomPtr->WkbSizecxx . . $ OGRGeometry#WkbSize(fe4d2d262d4164a8).(); |
| 8033 | abyWkb.resize(nWKBSize); |
| 8034 | if (poGeomPtr->exportToWkbcxx . . $ OGRGeometry#exportToWkb(cfa90e51281e04c0).(wkbNDR, abyWkb.data(), |
| 8035 | wkbVariantIso) != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 8036 | { |
| 8037 | nWKBSize = 0; |
| 8038 | } |
| 8039 | else |
| 8040 | { |
| 8041 | pabyWkb = abyWkb.data(); |
| 8042 | } |
| 8043 | } |
| 8044 | delete poGeomPtr; |
| 8045 | } |
| 8046 | |
| 8047 | if (nWKBSize != 0) |
| 8048 | { |
| 8049 | // Deal with spatial filter |
| 8050 | if (psFillArrowArray->poLayerForFilterGeomcxx . . $ OGRGPKGTableLayerFillArrowArray#poLayerForFilterGeom.) |
| 8051 | { |
| 8052 | OGREnvelope sEnvelope; |
| 8053 | bool bEnvelopeAlreadySet = false; |
| 8054 | if (oHeader.bEmptycxx . . $ $anonymous_type_2b740b2c8f9610bf_0#bEmpty.) |
| 8055 | { |
| 8056 | bEnvelopeAlreadySet = true; |
| 8057 | } |
| 8058 | else if (oHeader.bExtentHasXYcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#bExtentHasXY.) |
| 8059 | { |
| 8060 | bEnvelopeAlreadySet = true; |
| 8061 | sEnvelope.MinX = oHeader.MinXcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MinX.; |
| 8062 | sEnvelope.MinY = oHeader.MinYcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MinY.; |
| 8063 | sEnvelope.MaxX = oHeader.MaxXcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MaxX.; |
| 8064 | sEnvelope.MaxY = oHeader.MaxYcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MaxY.; |
| 8065 | } |
| 8066 | |
| 8067 | if (!psFillArrowArray->poLayerForFilterGeomcxx . . $ OGRGPKGTableLayerFillArrowArray#poLayerForFilterGeom. |
| 8068 | ->FilterWKBGeometrycxx . . $ OGRLayer#FilterWKBGeometry(bf9031396d345017).(pabyWkb, nWKBSize, |
| 8069 | bEnvelopeAlreadySet, |
| 8070 | sEnvelope)) |
| 8071 | { |
| 8072 | return; |
| 8073 | } |
| 8074 | } |
| 8075 | |
| 8076 | if (iFeat > 0) |
| 8077 | { |
| 8078 | auto panOffsets = static_cast<int32_t *>( |
| 8079 | const_cast<void *>(psArray->buffers[1])); |
| 8080 | const uint32_tcxx . . $ uint32_t# nCurLength = |
| 8081 | static_cast<uint32_tcxx . . $ uint32_t#>(panOffsets[iFeat]); |
| 8082 | if (nWKBSize <= nMemLimit && |
| 8083 | nWKBSize > nMemLimit - nCurLength) |
| 8084 | { |
| 8085 | DealWithTooBigArray(cxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).$anonymous_type_1#`operator()`(d76a70202c25db1).iFeat); |
| 8086 | if (psFillArrowArray->bAsynchronousModecxx . . $ OGRGPKGTableLayerFillArrowArray#bAsynchronousMode.) |
| 8087 | { |
| 8088 | goto begin; |
| 8089 | } |
| 8090 | else |
| 8091 | { |
| 8092 | return; |
| 8093 | } |
| 8094 | } |
| 8095 | } |
| 8096 | |
| 8097 | GBytecxx . . $ GByte# *outPtr = psHelper->GetPtrForStringOrBinarycxx . . $ OGRArrowArrayHelper#GetPtrForStringOrBinary(47285e4a556c5ed5).( |
| 8098 | iArrowField, iFeat, nWKBSize); |
| 8099 | if (outPtr == nullptr) |
| 8100 | { |
| 8101 | goto error; |
| 8102 | } |
| 8103 | memcpy(outPtr, pabyWkb, nWKBSize); |
| 8104 | } |
| 8105 | else |
| 8106 | { |
| 8107 | psHelper->SetEmptyStringOrBinarycxx . . $ OGRArrowArrayHelper#SetEmptyStringOrBinary(647c69b75b545302).(psArray, iFeat); |
| 8108 | } |
| 8109 | } |
| 8110 | |
| 8111 | if (nWKBSize == 0) |
| 8112 | { |
| 8113 | if (!psHelper->SetNullcxx . . $ OGRArrowArrayHelper#SetNull(cf9ef193275fa6d8).(iArrowField, iFeat)) |
| 8114 | { |
| 8115 | goto error; |
| 8116 | } |
| 8117 | } |
| 8118 | iCol++; |
| 8119 | } |
| 8120 | |
| 8121 | for (; iField < psHelper->m_nFieldCountcxx . . $ OGRArrowArrayHelper#m_nFieldCount.; iField++) |
| 8122 | { |
| 8123 | const int iArrowField = psHelper->m_mapOGRFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRFieldToArrowField.[iField]; |
| 8124 | if (iArrowField < 0) |
| 8125 | continue; |
| 8126 | if (iCol == SQLITE_MAX_FUNCTION_ARG) |
| 8127 | break; |
| 8128 | |
| 8129 | const OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = |
| 8130 | psFillArrowArray->poFeatureDefncxx . . $ OGRGPKGTableLayerFillArrowArray#poFeatureDefn.->GetFieldDefnUnsafecxx . . $ OGRFeatureDefn#GetFieldDefnUnsafe(2ec36f91b6ceefc7).(iField); |
| 8131 | |
| 8132 | auto psArray = psHelper->m_out_arraycxx . . $ OGRArrowArrayHelper#m_out_array.->children[iArrowField]; |
| 8133 | |
| 8134 | const int nSqlite3ColType = sqlite3_value_type(argv[iCol]); |
| 8135 | if (nSqlite3ColType == SQLITE_NULLcxx . . $ `<external>/2400532043262193228/sqlite3.h:5359:9`!) |
| 8136 | { |
| 8137 | if (!psHelper->SetNullcxx . . $ OGRArrowArrayHelper#SetNull(cf9ef193275fa6d8).(iArrowField, iFeat)) |
| 8138 | { |
| 8139 | goto error; |
| 8140 | } |
| 8141 | iCol++; |
| 8142 | continue; |
| 8143 | } |
| 8144 | |
| 8145 | switch (poFieldDefn->GetTypecxx . . $ OGRFieldDefn#GetType(b365ab774e05458e).()) |
| 8146 | { |
| 8147 | case OFTInteger: |
| 8148 | { |
| 8149 | const int nVal = sqlite3_value_int(argv[iCol]); |
| 8150 | if (poFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).() == OFSTBoolean) |
| 8151 | { |
| 8152 | if (nVal != 0) |
| 8153 | { |
| 8154 | psHelper->SetBoolOncxx . . $ OGRArrowArrayHelper#SetBoolOn(647c69b75b545302).(psArray, iFeat); |
| 8155 | } |
| 8156 | } |
| 8157 | else if (poFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).() == OFSTInt16) |
| 8158 | { |
| 8159 | psHelper->SetInt16cxx . . $ OGRArrowArrayHelper#SetInt16(b405a4372e2c02ab).(psArray, iFeat, |
| 8160 | static_cast<int16_t>(nVal)); |
| 8161 | } |
| 8162 | else |
| 8163 | { |
| 8164 | psHelper->SetInt32cxx . . $ OGRArrowArrayHelper#SetInt32(7adfdbc6f97800c1).(psArray, iFeat, nVal); |
| 8165 | } |
| 8166 | break; |
| 8167 | } |
| 8168 | |
| 8169 | case OFTInteger64: |
| 8170 | { |
| 8171 | psHelper->SetInt64cxx . . $ OGRArrowArrayHelper#SetInt64(6029e2da00656029).(psArray, iFeat, |
| 8172 | sqlite3_value_int64(argv[iCol])); |
| 8173 | break; |
| 8174 | } |
| 8175 | |
| 8176 | case OFTReal: |
| 8177 | { |
| 8178 | const double dfVal = sqlite3_value_double(argv[iCol]); |
| 8179 | if (poFieldDefn->GetSubTypecxx . . $ OGRFieldDefn#GetSubType(4db5e065ad90bc77).() == OFSTFloat32) |
| 8180 | { |
| 8181 | psHelper->SetFloatcxx . . $ OGRArrowArrayHelper#SetFloat(5bf4fcd39b9d2bc5).(psArray, iFeat, |
| 8182 | static_cast<float>(dfVal)); |
| 8183 | } |
| 8184 | else |
| 8185 | { |
| 8186 | psHelper->SetDoublecxx . . $ OGRArrowArrayHelper#SetDouble(456a041b0b32ee54).(psArray, iFeat, dfVal); |
| 8187 | } |
| 8188 | break; |
| 8189 | } |
| 8190 | |
| 8191 | case OFTBinary: |
| 8192 | { |
| 8193 | const uint32_tcxx . . $ uint32_t# nBytes = |
| 8194 | static_cast<uint32_tcxx . . $ uint32_t#>(sqlite3_value_bytes(argv[iCol])); |
| 8195 | // coverity[tainted_data_return] |
| 8196 | const void *pabyData = sqlite3_value_blob(argv[iCol]); |
| 8197 | if (pabyData != nullptr || nBytes == 0) |
| 8198 | { |
| 8199 | if (iFeat > 0) |
| 8200 | { |
| 8201 | auto panOffsets = static_cast<int32_t *>( |
| 8202 | const_cast<void *>(psArray->buffers[1])); |
| 8203 | const uint32_tcxx . . $ uint32_t# nCurLength = |
| 8204 | static_cast<uint32_tcxx . . $ uint32_t#>(panOffsets[iFeat]); |
| 8205 | if (nBytes <= nMemLimit && |
| 8206 | nBytes > nMemLimit - nCurLength) |
| 8207 | { |
| 8208 | DealWithTooBigArray(cxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).$anonymous_type_1#`operator()`(d76a70202c25db1).iFeat); |
| 8209 | if (psFillArrowArray->bAsynchronousModecxx . . $ OGRGPKGTableLayerFillArrowArray#bAsynchronousMode.) |
| 8210 | { |
| 8211 | goto begin; |
| 8212 | } |
| 8213 | else |
| 8214 | { |
| 8215 | return; |
| 8216 | } |
| 8217 | } |
| 8218 | } |
| 8219 | |
| 8220 | GBytecxx . . $ GByte# *outPtr = psHelper->GetPtrForStringOrBinarycxx . . $ OGRArrowArrayHelper#GetPtrForStringOrBinary(47285e4a556c5ed5).( |
| 8221 | iArrowField, iFeat, nBytes); |
| 8222 | if (outPtr == nullptr) |
| 8223 | { |
| 8224 | goto error; |
| 8225 | } |
| 8226 | if (nBytes) |
| 8227 | memcpy(outPtr, pabyData, nBytes); |
| 8228 | } |
| 8229 | else |
| 8230 | { |
| 8231 | psHelper->SetEmptyStringOrBinarycxx . . $ OGRArrowArrayHelper#SetEmptyStringOrBinary(647c69b75b545302).(psArray, iFeat); |
| 8232 | } |
| 8233 | break; |
| 8234 | } |
| 8235 | |
| 8236 | case OFTDate: |
| 8237 | { |
| 8238 | OGRField ogrField; |
| 8239 | const auto pszTxt = reinterpret_cast<const char *>( |
| 8240 | sqlite3_value_text(argv[iCol])); |
| 8241 | if (pszTxt != nullptr && |
| 8242 | psFillArrowArray->poLayercxx . . $ OGRGPKGTableLayerFillArrowArray#poLayer.->ParseDateFieldcxx . . $ OGRGeoPackageLayer#ParseDateField(97b28622d98424a1).( |
| 8243 | pszTxt, &ogrField, poFieldDefn, nFID)) |
| 8244 | { |
| 8245 | psHelper->SetDatecxx . . $ OGRArrowArrayHelper#SetDate(285c5139b8c9f774).(psArray, iFeat, |
| 8246 | psFillArrowArray->brokenDowncxx . . $ OGRGPKGTableLayerFillArrowArray#brokenDown., ogrField); |
| 8247 | } |
| 8248 | break; |
| 8249 | } |
| 8250 | |
| 8251 | case OFTDateTime: |
| 8252 | { |
| 8253 | if (!bDateTimeAsString) |
| 8254 | { |
| 8255 | OGRField ogrField; |
| 8256 | const auto pszTxt = reinterpret_cast<const char *>( |
| 8257 | sqlite3_value_text(argv[iCol])); |
| 8258 | if (pszTxt != nullptr && |
| 8259 | psFillArrowArray->poLayercxx . . $ OGRGPKGTableLayerFillArrowArray#poLayer.->ParseDateTimeFieldcxx . . $ OGRGeoPackageLayer#ParseDateTimeField(97b28622d98424a1).( |
| 8260 | pszTxt, &ogrField, poFieldDefn, nFID)) |
| 8261 | { |
| 8262 | psHelper->SetDateTimecxx . . $ OGRArrowArrayHelper#SetDateTime(30c816e5f2953726).( |
| 8263 | psArray, iFeat, psFillArrowArray->brokenDowncxx . . $ OGRGPKGTableLayerFillArrowArray#brokenDown., |
| 8264 | psHelper->m_anTZFlagscxx . . $ OGRArrowArrayHelper#m_anTZFlags.[iField], ogrField); |
| 8265 | } |
| 8266 | break; |
| 8267 | } |
| 8268 | else |
| 8269 | { |
| 8270 | [[fallthrough]]; |
| 8271 | } |
| 8272 | } |
| 8273 | |
| 8274 | case OFTString: |
| 8275 | { |
| 8276 | const auto pszTxt = reinterpret_cast<const char *>( |
| 8277 | sqlite3_value_text(argv[iCol])); |
| 8278 | if (pszTxt != nullptr) |
| 8279 | { |
| 8280 | const size_t nBytes = strlen(pszTxt); |
| 8281 | if (iFeat > 0) |
| 8282 | { |
| 8283 | auto panOffsets = static_cast<int32_t *>( |
| 8284 | const_cast<void *>(psArray->buffers[1])); |
| 8285 | const uint32_tcxx . . $ uint32_t# nCurLength = |
| 8286 | static_cast<uint32_tcxx . . $ uint32_t#>(panOffsets[iFeat]); |
| 8287 | if (nBytes <= nMemLimit && |
| 8288 | nBytes > nMemLimit - nCurLength) |
| 8289 | { |
| 8290 | DealWithTooBigArray(cxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d).$anonymous_type_1#`operator()`(d76a70202c25db1).iFeat); |
| 8291 | if (psFillArrowArray->bAsynchronousModecxx . . $ OGRGPKGTableLayerFillArrowArray#bAsynchronousMode.) |
| 8292 | { |
| 8293 | goto begin; |
| 8294 | } |
| 8295 | else |
| 8296 | { |
| 8297 | return; |
| 8298 | } |
| 8299 | } |
| 8300 | } |
| 8301 | |
| 8302 | GBytecxx . . $ GByte# *outPtr = psHelper->GetPtrForStringOrBinarycxx . . $ OGRArrowArrayHelper#GetPtrForStringOrBinary(47285e4a556c5ed5).( |
| 8303 | iArrowField, iFeat, nBytes); |
| 8304 | if (outPtr == nullptr) |
| 8305 | { |
| 8306 | goto error; |
| 8307 | } |
| 8308 | if (nBytes) |
| 8309 | memcpy(outPtr, pszTxt, nBytes); |
| 8310 | } |
| 8311 | else |
| 8312 | { |
| 8313 | psHelper->SetEmptyStringOrBinarycxx . . $ OGRArrowArrayHelper#SetEmptyStringOrBinary(647c69b75b545302).(psArray, iFeat); |
| 8314 | } |
| 8315 | break; |
| 8316 | } |
| 8317 | |
| 8318 | default: |
| 8319 | break; |
| 8320 | } |
| 8321 | |
| 8322 | iCol++; |
| 8323 | } |
| 8324 | |
| 8325 | if (iField == psHelper->m_nFieldCountcxx . . $ OGRArrowArrayHelper#m_nFieldCount.) |
| 8326 | { |
| 8327 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(psFillArrowArray->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 8328 | psFillArrowArray->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows.++; |
| 8329 | } |
| 8330 | return; |
| 8331 | |
| 8332 | error: |
| 8333 | sqlite3_interrupt(psFillArrowArray->hDBcxx . . $ OGRGPKGTableLayerFillArrowArray#hDB.); |
| 8334 | } |
| 8335 | |
| 8336 | /************************************************************************/ |
| 8337 | /* OGR_GPKG_FillArrowArray_Finalize() */ |
| 8338 | /************************************************************************/ |
| 8339 | |
| 8340 | static void OGR_GPKG_FillArrowArray_Finalizecxx . . $ OGR_GPKG_FillArrowArray_Finalize(e5276f5e0ac5ec48).(sqlite3_context * /*pContext*/) |
| 8341 | { |
| 8342 | } |
| 8343 | |
| 8344 | /************************************************************************/ |
| 8345 | /* GetNextArrowArrayAsynchronous() */ |
| 8346 | /************************************************************************/ |
| 8347 | |
| 8348 | int OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetNextArrowArrayAsynchronouscxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronous(b1dcf2e4b2dc4bae).( |
| 8349 | struct ArrowArrayStreamcxx . . $ ArrowArrayStream# *stream, struct ArrowArray *out_array) |
| 8350 | { |
| 8351 | memset(out_array, 0, sizeof(*out_array)); |
| 8352 | |
| 8353 | m_bGetNextArrowArrayCalledSinceResetReadingcxx . . $ OGRGeoPackageTableLayer#m_bGetNextArrowArrayCalledSinceResetReading. = true; |
| 8354 | |
| 8355 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.) |
| 8356 | { |
| 8357 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 8358 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bIsFinishedcxx . . $ OGRGPKGTableLayerFillArrowArray#bIsFinished.) |
| 8359 | { |
| 8360 | return 0; |
| 8361 | } |
| 8362 | } |
| 8363 | |
| 8364 | auto psHelper = stdcxx . . $ std/::make_unique<OGRArrowArrayHelpercxx . . $ OGRArrowArrayHelper#>( |
| 8365 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS., m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn., m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions., out_array); |
| 8366 | if (out_array->release == nullptr) |
| 8367 | { |
| 8368 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 8369 | } |
| 8370 | |
| 8371 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray. == nullptr) |
| 8372 | { |
| 8373 | // Check that the total number of arguments passed to |
| 8374 | // OGR_GPKG_FillArrowArray_INTERNAL() doesn't exceed SQLITE_MAX_FUNCTION_ARG |
| 8375 | // If it does, we cannot reliably use GetNextArrowArrayAsynchronous() in |
| 8376 | // the situation where the ArrowArray would exceed the nMemLimit. |
| 8377 | // So be on the safe side, and rely on the base OGRGeoPackageLayer |
| 8378 | // implementation |
| 8379 | const int SQLITE_MAX_FUNCTION_ARG = |
| 8380 | sqlite3_limit(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), SQLITE_LIMIT_FUNCTION_ARGcxx . . $ `<external>/2400532043262193228/sqlite3.h:4415:9`!, -1); |
| 8381 | int nCountArgs = 1 // field index |
| 8382 | + 1; // FID column |
| 8383 | if (!psHelper->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField..empty() && |
| 8384 | psHelper->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField.[0] >= 0) |
| 8385 | { |
| 8386 | ++nCountArgs; |
| 8387 | } |
| 8388 | for (int iField = 0; iField < psHelper->m_nFieldCountcxx . . $ OGRArrowArrayHelper#m_nFieldCount.; iField++) |
| 8389 | { |
| 8390 | const int iArrowField = psHelper->m_mapOGRFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRFieldToArrowField.[iField]; |
| 8391 | if (iArrowField >= 0) |
| 8392 | { |
| 8393 | if (nCountArgs == SQLITE_MAX_FUNCTION_ARG) |
| 8394 | { |
| 8395 | psHelper.reset(); |
| 8396 | if (out_array->release) |
| 8397 | out_array->release(out_array); |
| 8398 | return OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#::GetNextArrowArraycxx . . $ OGRGeoPackageLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).(stream, |
| 8399 | out_array); |
| 8400 | } |
| 8401 | ++nCountArgs; |
| 8402 | } |
| 8403 | } |
| 8404 | |
| 8405 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray. = |
| 8406 | stdcxx . . $ std/::make_unique<OGRGPKGTableLayerFillArrowArraycxx . . $ OGRGPKGTableLayerFillArrowArray#>(); |
| 8407 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper. = stdcxx . . $ std/::move(psHelper); |
| 8408 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bDateTimeAsStringcxx . . $ OGRGPKGTableLayerFillArrowArray#bDateTimeAsString. = |
| 8409 | m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions..FetchBool(GAS_OPT_DATETIME_AS_STRINGcxx . . $ GAS_OPT_DATETIME_AS_STRING., |
| 8410 | false); |
| 8411 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->poFeatureDefncxx . . $ OGRGPKGTableLayerFillArrowArray#poFeatureDefn. = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.; |
| 8412 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->poLayercxx . . $ OGRGPKGTableLayerFillArrowArray#poLayer. = this; |
| 8413 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->hDBcxx . . $ OGRGPKGTableLayerFillArrowArray#hDB. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 8414 | memset(&m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->brokenDowncxx . . $ OGRGPKGTableLayerFillArrowArray#brokenDown., 0, |
| 8415 | sizeof(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->brokenDowncxx . . $ OGRGPKGTableLayerFillArrowArray#brokenDown.)); |
| 8416 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bAsynchronousModecxx . . $ OGRGPKGTableLayerFillArrowArray#bAsynchronousMode. = true; |
| 8417 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom.) |
| 8418 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->poLayerForFilterGeomcxx . . $ OGRGPKGTableLayerFillArrowArray#poLayerForFilterGeom. = this; |
| 8419 | |
| 8420 | try |
| 8421 | { |
| 8422 | m_oThreadNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_oThreadNextArrowArray. =cxx . . $ std/thread#`operator=`(e140d598480f0461). stdcxx . . $ std/::threadcxx . . $ std/thread#( |
| 8423 | [this]() { GetNextArrowArrayAsynchronousWorkercxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronousWorker(49f6e7a06ebc5aa8).(); }); |
| 8424 | } |
| 8425 | catch (const stdcxx . . $ std/::exception &e) |
| 8426 | { |
| 8427 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray..reset(); |
| 8428 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 8429 | "Cannot start worker thread: %s", e.what()); |
| 8430 | out_array->release(out_array); |
| 8431 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 8432 | } |
| 8433 | } |
| 8434 | else |
| 8435 | { |
| 8436 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 8437 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bErrorOccurredcxx . . $ OGRGPKGTableLayerFillArrowArray#bErrorOccurred.) |
| 8438 | { |
| 8439 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "%s", |
| 8440 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->osErrorMsgcxx . . $ OGRGPKGTableLayerFillArrowArray#osErrorMsg..c_str()); |
| 8441 | out_array->release(out_array); |
| 8442 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 8443 | } |
| 8444 | |
| 8445 | // Resume worker thread |
| 8446 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper. = stdcxx . . $ std/::move(psHelper); |
| 8447 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. = 0; |
| 8448 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bThreadReadycxx . . $ OGRGPKGTableLayerFillArrowArray#bThreadReady. = false; |
| 8449 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bMemoryLimitReachedcxx . . $ OGRGPKGTableLayerFillArrowArray#bMemoryLimitReached. = false; |
| 8450 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oCVcxx . . $ OGRGPKGTableLayerFillArrowArray#oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 8451 | } |
| 8452 | |
| 8453 | // Wait for GetNextArrowArrayAsynchronousWorker() / |
| 8454 | // OGR_GPKG_FillArrowArray_Step() to have generated a result set (or an |
| 8455 | // error) |
| 8456 | bool bIsFinished; |
| 8457 | stdcxx . . $ std/::string osErrorMsg; |
| 8458 | { |
| 8459 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 8460 | while (!m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bThreadReadycxx . . $ OGRGPKGTableLayerFillArrowArray#bThreadReady.) |
| 8461 | { |
| 8462 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oCVcxx . . $ OGRGPKGTableLayerFillArrowArray#oCV..waitcxx . . $ std/condition_variable#wait(f38159257778c065).(oLock); |
| 8463 | } |
| 8464 | CPLAssertcxx . . $ `port/cpl_error.h:353:9`!(m_poFillArrowArray->bErrorOccurred || |
| 8465 | m_poFillArrowArray->bMemoryLimitReached || |
| 8466 | m_poFillArrowArray->bIsFinished || |
| 8467 | m_poFillArrowArray->nCountRows == |
| 8468 | m_poFillArrowArray->psHelper->m_nMaxBatchSize); |
| 8469 | bIsFinished = m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bIsFinishedcxx . . $ OGRGPKGTableLayerFillArrowArray#bIsFinished.; |
| 8470 | osErrorMsg = m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->osErrorMsgcxx . . $ OGRGPKGTableLayerFillArrowArray#osErrorMsg.; |
| 8471 | } |
| 8472 | |
| 8473 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bErrorOccurredcxx . . $ OGRGPKGTableLayerFillArrowArray#bErrorOccurred.) |
| 8474 | { |
| 8475 | m_oThreadNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_oThreadNextArrowArray..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 8476 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "%s", osErrorMsg.c_str()); |
| 8477 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->ClearArraycxx . . $ OGRArrowArrayHelper#ClearArray(49f6e7a06ebc5aa8).(); |
| 8478 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 8479 | } |
| 8480 | else if (bIsFinished) |
| 8481 | { |
| 8482 | m_oThreadNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_oThreadNextArrowArray..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 8483 | } |
| 8484 | |
| 8485 | return 0; |
| 8486 | } |
| 8487 | |
| 8488 | /************************************************************************/ |
| 8489 | /* GetNextArrowArrayAsynchronousWorker() */ |
| 8490 | /************************************************************************/ |
| 8491 | |
| 8492 | void OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetNextArrowArrayAsynchronousWorkercxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronousWorker(49f6e7a06ebc5aa8).() |
| 8493 | { |
| 8494 | sqlite3_create_function( |
| 8495 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "OGR_GPKG_FillArrowArray_INTERNAL", -1, |
| 8496 | SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`! | SQLITE_DETERMINISTICcxx . . $ `<external>/2400532043262193228/sqlite3.h:5985:9`!, m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray..get(), nullptr, |
| 8497 | OGR_GPKG_FillArrowArray_Stepcxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d)., OGR_GPKG_FillArrowArray_Finalizecxx . . $ OGR_GPKG_FillArrowArray_Finalize(e5276f5e0ac5ec48).); |
| 8498 | |
| 8499 | stdcxx . . $ std/::string osSQL; |
| 8500 | osSQL = "SELECT OGR_GPKG_FillArrowArray_INTERNAL(-1,"; |
| 8501 | |
| 8502 | const auto AddFields = [this, &osSQL]() |
| 8503 | { |
| 8504 | if (m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.) |
| 8505 | { |
| 8506 | osSQL += "m.\""; |
| 8507 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 8508 | osSQL += '"'; |
| 8509 | } |
| 8510 | else |
| 8511 | { |
| 8512 | osSQL += "NULL"; |
| 8513 | } |
| 8514 | |
| 8515 | if (!m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField. |
| 8516 | .empty() && |
| 8517 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField.[0] >= 0) |
| 8518 | { |
| 8519 | osSQL += ",m.\""; |
| 8520 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).()); |
| 8521 | osSQL += '"'; |
| 8522 | } |
| 8523 | for (int iField = 0; |
| 8524 | iField < m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_nFieldCountcxx . . $ OGRArrowArrayHelper#m_nFieldCount.; iField++) |
| 8525 | { |
| 8526 | const int iArrowField = |
| 8527 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_mapOGRFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRFieldToArrowField.[iField]; |
| 8528 | if (iArrowField >= 0) |
| 8529 | { |
| 8530 | const OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = |
| 8531 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefnUnsafecxx . . $ OGRFeatureDefn#GetFieldDefnUnsafe(2ec36f91b6ceefc7).(iField); |
| 8532 | osSQL += ",m.\""; |
| 8533 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 8534 | osSQL += '"'; |
| 8535 | } |
| 8536 | } |
| 8537 | }; |
| 8538 | |
| 8539 | AddFields(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronousWorker(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(83f5f38750778ac8).); |
| 8540 | |
| 8541 | osSQL += ") FROM "; |
| 8542 | if (m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. > 0) |
| 8543 | { |
| 8544 | osSQL += "(SELECT "; |
| 8545 | AddFields(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronousWorker(49f6e7a06ebc5aa8).$anonymous_type_2#`operator()`(83f5f38750778ac8).); |
| 8546 | osSQL += " FROM "; |
| 8547 | } |
| 8548 | osSQL += '\"'; |
| 8549 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 8550 | osSQL += "\" m"; |
| 8551 | if (!m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty()) |
| 8552 | { |
| 8553 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr && m_pszAttrQueryStringcxx . . $ OGRLayer#m_pszAttrQueryString. == nullptr && |
| 8554 | HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 8555 | { |
| 8556 | OGREnvelope sEnvelope; |
| 8557 | |
| 8558 | m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom.->getEnvelopecxx . . $ OGRGeometry#getEnvelope(e5217c1f2a4fd7ce).(&sEnvelope); |
| 8559 | |
| 8560 | bool bUseSpatialIndex = true; |
| 8561 | if (m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent. && sEnvelope.MinX <= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinX && |
| 8562 | sEnvelope.MinY <= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MinY && |
| 8563 | sEnvelope.MaxX >= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxX && |
| 8564 | sEnvelope.MaxY >= m_poExtentcxx . . $ OGRGeoPackageTableLayer#m_poExtent.->MaxY) |
| 8565 | { |
| 8566 | // Selecting from spatial filter on whole extent can be rather |
| 8567 | // slow. So use function based filtering, just in case the |
| 8568 | // advertized global extent might be wrong. Otherwise we might |
| 8569 | // just discard completely the spatial filter. |
| 8570 | bUseSpatialIndex = false; |
| 8571 | } |
| 8572 | |
| 8573 | if (bUseSpatialIndex && !stdcxx . . $ std/::isinf(sEnvelope.MinX) && |
| 8574 | !stdcxx . . $ std/::isinf(sEnvelope.MinY) && !stdcxx . . $ std/::isinf(sEnvelope.MaxX) && |
| 8575 | !stdcxx . . $ std/::isinf(sEnvelope.MaxY)) |
| 8576 | { |
| 8577 | osSQL += |
| 8578 | CPLSPrintf(" JOIN \"%s\" r " |
| 8579 | "ON m.\"%s\" = r.id WHERE " |
| 8580 | "r.maxx >= %.12f AND r.minx <= %.12f AND " |
| 8581 | "r.maxy >= %.12f AND r.miny <= %.12f", |
| 8582 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName.).c_str(), |
| 8583 | SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_osFIDForRTreecxx . . $ OGRGeoPackageTableLayer#m_osFIDForRTree.).c_str(), |
| 8584 | sEnvelope.MinX - 1e-11, sEnvelope.MaxX + 1e-11, |
| 8585 | sEnvelope.MinY - 1e-11, sEnvelope.MaxY + 1e-11); |
| 8586 | } |
| 8587 | } |
| 8588 | else |
| 8589 | { |
| 8590 | osSQL += " WHERE "; |
| 8591 | osSQL += m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter.; |
| 8592 | } |
| 8593 | } |
| 8594 | |
| 8595 | if (m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. > 0) |
| 8596 | osSQL += |
| 8597 | CPLSPrintf(" LIMIT -1 OFFSET " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! ") m", m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId.); |
| 8598 | |
| 8599 | // CPLDebug("GPKG", "%s", osSQL.c_str()); |
| 8600 | |
| 8601 | char *pszErrMsg = nullptr; |
| 8602 | stdcxx . . $ std/::string osErrorMsg; |
| 8603 | if (sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL.c_str(), nullptr, nullptr, |
| 8604 | &pszErrMsg) != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 8605 | { |
| 8606 | osErrorMsg = pszErrMsg ? pszErrMsg : "unknown error"; |
| 8607 | } |
| 8608 | sqlite3_free(pszErrMsg); |
| 8609 | |
| 8610 | // Delete function |
| 8611 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "OGR_GPKG_FillArrowArray_INTERNAL", |
| 8612 | -1, SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`! | SQLITE_DETERMINISTICcxx . . $ `<external>/2400532043262193228/sqlite3.h:5985:9`!, nullptr, |
| 8613 | nullptr, nullptr, nullptr); |
| 8614 | |
| 8615 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oMutexcxx . . $ OGRGPKGTableLayerFillArrowArray#oMutex.); |
| 8616 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bIsFinishedcxx . . $ OGRGPKGTableLayerFillArrowArray#bIsFinished. = true; |
| 8617 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bErrorOccurredcxx . . $ OGRGPKGTableLayerFillArrowArray#bErrorOccurred. = !osErrorMsg.empty(); |
| 8618 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->osErrorMsgcxx . . $ OGRGPKGTableLayerFillArrowArray#osErrorMsg. = stdcxx . . $ std/::move(osErrorMsg); |
| 8619 | |
| 8620 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. >= 0) |
| 8621 | { |
| 8622 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->Shrinkcxx . . $ OGRArrowArrayHelper#Shrink(d4f767463ce0a6b3).(m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows.); |
| 8623 | if (m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. == 0) |
| 8624 | { |
| 8625 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->ClearArraycxx . . $ OGRArrowArrayHelper#ClearArray(49f6e7a06ebc5aa8).(); |
| 8626 | } |
| 8627 | } |
| 8628 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->bThreadReadycxx . . $ OGRGPKGTableLayerFillArrowArray#bThreadReady. = true; |
| 8629 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray.->oCVcxx . . $ OGRGPKGTableLayerFillArrowArray#oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 8630 | } |
| 8631 | |
| 8632 | /************************************************************************/ |
| 8633 | /* GetNextArrowArray() */ |
| 8634 | /************************************************************************/ |
| 8635 | |
| 8636 | int OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).(struct ArrowArrayStreamcxx . . $ ArrowArrayStream# *stream, |
| 8637 | struct ArrowArray *out_array) |
| 8638 | { |
| 8639 | if (!m_bFeatureDefnCompletedcxx . . $ OGRGeoPackageTableLayer#m_bFeatureDefnCompleted.) |
| 8640 | GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 8641 | if (m_bDeferredCreationcxx . . $ OGRGeoPackageTableLayer#m_bDeferredCreation. && RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).() != OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 8642 | { |
| 8643 | memset(out_array, 0, sizeof(*out_array)); |
| 8644 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 8645 | } |
| 8646 | |
| 8647 | if (m_poFilterGeomcxx . . $ OGRLayer#m_poFilterGeom. != nullptr) |
| 8648 | { |
| 8649 | // Both are exclusive |
| 8650 | CreateSpatialIndexIfNecessarycxx . . $ OGRGeoPackageTableLayer#CreateSpatialIndexIfNecessary(49f6e7a06ebc5aa8).(); |
| 8651 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 8652 | { |
| 8653 | memset(out_array, 0, sizeof(*out_array)); |
| 8654 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 8655 | } |
| 8656 | } |
| 8657 | |
| 8658 | if (CPLTestBool(CPLGetConfigOption("OGR_GPKG_STREAM_BASE_IMPL", "NO"))) |
| 8659 | { |
| 8660 | return OGRGeoPackageLayercxx . . $ OGRGeoPackageLayer#::GetNextArrowArraycxx . . $ OGRGeoPackageLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).(stream, out_array); |
| 8661 | } |
| 8662 | |
| 8663 | if (m_nIsCompatOfOptimizedGetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_nIsCompatOfOptimizedGetNextArrowArray. == FALSEcxx . . $ `port/cpl_port.h:1180:9`! || |
| 8664 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn. == nullptr || !m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty() || |
| 8665 | m_poFillArrowArraycxx . . $ OGRGeoPackageTableLayer#m_poFillArrowArray. || |
| 8666 | (!m_bGetNextArrowArrayCalledSinceResetReadingcxx . . $ OGRGeoPackageTableLayer#m_bGetNextArrowArrayCalledSinceResetReading. && m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. > 0)) |
| 8667 | { |
| 8668 | return GetNextArrowArrayAsynchronouscxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronous(b1dcf2e4b2dc4bae).(stream, out_array); |
| 8669 | } |
| 8670 | |
| 8671 | // We can use this optimized version only if there is no hole in FID |
| 8672 | // numbering. That is min(fid) == 1 and max(fid) == m_nTotalFeatureCount |
| 8673 | if (m_nIsCompatOfOptimizedGetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_nIsCompatOfOptimizedGetNextArrowArray. < 0) |
| 8674 | { |
| 8675 | m_nIsCompatOfOptimizedGetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_nIsCompatOfOptimizedGetNextArrowArray. = FALSEcxx . . $ `port/cpl_port.h:1180:9`!; |
| 8676 | const auto nTotalFeatureCount = GetTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#GetTotalFeatureCount(a5d9f2bf8849668d).(); |
| 8677 | if (nTotalFeatureCount < 0) |
| 8678 | return GetNextArrowArrayAsynchronouscxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronous(b1dcf2e4b2dc4bae).(stream, out_array); |
| 8679 | { |
| 8680 | char *pszSQL = sqlite3_mprintf("SELECT MAX(\"%w\") FROM \"%w\"", |
| 8681 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 8682 | OGRErr err; |
| 8683 | const auto nMaxFID = SQLGetInteger64cxx . . $ SQLGetInteger64(c8fc3d71eb4a6aab).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, &err); |
| 8684 | sqlite3_free(pszSQL); |
| 8685 | if (nMaxFID != nTotalFeatureCount) |
| 8686 | return GetNextArrowArrayAsynchronouscxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronous(b1dcf2e4b2dc4bae).(stream, out_array); |
| 8687 | } |
| 8688 | { |
| 8689 | char *pszSQL = sqlite3_mprintf("SELECT MIN(\"%w\") FROM \"%w\"", |
| 8690 | m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 8691 | OGRErr err; |
| 8692 | const auto nMinFID = SQLGetInteger64cxx . . $ SQLGetInteger64(c8fc3d71eb4a6aab).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, &err); |
| 8693 | sqlite3_free(pszSQL); |
| 8694 | if (nMinFID != 1) |
| 8695 | return GetNextArrowArrayAsynchronouscxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayAsynchronous(b1dcf2e4b2dc4bae).(stream, out_array); |
| 8696 | } |
| 8697 | m_nIsCompatOfOptimizedGetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_nIsCompatOfOptimizedGetNextArrowArray. = TRUEcxx . . $ `port/cpl_port.h:1184:9`!; |
| 8698 | } |
| 8699 | |
| 8700 | m_bGetNextArrowArrayCalledSinceResetReadingcxx . . $ OGRGeoPackageTableLayer#m_bGetNextArrowArrayCalledSinceResetReading. = true; |
| 8701 | |
| 8702 | // CPLDebug("GPKG", "m_iNextShapeId = " CPL_FRMT_GIB, m_iNextShapeId); |
| 8703 | |
| 8704 | const int nMaxBatchSize = OGRArrowArrayHelpercxx . . $ OGRArrowArrayHelper#::GetMaxFeaturesInBatchcxx . . $ OGRArrowArrayHelper#GetMaxFeaturesInBatch(1a5998c83e261108).( |
| 8705 | m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions.); |
| 8706 | |
| 8707 | // Fetch the answer from a potentially queued asynchronous task |
| 8708 | if (!m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..emptycxx . . $ std/queue#empty(50ce9a9e25b4a850).()) |
| 8709 | { |
| 8710 | const size_t nTasks = m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..sizecxx . . $ std/queue#size(71e6dd9020568ee8).(); |
| 8711 | auto task = stdcxx . . $ std/::move(m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..frontcxx . . $ std/queue#front(d8c1a3bbdff15733).()); |
| 8712 | m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..popcxx . . $ std/queue#pop(49f6e7a06ebc5aa8).(); |
| 8713 | |
| 8714 | // Wait for thread to be ready |
| 8715 | { |
| 8716 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(task->m_oMutexcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oMutex.); |
| 8717 | while (!task->m_bArrayReadycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bArrayReady.) |
| 8718 | { |
| 8719 | task->m_oCVcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oCV..waitcxx . . $ std/condition_variable#wait(f38159257778c065).(oLock); |
| 8720 | } |
| 8721 | task->m_bArrayReadycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bArrayReady. = false; |
| 8722 | } |
| 8723 | if (!task->m_osErrorMsgcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_osErrorMsg..empty()) |
| 8724 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "%s", |
| 8725 | task->m_osErrorMsgcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_osErrorMsg..c_str()); |
| 8726 | |
| 8727 | const auto stopThread = [&task]() |
| 8728 | { |
| 8729 | { |
| 8730 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(task->m_oMutexcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oMutex.); |
| 8731 | task->m_bStopcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bStop. = true; |
| 8732 | task->m_oCVcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 8733 | } |
| 8734 | if (task->m_oThreadcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oThread..joinablecxx . . $ std/thread#joinable(3482b152b9333168).()) |
| 8735 | task->m_oThreadcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oThread..joincxx . . $ std/thread#join(49f6e7a06ebc5aa8).(); |
| 8736 | }; |
| 8737 | |
| 8738 | if (task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId. != m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId.) |
| 8739 | { |
| 8740 | // Should not normally happen, unless the user messes with |
| 8741 | // GetNextFeature() |
| 8742 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 8743 | "Worker thread task has not expected m_iStartShapeId " |
| 8744 | "value. Got " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`! ", expected " CPL_FRMT_GIBcxx . . $ `port/cpl_port.h:257:9`!, |
| 8745 | task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId., m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId.); |
| 8746 | if (task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.->release) |
| 8747 | task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.->release(task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray..get()); |
| 8748 | |
| 8749 | stopThread(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_3#`operator()`(83f5f38750778ac8).); |
| 8750 | } |
| 8751 | else if (task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.->release) |
| 8752 | { |
| 8753 | m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. += task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray.->length; |
| 8754 | |
| 8755 | // Transfer the task ArrowArray to the client array |
| 8756 | memcpy(out_array, task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray..get(), |
| 8757 | sizeof(struct ArrowArray)); |
| 8758 | memset(task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray..get(), 0, sizeof(struct ArrowArray)); |
| 8759 | |
| 8760 | const bool bMemoryLimitReached = [&task]() |
| 8761 | { |
| 8762 | stdcxx . . $ std/::unique_lock oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(task->m_oMutexcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oMutex.); |
| 8763 | return task->m_bMemoryLimitReachedcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bMemoryLimitReached.; |
| 8764 | }(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_4#`operator()`(50ce9a9e25b4a850).); |
| 8765 | |
| 8766 | if (bMemoryLimitReached) |
| 8767 | { |
| 8768 | m_nIsCompatOfOptimizedGetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_nIsCompatOfOptimizedGetNextArrowArray. = false; |
| 8769 | stopThread(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_3#`operator()`(83f5f38750778ac8).); |
| 8770 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 8771 | return 0; |
| 8772 | } |
| 8773 | // Are the records still available for reading beyond the current |
| 8774 | // queued tasks ? If so, recycle this task to read them |
| 8775 | else if (task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId. + |
| 8776 | static_cast<GIntBigcxx . . $ GIntBig#>(nTasks) * nMaxBatchSize <= |
| 8777 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.) |
| 8778 | { |
| 8779 | task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId. += |
| 8780 | static_cast<GIntBigcxx . . $ GIntBig#>(nTasks) * nMaxBatchSize; |
| 8781 | task->m_poLayercxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poLayer.->m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. = task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId.; |
| 8782 | try |
| 8783 | { |
| 8784 | // Wake-up thread with new task |
| 8785 | { |
| 8786 | stdcxx . . $ std/::lock_guard oLockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(task->m_oMutexcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oMutex.); |
| 8787 | task->m_bFetchRowscxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bFetchRows. = true; |
| 8788 | task->m_oCVcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 8789 | } |
| 8790 | m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..pushcxx . . $ std/queue#push(bfe8a576267fe2ec).(stdcxx . . $ std/::move(task)); |
| 8791 | return 0; |
| 8792 | } |
| 8793 | catch (const stdcxx . . $ std/::exception &e) |
| 8794 | { |
| 8795 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 8796 | "Cannot start worker thread: %s", e.what()); |
| 8797 | } |
| 8798 | } |
| 8799 | else |
| 8800 | { |
| 8801 | stopThread(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_3#`operator()`(83f5f38750778ac8).); |
| 8802 | return 0; |
| 8803 | } |
| 8804 | } |
| 8805 | |
| 8806 | stopThread(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_3#`operator()`(83f5f38750778ac8).); |
| 8807 | } |
| 8808 | |
| 8809 | const auto GetThreadsAvailable = []() |
| 8810 | { |
| 8811 | const char *pszMaxThreads = |
| 8812 | CPLGetConfigOption("OGR_GPKG_NUM_THREADS", nullptr); |
| 8813 | if (pszMaxThreads == nullptr) |
| 8814 | return stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(4, CPLGetNumCPUs()); |
| 8815 | else if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(pszMaxThreads, "ALL_CPUS")) |
| 8816 | return CPLGetNumCPUs(); |
| 8817 | else |
| 8818 | return atoicxx . . $ atoi(f5ecf3191ed0cd93).(pszMaxThreads); |
| 8819 | }; |
| 8820 | |
| 8821 | // Start asynchronous tasks to prefetch the next ArrowArray |
| 8822 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetAccesscxx . . $ GDALDataset#GetAccess(104a36ce1815e5a3).() == GA_ReadOnly && |
| 8823 | m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..emptycxx . . $ std/queue#empty(50ce9a9e25b4a850).() && |
| 8824 | m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. + 2 * static_cast<GIntBigcxx . . $ GIntBig#>(nMaxBatchSize) <= |
| 8825 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. && |
| 8826 | sqlite3_threadsafe() != 0 && GetThreadsAvailable(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_5#`operator()`(455f465bc33b4cdf).) >= 2 && |
| 8827 | CPLGetUsablePhysicalRAM() > 1024 * 1024 * 1024) |
| 8828 | { |
| 8829 | const int nMaxTasks = static_cast<int>(stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).<GIntBigcxx . . $ GIntBig#>( |
| 8830 | DIV_ROUND_UPcxx . . $ `gcore/gdal_cpp_functions.h:296:9`!(m_nTotalFeatureCount - nMaxBatchSize - m_iNextShapeId, |
| 8831 | nMaxBatchSize), |
| 8832 | GetThreadsAvailable(cxx . . $ OGRGeoPackageTableLayer#GetNextArrowArray(b1dcf2e4b2dc4bae).$anonymous_type_5#`operator()`(455f465bc33b4cdf).))); |
| 8833 | CPLDebug("GPKG", "Using %d threads", nMaxTasks); |
| 8834 | GDALOpenInfocxx . . $ GDALOpenInfo# oOpenInfocxx . . $ GDALOpenInfo#GDALOpenInfo(5369a9d766ba1673).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDescriptioncxx . . $ GDALMajorObject#GetDescription(a9f41ea0e82d88cf).(), GA_ReadOnly); |
| 8835 | oOpenInfo.papszOpenOptionscxx . . $ GDALOpenInfo#papszOpenOptions. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetOpenOptionscxx . . $ GDALDataset#GetOpenOptions(de5739791ae7584).(); |
| 8836 | oOpenInfo.nOpenFlagscxx . . $ GDALOpenInfo#nOpenFlags. = GDAL_OF_VECTORcxx . . $ `gcore/gdal.h:1130:9`!; |
| 8837 | for (int iTask = 0; iTask < nMaxTasks; ++iTask) |
| 8838 | { |
| 8839 | auto task = stdcxx . . $ std/::make_unique<ArrowArrayPrefetchTaskcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#>(); |
| 8840 | task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId. = |
| 8841 | m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. + |
| 8842 | static_cast<GIntBigcxx . . $ GIntBig#>(iTask + 1) * nMaxBatchSize; |
| 8843 | task->m_poDScxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poDS. = stdcxx . . $ std/::make_unique<GDALGeoPackageDatasetcxx . . $ GDALGeoPackageDataset#>(); |
| 8844 | if (!task->m_poDScxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poDS.->Opencxx . . $ GDALGeoPackageDataset#Open(ee612a953ed30b3).(&oOpenInfo, m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_osFilenameInZipcxx . . $ GDALGeoPackageDataset#m_osFilenameInZip.)) |
| 8845 | { |
| 8846 | break; |
| 8847 | } |
| 8848 | auto poOtherLayer = dynamic_cast<OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer# *>( |
| 8849 | task->m_poDScxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poDS.->GetLayerByNamecxx . . $ GDALDataset#GetLayerByName(5ddf27af0841fa5b).(GetNamecxx . . $ OGRGeoPackageTableLayer#GetName(a9f41ea0e82d88cf).())); |
| 8850 | if (poOtherLayer == nullptr || |
| 8851 | poOtherLayer->GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).()->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).() != |
| 8852 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).()) |
| 8853 | { |
| 8854 | break; |
| 8855 | } |
| 8856 | |
| 8857 | // Install query logging callback |
| 8858 | if (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->pfnQueryLoggerFunccxx . . $ OGRSQLiteBaseDataSource#pfnQueryLoggerFunc.) |
| 8859 | { |
| 8860 | task->m_poDScxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poDS.->SetQueryLoggerFunccxx . . $ OGRSQLiteBaseDataSource#SetQueryLoggerFunc(4f3f55768c6dd3a7).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->pfnQueryLoggerFunccxx . . $ OGRSQLiteBaseDataSource#pfnQueryLoggerFunc., |
| 8861 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->poQueryLoggerArgcxx . . $ OGRSQLiteBaseDataSource#poQueryLoggerArg.); |
| 8862 | } |
| 8863 | |
| 8864 | task->m_poLayercxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poLayer. = poOtherLayer; |
| 8865 | task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray. = stdcxx . . $ std/::make_unique<struct ArrowArray>(); |
| 8866 | memset(task->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray..get(), 0, sizeof(struct ArrowArray)); |
| 8867 | |
| 8868 | poOtherLayer->m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.; |
| 8869 | poOtherLayer->m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions. = |
| 8870 | m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions.; |
| 8871 | OGRLayercxx . . $ OGRLayer# *poOtherLayerAsLayer = poOtherLayer; |
| 8872 | auto poOtherFDefn = poOtherLayerAsLayer->GetLayerDefncxx . . $ OGRLayer#GetLayerDefn(407fccde18759965).(); |
| 8873 | for (int i = 0; i < m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldCountcxx . . $ OGRFeatureDefn#GetGeomFieldCount(455f465bc33b4cdf).(); ++i) |
| 8874 | { |
| 8875 | poOtherFDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(i)->SetIgnoredcxx . . $ OGRGeomFieldDefn#SetIgnored(d4f767463ce0a6b3).( |
| 8876 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(i)->IsIgnoredcxx . . $ OGRGeomFieldDefn#IsIgnored(455f465bc33b4cdf).()); |
| 8877 | } |
| 8878 | for (int i = 0; i < m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldCountcxx . . $ OGRFeatureDefn#GetFieldCount(455f465bc33b4cdf).(); ++i) |
| 8879 | { |
| 8880 | poOtherFDefn->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(i)->SetIgnoredcxx . . $ OGRFieldDefn#SetIgnored(d4f767463ce0a6b3).( |
| 8881 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefncxx . . $ OGRFeatureDefn#GetFieldDefn(2ec36f91b6ceefc7).(i)->IsIgnoredcxx . . $ OGRFieldDefn#IsIgnored(455f465bc33b4cdf).()); |
| 8882 | } |
| 8883 | |
| 8884 | poOtherLayer->m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. = task->m_iStartShapeIdcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_iStartShapeId.; |
| 8885 | |
| 8886 | auto taskPtr = task.get(); |
| 8887 | auto taskRunner = [taskPtr]() |
| 8888 | { |
| 8889 | stdcxx . . $ std/::unique_lock oLockcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(taskPtr->m_oMutexcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oMutex.); |
| 8890 | do |
| 8891 | { |
| 8892 | taskPtr->m_bFetchRowscxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bFetchRows. = false; |
| 8893 | taskPtr->m_poLayercxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_poLayer.->GetNextArrowArrayInternalcxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayInternal(4e923a706d6e3ca0).( |
| 8894 | taskPtr->m_psArrowArraycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_psArrowArray..get(), taskPtr->m_osErrorMsgcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_osErrorMsg., |
| 8895 | taskPtr->m_bMemoryLimitReachedcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bMemoryLimitReached.); |
| 8896 | taskPtr->m_bArrayReadycxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bArrayReady. = true; |
| 8897 | taskPtr->m_oCVcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oCV..notify_onecxx . . $ std/condition_variable#notify_one(ced63f7c635d850d).(); |
| 8898 | if (taskPtr->m_bMemoryLimitReachedcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bMemoryLimitReached.) |
| 8899 | break; |
| 8900 | // cppcheck-suppress knownConditionTrueFalse |
| 8901 | // Coverity apparently is confused by the fact that we |
| 8902 | // use unique_lock here to guard access for m_bStop whereas |
| 8903 | // in other places we use a lock_guard, but there's nothing |
| 8904 | // wrong. |
| 8905 | // coverity[missing_lock:FALSE] |
| 8906 | while (!taskPtr->m_bStopcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bStop. && !taskPtr->m_bFetchRowscxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bFetchRows.) |
| 8907 | { |
| 8908 | taskPtr->m_oCVcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oCV..waitcxx . . $ std/condition_variable#wait(f38159257778c065).(oLock); |
| 8909 | } |
| 8910 | } while (!taskPtr->m_bStopcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bStop.); |
| 8911 | }; |
| 8912 | |
| 8913 | task->m_bFetchRowscxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_bFetchRows. = true; |
| 8914 | try |
| 8915 | { |
| 8916 | task->m_oThreadcxx . . $ OGRGeoPackageTableLayer#ArrowArrayPrefetchTask#m_oThread. =cxx . . $ std/thread#`operator=`(e140d598480f0461). stdcxx . . $ std/::threadcxx . . $ std/thread#(taskRunner); |
| 8917 | } |
| 8918 | catch (const stdcxx . . $ std/::exception &e) |
| 8919 | { |
| 8920 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, |
| 8921 | "Cannot start worker thread: %s", e.what()); |
| 8922 | break; |
| 8923 | } |
| 8924 | m_oQueueArrowArrayPrefetchTaskscxx . . $ OGRGeoPackageTableLayer#m_oQueueArrowArrayPrefetchTasks..pushcxx . . $ std/queue#push(bfe8a576267fe2ec).(stdcxx . . $ std/::move(task)); |
| 8925 | } |
| 8926 | } |
| 8927 | |
| 8928 | stdcxx . . $ std/::string osErrorMsg; |
| 8929 | bool bMemoryLimitReached = false; |
| 8930 | int ret = |
| 8931 | GetNextArrowArrayInternalcxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayInternal(4e923a706d6e3ca0).(out_array, osErrorMsg, bMemoryLimitReached); |
| 8932 | if (!osErrorMsg.empty()) |
| 8933 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "%s", osErrorMsg.c_str()); |
| 8934 | if (bMemoryLimitReached) |
| 8935 | { |
| 8936 | CancelAsyncNextArrowArraycxx . . $ OGRGeoPackageTableLayer#CancelAsyncNextArrowArray(49f6e7a06ebc5aa8).(); |
| 8937 | m_nIsCompatOfOptimizedGetNextArrowArraycxx . . $ OGRGeoPackageTableLayer#m_nIsCompatOfOptimizedGetNextArrowArray. = false; |
| 8938 | } |
| 8939 | return ret; |
| 8940 | } |
| 8941 | |
| 8942 | /************************************************************************/ |
| 8943 | /* GetNextArrowArrayInternal() */ |
| 8944 | /************************************************************************/ |
| 8945 | |
| 8946 | int OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::GetNextArrowArrayInternalcxx . . $ OGRGeoPackageTableLayer#GetNextArrowArrayInternal(4e923a706d6e3ca0).( |
| 8947 | struct ArrowArray *out_array, stdcxx . . $ std/::string &osErrorMsg, |
| 8948 | bool &bMemoryLimitReached) |
| 8949 | { |
| 8950 | bMemoryLimitReached = false; |
| 8951 | memset(out_array, 0, sizeof(*out_array)); |
| 8952 | |
| 8953 | if (m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. >= m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount.) |
| 8954 | { |
| 8955 | return 0; |
| 8956 | } |
| 8957 | |
| 8958 | auto psHelper = stdcxx . . $ std/::make_unique<OGRArrowArrayHelpercxx . . $ OGRArrowArrayHelper#>( |
| 8959 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS., m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn., m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions., out_array); |
| 8960 | if (out_array->release == nullptr) |
| 8961 | { |
| 8962 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 8963 | } |
| 8964 | |
| 8965 | OGRGPKGTableLayerFillArrowArraycxx . . $ OGRGPKGTableLayerFillArrowArray# sFillArrowArray; |
| 8966 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper. = stdcxx . . $ std/::move(psHelper); |
| 8967 | sFillArrowArray.bDateTimeAsStringcxx . . $ OGRGPKGTableLayerFillArrowArray#bDateTimeAsString. = m_aosArrowArrayStreamOptionscxx . . $ OGRLayer#m_aosArrowArrayStreamOptions..FetchBool( |
| 8968 | GAS_OPT_DATETIME_AS_STRINGcxx . . $ GAS_OPT_DATETIME_AS_STRING., false); |
| 8969 | sFillArrowArray.poFeatureDefncxx . . $ OGRGPKGTableLayerFillArrowArray#poFeatureDefn. = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.; |
| 8970 | sFillArrowArray.poLayercxx . . $ OGRGPKGTableLayerFillArrowArray#poLayer. = this; |
| 8971 | sFillArrowArray.hDBcxx . . $ OGRGPKGTableLayerFillArrowArray#hDB. = m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(); |
| 8972 | memset(&sFillArrowArray.brokenDowncxx . . $ OGRGPKGTableLayerFillArrowArray#brokenDown., 0, sizeof(sFillArrowArray.brokenDowncxx . . $ OGRGPKGTableLayerFillArrowArray#brokenDown.)); |
| 8973 | |
| 8974 | sqlite3_create_function( |
| 8975 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "OGR_GPKG_FillArrowArray_INTERNAL", -1, |
| 8976 | SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`! | SQLITE_DETERMINISTICcxx . . $ `<external>/2400532043262193228/sqlite3.h:5985:9`!, &sFillArrowArray, nullptr, |
| 8977 | OGR_GPKG_FillArrowArray_Stepcxx . . $ OGR_GPKG_FillArrowArray_Step(77c4cd3acce4959d)., OGR_GPKG_FillArrowArray_Finalizecxx . . $ OGR_GPKG_FillArrowArray_Finalize(e5276f5e0ac5ec48).); |
| 8978 | |
| 8979 | stdcxx . . $ std/::string osSQL; |
| 8980 | osSQL = "SELECT OGR_GPKG_FillArrowArray_INTERNAL(-1,"; |
| 8981 | int nCountArgs = 1; |
| 8982 | |
| 8983 | osSQL += '"'; |
| 8984 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 8985 | osSQL += '"'; |
| 8986 | ++nCountArgs; |
| 8987 | |
| 8988 | if (!sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField..empty() && |
| 8989 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_mapOGRGeomFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRGeomFieldToArrowField.[0] >= 0) |
| 8990 | { |
| 8991 | osSQL += ','; |
| 8992 | osSQL += '"'; |
| 8993 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(GetGeometryColumncxx . . $ OGRGeoPackageTableLayer#GetGeometryColumn(a9f41ea0e82d88cf).()); |
| 8994 | osSQL += '"'; |
| 8995 | ++nCountArgs; |
| 8996 | } |
| 8997 | const int SQLITE_MAX_FUNCTION_ARG = |
| 8998 | sqlite3_limit(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), SQLITE_LIMIT_FUNCTION_ARGcxx . . $ `<external>/2400532043262193228/sqlite3.h:4415:9`!, -1); |
| 8999 | for (int iField = 0; iField < sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_nFieldCountcxx . . $ OGRArrowArrayHelper#m_nFieldCount.; |
| 9000 | iField++) |
| 9001 | { |
| 9002 | const int iArrowField = |
| 9003 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_mapOGRFieldToArrowFieldcxx . . $ OGRArrowArrayHelper#m_mapOGRFieldToArrowField.[iField]; |
| 9004 | if (iArrowField >= 0) |
| 9005 | { |
| 9006 | if (nCountArgs == SQLITE_MAX_FUNCTION_ARG) |
| 9007 | { |
| 9008 | // We cannot pass more than SQLITE_MAX_FUNCTION_ARG args |
| 9009 | // to a function... So we have to split in several calls... |
| 9010 | osSQL += "), OGR_GPKG_FillArrowArray_INTERNAL("; |
| 9011 | osSQL += CPLSPrintf("%d", iField); |
| 9012 | nCountArgs = 1; |
| 9013 | } |
| 9014 | const OGRFieldDefncxx . . $ OGRFieldDefn# *poFieldDefn = |
| 9015 | m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetFieldDefnUnsafecxx . . $ OGRFeatureDefn#GetFieldDefnUnsafe(2ec36f91b6ceefc7).(iField); |
| 9016 | osSQL += ','; |
| 9017 | osSQL += '"'; |
| 9018 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(poFieldDefn->GetNameRefcxx . . $ OGRFieldDefn#GetNameRef(a9f41ea0e82d88cf).()); |
| 9019 | osSQL += '"'; |
| 9020 | ++nCountArgs; |
| 9021 | } |
| 9022 | } |
| 9023 | osSQL += ") FROM \""; |
| 9024 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 9025 | osSQL += "\" WHERE \""; |
| 9026 | osSQL += SQLEscapeNamecxx . . $ SQLEscapeName(a9d72c988d85d6d8).(m_pszFidColumncxx . . $ OGRGeoPackageLayer#m_pszFidColumn.); |
| 9027 | osSQL += "\" BETWEEN "; |
| 9028 | osSQL += stdcxx . . $ std/::to_string(m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. + 1); |
| 9029 | osSQL += " AND "; |
| 9030 | osSQL += stdcxx . . $ std/::to_string(m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. + |
| 9031 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->m_nMaxBatchSizecxx . . $ OGRArrowArrayHelper#m_nMaxBatchSize.); |
| 9032 | |
| 9033 | // CPLDebug("GPKG", "%s", osSQL.c_str()); |
| 9034 | |
| 9035 | char *pszErrMsg = nullptr; |
| 9036 | if (sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osSQL.c_str(), nullptr, nullptr, |
| 9037 | &pszErrMsg) != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 9038 | { |
| 9039 | if (!sFillArrowArray.bErrorOccurredcxx . . $ OGRGPKGTableLayerFillArrowArray#bErrorOccurred. && |
| 9040 | !sFillArrowArray.bMemoryLimitReachedcxx . . $ OGRGPKGTableLayerFillArrowArray#bMemoryLimitReached.) |
| 9041 | { |
| 9042 | osErrorMsg = pszErrMsg ? pszErrMsg : "unknown error"; |
| 9043 | } |
| 9044 | } |
| 9045 | sqlite3_free(pszErrMsg); |
| 9046 | |
| 9047 | bMemoryLimitReached = sFillArrowArray.bMemoryLimitReachedcxx . . $ OGRGPKGTableLayerFillArrowArray#bMemoryLimitReached.; |
| 9048 | |
| 9049 | // Delete function |
| 9050 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), "OGR_GPKG_FillArrowArray_INTERNAL", |
| 9051 | -1, SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`! | SQLITE_DETERMINISTICcxx . . $ `<external>/2400532043262193228/sqlite3.h:5985:9`!, nullptr, |
| 9052 | nullptr, nullptr, nullptr); |
| 9053 | |
| 9054 | if (sFillArrowArray.bErrorOccurredcxx . . $ OGRGPKGTableLayerFillArrowArray#bErrorOccurred.) |
| 9055 | { |
| 9056 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->ClearArraycxx . . $ OGRArrowArrayHelper#ClearArray(49f6e7a06ebc5aa8).(); |
| 9057 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 9058 | } |
| 9059 | |
| 9060 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->Shrinkcxx . . $ OGRArrowArrayHelper#Shrink(d4f767463ce0a6b3).(sFillArrowArray.nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows.); |
| 9061 | if (sFillArrowArray.nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows. == 0) |
| 9062 | { |
| 9063 | sFillArrowArray.psHelpercxx . . $ OGRGPKGTableLayerFillArrowArray#psHelper.->ClearArraycxx . . $ OGRArrowArrayHelper#ClearArray(49f6e7a06ebc5aa8).(); |
| 9064 | } |
| 9065 | |
| 9066 | m_iNextShapeIdcxx . . $ OGRGeoPackageLayer#m_iNextShapeId. += sFillArrowArray.nCountRowscxx . . $ OGRGPKGTableLayerFillArrowArray#nCountRows.; |
| 9067 | |
| 9068 | return 0; |
| 9069 | } |
| 9070 | |
| 9071 | /************************************************************************/ |
| 9072 | /* OGR_GPKG_GeometryExtent3DAggregate() */ |
| 9073 | /************************************************************************/ |
| 9074 | |
| 9075 | namespacecxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/ |
| 9076 | { |
| 9077 | struct GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext# |
| 9078 | { |
| 9079 | sqlite3 *m_hDBcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_hDB. = nullptr; |
| 9080 | OGREnvelope3D m_oExtent3Dcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_oExtent3D.; |
| 9081 | |
| 9082 | explicit GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#GeometryExtent3DAggregateContext(76baac4849a44ec2).(sqlite3 *hDB) |
| 9083 | : m_hDBcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_hDB.(hDB), m_oExtent3Dcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_oExtent3D.() |
| 9084 | { |
| 9085 | } |
| 9086 | |
| 9087 | GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#GeometryExtent3DAggregateContext(e72cca929ff54586).(const GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext# &) = |
| 9088 | delete; |
| 9089 | GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext# & |
| 9090 | operatorcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#`operator=`(81003542b4cf22ad).=(const GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext# &) = delete; |
| 9091 | }; |
| 9092 | |
| 9093 | } // namespace |
| 9094 | |
| 9095 | static void OGR_GPKG_GeometryExtent3DAggregate_Stepcxx . . $ OGR_GPKG_GeometryExtent3DAggregate_Step(77c4cd3acce4959d).(sqlite3_context *pContext, |
| 9096 | int /*argc*/, |
| 9097 | sqlite3_value **argv) |
| 9098 | { |
| 9099 | const GBytecxx . . $ GByte# *pabyBLOB = |
| 9100 | reinterpret_cast<const GBytecxx . . $ GByte# *>(sqlite3_value_blob(argv[0])); |
| 9101 | |
| 9102 | auto poContext = static_cast<GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext# *>( |
| 9103 | sqlite3_user_data(pContext)); |
| 9104 | |
| 9105 | if (pabyBLOB != nullptr) |
| 9106 | { |
| 9107 | GPkgHeadercxx . . $ GPkgHeader# sHeader; |
| 9108 | if (OGRGeoPackageGetHeadercxx . . $ OGRGeoPackageGetHeader(2e0c5e2af0c6a54b).(pContext, 0, argv, &sHeader, true, true)) |
| 9109 | { |
| 9110 | OGREnvelope3D extent3D; |
| 9111 | extent3D.MinX = sHeader.MinXcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MinX.; |
| 9112 | extent3D.MaxX = sHeader.MaxXcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MaxX.; |
| 9113 | extent3D.MinY = sHeader.MinYcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MinY.; |
| 9114 | extent3D.MaxY = sHeader.MaxYcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MaxY.; |
| 9115 | extent3D.MinZ = sHeader.MinZcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MinZ.; |
| 9116 | extent3D.MaxZ = sHeader.MaxZcxx . . $ $anonymous_type_2b740b2c8f9610bf_0#MaxZ.; |
| 9117 | poContext->m_oExtent3Dcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_oExtent3D..Merge(extent3D); |
| 9118 | } |
| 9119 | else if (!sHeader.bEmptycxx . . $ $anonymous_type_2b740b2c8f9610bf_0#bEmpty.) |
| 9120 | { |
| 9121 | // Try also spatialite geometry blobs |
| 9122 | const int nBLOBLen = sqlite3_value_bytes(argv[0]); |
| 9123 | OGRGeometrycxx . . $ OGRGeometry# *poGeom = nullptr; |
| 9124 | if (OGRSQLiteImportSpatiaLiteGeometrycxx . . $ OGRSQLiteImportSpatiaLiteGeometry(5f689a382454ef53).(pabyBLOB, nBLOBLen, |
| 9125 | &poGeom) == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! && |
| 9126 | poGeom && !poGeom->IsEmptycxx . . $ OGRGeometry#IsEmpty(455f465bc33b4cdf).()) |
| 9127 | { |
| 9128 | OGREnvelope3D extent3D; |
| 9129 | poGeom->getEnvelopecxx . . $ OGRGeometry#getEnvelope(c0c7dd073248fd4f).(&extent3D); |
| 9130 | poContext->m_oExtent3Dcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_oExtent3D..Merge(extent3D); |
| 9131 | } |
| 9132 | delete poGeom; |
| 9133 | } |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | static void OGR_GPKG_GeometryExtent3DAggregate_Finalizecxx . . $ OGR_GPKG_GeometryExtent3DAggregate_Finalize(e5276f5e0ac5ec48).(sqlite3_context *) |
| 9138 | { |
| 9139 | } |
| 9140 | |
| 9141 | /************************************************************************/ |
| 9142 | /* IGetExtent3D */ |
| 9143 | /************************************************************************/ |
| 9144 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::IGetExtent3Dcxx . . $ OGRGeoPackageTableLayer#IGetExtent3D(308398dff6ed51e0).(int iGeomField, |
| 9145 | OGREnvelope3D *psExtent3D, |
| 9146 | bool bForce) |
| 9147 | { |
| 9148 | |
| 9149 | const OGRFeatureDefncxx . . $ OGRFeatureDefn# *poDefn = GetLayerDefncxx . . $ OGRGeoPackageTableLayer#GetLayerDefn(448b209f43d15bcc).(); |
| 9150 | |
| 9151 | /* -------------------------------------------------------------------- */ |
| 9152 | /* Deferred actions, reset state. */ |
| 9153 | /* -------------------------------------------------------------------- */ |
| 9154 | RunDeferredCreationIfNecessarycxx . . $ OGRGeoPackageTableLayer#RunDeferredCreationIfNecessary(b126dc7c1de90089).(); |
| 9155 | if (!RunDeferredSpatialIndexUpdatecxx . . $ OGRGeoPackageTableLayer#RunDeferredSpatialIndexUpdate(c9857a73d68e59ba).()) |
| 9156 | { |
| 9157 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 9158 | } |
| 9159 | |
| 9160 | if (m_nZFlagcxx . . $ OGRGeoPackageTableLayer#m_nZFlag. == 0 && m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty()) |
| 9161 | { |
| 9162 | // If the layer doesn't contain any 3D geometry and no filter is set, |
| 9163 | // we can fallback to the fast 2D GetExtent() |
| 9164 | const OGRErr retVal{GetExtentcxx . . $ OGRLayer#GetExtent(ee9c866093418aa0).(iGeomField, psExtent3D, bForce)}; |
| 9165 | psExtent3D->MinZ = stdcxx . . $ std/::numeric_limits<double>::infinity(); |
| 9166 | psExtent3D->MaxZ = -stdcxx . . $ std/::numeric_limits<double>::infinity(); |
| 9167 | return retVal; |
| 9168 | } |
| 9169 | else |
| 9170 | { |
| 9171 | *psExtent3D = OGREnvelope3D(); |
| 9172 | } |
| 9173 | |
| 9174 | // For internal use only |
| 9175 | |
| 9176 | GeometryExtent3DAggregateContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext# sContextcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#GeometryExtent3DAggregateContext(76baac4849a44ec2).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB.); |
| 9177 | |
| 9178 | CPLString osFuncName; |
| 9179 | osFuncName.Printf("OGR_GPKG_GeometryExtent3DAggregate_INTERNAL_%p", |
| 9180 | &sContext); |
| 9181 | |
| 9182 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., osFuncName.c_str(), 1, SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`!, |
| 9183 | &sContext, nullptr, |
| 9184 | OGR_GPKG_GeometryExtent3DAggregate_Stepcxx . . $ OGR_GPKG_GeometryExtent3DAggregate_Step(77c4cd3acce4959d)., |
| 9185 | OGR_GPKG_GeometryExtent3DAggregate_Finalizecxx . . $ OGR_GPKG_GeometryExtent3DAggregate_Finalize(e5276f5e0ac5ec48).); |
| 9186 | |
| 9187 | char *pszSQL = sqlite3_mprintf( |
| 9188 | "SELECT %s(\"%w\") FROM \"%w\"%s", osFuncName.c_str(), |
| 9189 | poDefn->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(801b12ff899738d8).(iGeomField)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(), m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., |
| 9190 | m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter..empty() ? "" : (" WHERE " + m_soFiltercxx . . $ OGRGeoPackageTableLayer#m_soFilter.).c_str()); |
| 9191 | char *pszErrMsg = nullptr; |
| 9192 | const int rc = |
| 9193 | sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, nullptr, &(pszErrMsg)); |
| 9194 | |
| 9195 | // Delete function |
| 9196 | sqlite3_create_function(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), osFuncName.c_str(), 1, SQLITE_UTF8cxx . . $ `<external>/2400532043262193228/sqlite3.h:5878:9`!, |
| 9197 | nullptr, nullptr, nullptr, nullptr); |
| 9198 | |
| 9199 | if (rc != SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!) |
| 9200 | { |
| 9201 | if (rc != SQLITE_INTERRUPTcxx . . $ `<external>/2400532043262193228/sqlite3.h:459:9`!) |
| 9202 | { |
| 9203 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "sqlite3_exec(%s) failed: %s", |
| 9204 | pszSQL, pszErrMsg); |
| 9205 | } |
| 9206 | sqlite3_free(pszErrMsg); |
| 9207 | sqlite3_free(pszSQL); |
| 9208 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 9209 | } |
| 9210 | sqlite3_free(pszErrMsg); |
| 9211 | sqlite3_free(pszSQL); |
| 9212 | |
| 9213 | *psExtent3D = sContext.m_oExtent3Dcxx . . $ `$anonymous_namespace_ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp`/GeometryExtent3DAggregateContext#m_oExtent3D.; |
| 9214 | |
| 9215 | return OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 9216 | } |
| 9217 | |
| 9218 | /************************************************************************/ |
| 9219 | /* Truncate() */ |
| 9220 | /************************************************************************/ |
| 9221 | |
| 9222 | /** Implements "DELETE FROM {table_name}" in an optimized way. |
| 9223 | * |
| 9224 | * Disable triggers if we detect that the only triggers on the table are ones |
| 9225 | * under our control (i.e. the ones for the gpkg_ogr_contents table and the |
| 9226 | * ones updating the RTree) |
| 9227 | * And even if we cannot disable triggers, truncate the RTree before the main |
| 9228 | * table, as this dramatically speeds up truncating the main table. |
| 9229 | */ |
| 9230 | OGRErr OGRGeoPackageTableLayercxx . . $ OGRGeoPackageTableLayer#::Truncatecxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).() |
| 9231 | { |
| 9232 | if (!m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetUpdatecxx . . $ OGRSQLiteBaseDataSource#GetUpdate(50ce9a9e25b4a850).()) |
| 9233 | { |
| 9234 | CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, UNSUPPORTED_OP_READ_ONLYcxx . . $ UNSUPPORTED_OP_READ_ONLY., |
| 9235 | "Truncate"); |
| 9236 | return OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 9237 | } |
| 9238 | |
| 9239 | ResetReadingcxx . . $ OGRGeoPackageTableLayer#ResetReading(49f6e7a06ebc5aa8).(); |
| 9240 | SyncToDiskcxx . . $ OGRGeoPackageTableLayer#SyncToDisk(b126dc7c1de90089).(); |
| 9241 | |
| 9242 | bool bOK = (m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftStartTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftStartTransaction(b126dc7c1de90089).() == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!); |
| 9243 | |
| 9244 | struct ReenableTriggerscxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers# |
| 9245 | { |
| 9246 | sqlite3 *m_hDBcxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#m_hDB. = nullptr; |
| 9247 | |
| 9248 | explicit ReenableTriggerscxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#ReenableTriggers(76baac4849a44ec2).(sqlite3 *hDB) : m_hDBcxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#m_hDB.(hDB) |
| 9249 | { |
| 9250 | } |
| 9251 | |
| 9252 | ~cxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#`~ReenableTriggers`(ced63f7c635d850d).ReenableTriggerscxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#() |
| 9253 | { |
| 9254 | sqlite3_db_config(m_hDBcxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#m_hDB., SQLITE_DBCONFIG_ENABLE_TRIGGERcxx . . $ `<external>/2400532043262193228/sqlite3.h:2702:9`!, 1, |
| 9255 | nullptr); |
| 9256 | } |
| 9257 | CPL_DISALLOW_COPY_ASSIGNcxx . . $ `port/cpl_port.h:1101:9`!(ReenableTriggers) |
| 9258 | }; |
| 9259 | |
| 9260 | // to keep in top level scope! |
| 9261 | stdcxx . . $ std/::unique_ptr<ReenableTriggerscxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#> reenableTriggers; |
| 9262 | |
| 9263 | // Temporarily disable triggers for greater speed if we detect that the |
| 9264 | // only triggers on the table are the RTree ones and the ones for the |
| 9265 | // gpkg_ogr_contents table |
| 9266 | if (bOK && m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable.) |
| 9267 | { |
| 9268 | char *pszSQL = sqlite3_mprintf( |
| 9269 | "SELECT COUNT(*) FROM sqlite_master WHERE type = 'trigger' " |
| 9270 | "AND tbl_name = '%q' " |
| 9271 | "AND name NOT IN ('trigger_insert_feature_count_%q'," |
| 9272 | "'trigger_delete_feature_count_%q') " |
| 9273 | "AND name NOT LIKE 'rtree_%q_%%'", |
| 9274 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 9275 | OGRErr eErr = OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!; |
| 9276 | if (SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, &eErr) == 0 && |
| 9277 | eErr == OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`!) |
| 9278 | { |
| 9279 | int nEnableTriggerOldVal = -1; |
| 9280 | sqlite3_db_config(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), SQLITE_DBCONFIG_ENABLE_TRIGGERcxx . . $ `<external>/2400532043262193228/sqlite3.h:2702:9`!, |
| 9281 | -1, &nEnableTriggerOldVal); |
| 9282 | if (nEnableTriggerOldVal == 1) |
| 9283 | { |
| 9284 | int nNewVal = -1; |
| 9285 | sqlite3_db_config(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), |
| 9286 | SQLITE_DBCONFIG_ENABLE_TRIGGERcxx . . $ `<external>/2400532043262193228/sqlite3.h:2702:9`!, 0, &nNewVal); |
| 9287 | if (nNewVal == 0) |
| 9288 | { |
| 9289 | CPLDebugOnlycxx . . $ `port/cpl_error.h:335:9`!("GPKG", |
| 9290 | "Disabling triggers during truncation of %s", |
| 9291 | m_pszTableName); |
| 9292 | reenableTriggers = |
| 9293 | stdcxx . . $ std/::make_unique<ReenableTriggerscxx . . $ OGRGeoPackageTableLayer#Truncate(b126dc7c1de90089).ReenableTriggers#>(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).()); |
| 9294 | CPL_IGNORE_RET_VAL(reenableTriggers); // to please cppcheck |
| 9295 | } |
| 9296 | } |
| 9297 | } |
| 9298 | sqlite3_free(pszSQL); |
| 9299 | } |
| 9300 | |
| 9301 | char *pszErrMsg = nullptr; |
| 9302 | if (bOK && m_bIsTablecxx . . $ OGRGeoPackageTableLayer#m_bIsTable. && HasSpatialIndexcxx . . $ OGRGeoPackageTableLayer#HasSpatialIndex(50ce9a9e25b4a850).()) |
| 9303 | { |
| 9304 | // Manually clean the 3 tables that are used by the RTree: |
| 9305 | // - rtree_{tablename}_{geom}_node: all rows, but nodeno = 1 for which |
| 9306 | // we reset the 'data' field to a zero blob of the same size |
| 9307 | // - rtree_{tablename}_{geom}_parent: all rows |
| 9308 | // - rtree_{tablename}_{geom}_rowid: all rows |
| 9309 | |
| 9310 | const char *pszT = m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.; |
| 9311 | const char *pszC = m_poFeatureDefncxx . . $ OGRGeoPackageLayer#m_poFeatureDefn.->GetGeomFieldDefncxx . . $ OGRFeatureDefn#GetGeomFieldDefn(39768c424f32bab2).(0)->GetNameRefcxx . . $ OGRGeomFieldDefn#GetNameRef(a9f41ea0e82d88cf).(); |
| 9312 | |
| 9313 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. = "rtree_"; |
| 9314 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszT; |
| 9315 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += "_"; |
| 9316 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName. += pszC; |
| 9317 | |
| 9318 | { |
| 9319 | char *pszSQL = |
| 9320 | sqlite3_mprintf("DELETE FROM \"%w_node\" WHERE nodeno > 1;" |
| 9321 | "DELETE FROM \"%w_parent\"; " |
| 9322 | "DELETE FROM \"%w_rowid\"", |
| 9323 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), |
| 9324 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 9325 | bOK = sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, nullptr, |
| 9326 | &pszErrMsg) == SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!; |
| 9327 | sqlite3_free(pszSQL); |
| 9328 | } |
| 9329 | |
| 9330 | if (bOK) |
| 9331 | { |
| 9332 | char *pszSQL = sqlite3_mprintf( |
| 9333 | "SELECT length(data) FROM \"%w_node\" WHERE nodeno = 1", |
| 9334 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str()); |
| 9335 | const int nBlobSize = |
| 9336 | SQLGetIntegercxx . . $ SQLGetInteger(763488aa9147b4aa).(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->GetDBcxx . . $ OGRSQLiteBaseDataSource#GetDB(b8c523d2508df5d6).(), pszSQL, nullptr); |
| 9337 | sqlite3_free(pszSQL); |
| 9338 | |
| 9339 | pszSQL = sqlite3_mprintf( |
| 9340 | "UPDATE \"%w_node\" SET data = zeroblob(%d) WHERE nodeno = 1", |
| 9341 | m_osRTreeNamecxx . . $ OGRGeoPackageTableLayer#m_osRTreeName..c_str(), nBlobSize); |
| 9342 | bOK = sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, nullptr, |
| 9343 | &pszErrMsg) == SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!; |
| 9344 | sqlite3_free(pszSQL); |
| 9345 | } |
| 9346 | } |
| 9347 | |
| 9348 | if (bOK) |
| 9349 | { |
| 9350 | // Truncate main table |
| 9351 | char *pszSQL = sqlite3_mprintf("DELETE FROM \"%w\"", m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 9352 | bOK = sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, nullptr, &pszErrMsg) == |
| 9353 | SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!; |
| 9354 | sqlite3_free(pszSQL); |
| 9355 | } |
| 9356 | |
| 9357 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 9358 | // Reset feature count |
| 9359 | if (bOK && m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->m_bHasGPKGOGRContentscxx . . $ GDALGeoPackageDataset#m_bHasGPKGOGRContents.) |
| 9360 | { |
| 9361 | char *pszSQL = |
| 9362 | sqlite3_mprintf("UPDATE gpkg_ogr_contents SET feature_count = 0 " |
| 9363 | "WHERE lower(table_name) = lower('%q')", |
| 9364 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName.); |
| 9365 | bOK = sqlite3_exec(m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->hDBcxx . . $ OGRSQLiteBaseDataSource#hDB., pszSQL, nullptr, nullptr, &pszErrMsg) == |
| 9366 | SQLITE_OKcxx . . $ `<external>/2400532043262193228/sqlite3.h:449:9`!; |
| 9367 | sqlite3_free(pszSQL); |
| 9368 | } |
| 9369 | |
| 9370 | if (bOK) |
| 9371 | { |
| 9372 | m_nTotalFeatureCountcxx . . $ OGRGeoPackageTableLayer#m_nTotalFeatureCount. = 0; |
| 9373 | } |
| 9374 | #endif |
| 9375 | |
| 9376 | if (bOK) |
| 9377 | { |
| 9378 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftCommitTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftCommitTransaction(b126dc7c1de90089).(); |
| 9379 | } |
| 9380 | else |
| 9381 | { |
| 9382 | m_poDScxx . . $ OGRGeoPackageLayer#m_poDS.->SoftRollbackTransactioncxx . . $ OGRSQLiteBaseDataSource#SoftRollbackTransaction(b126dc7c1de90089).(); |
| 9383 | #ifdef ENABLE_GPKG_OGR_CONTENTScxx . . $ `ogr/ogrsf_frmts/gpkg/ogr_geopackage.h:38:9`! |
| 9384 | DisableFeatureCountcxx . . $ OGRGeoPackageTableLayer#DisableFeatureCount(49f6e7a06ebc5aa8).(); |
| 9385 | #endif |
| 9386 | CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Truncate(%s) failed: %s", |
| 9387 | m_pszTableNamecxx . . $ OGRGeoPackageTableLayer#m_pszTableName., pszErrMsg ? pszErrMsg : "(unknown reason)"); |
| 9388 | } |
| 9389 | sqlite3_free(pszErrMsg); |
| 9390 | |
| 9391 | return bOK ? OGRERR_NONEcxx . . $ `ogr/ogr_core.h:390:9`! : OGRERR_FAILUREcxx . . $ `ogr/ogr_core.h:396:9`!; |
| 9392 | } |