Changeset 23945
- Timestamp:
- Feb 11, 2012, 6:33:34 AM (13 years ago)
- Location:
- trunk/gdal/ogr/ogrsf_frmts/sqlite
- Files:
-
- 3 edited
-
ogr_sqlite.h (modified) (4 diffs)
-
ogrsqlitedatasource.cpp (modified) (1 diff)
-
ogrsqliteviewlayer.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/gdal/ogr/ogrsf_frmts/sqlite/ogr_sqlite.h
r23944 r23945 358 358 int bHasCheckedSpatialIndexTable; 359 359 360 char *pszViewName; 360 361 char *pszEscapedTableName; 361 362 char *pszEscapedUnderlyingTableName; 362 363 364 int bLayerDefnError; 365 363 366 CPLString osUnderlyingTableName; 364 367 CPLString osUnderlyingGeometryColumn; … … 368 371 OGRErr ResetStatement(); 369 372 373 CPLErr EstablishFeatureDefn(); 374 370 375 public: 371 376 OGRSQLiteViewLayer( OGRSQLiteDataSource * ); 372 377 ~OGRSQLiteViewLayer(); 378 379 virtual const char* GetName() { return pszViewName; } 380 virtual OGRwkbGeometryType GetGeomType(); 373 381 374 382 CPLErr Initialize( const char *pszViewName, … … 379 387 int bSpatialiteLoaded); 380 388 389 virtual OGRFeatureDefn *GetLayerDefn(); 390 int HasLayerDefnError() { GetLayerDefn(); return bLayerDefnError; } 391 392 virtual OGRFeature *GetNextFeature(); 381 393 virtual int GetFeatureCount( int ); 382 394 … … 387 399 388 400 virtual int TestCapability( const char * ); 401 402 virtual OGRSpatialReference *GetSpatialRef(); 389 403 390 404 virtual CPLString GetSpatialWhere(OGRGeometry* poFilterGeom); -
trunk/gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp
r23736 r23945 1089 1089 } 1090 1090 1091 /* If not a slow file, then establish layer definition immediately */1092 /* to check if the table is valid */1093 /* Note: we could do differed table layer definition for all files */1094 /* but it is only worth doing for slow files. */1095 if ( strncmp(pszName, "/vsicurl/", 9) != 0 &&1096 poLayer->HasLayerDefnError() )1097 {1098 delete poLayer;1099 return FALSE;1100 }1101 1102 1091 poLayer->SetSpatialite2D ( bForce2D ); 1103 1092 -
trunk/gdal/ogr/ogrsf_frmts/sqlite/ogrsqliteviewlayer.cpp
r23944 r23945 49 49 50 50 poFeatureDefn = NULL; 51 pszViewName = NULL; 51 52 pszEscapedTableName = NULL; 52 53 pszEscapedUnderlyingTableName = NULL; 53 54 54 55 bHasCheckedSpatialIndexTable = FALSE; 56 57 bLayerDefnError = FALSE; 55 58 } 56 59 … … 63 66 { 64 67 ClearStatement(); 68 CPLFree(pszViewName); 65 69 CPLFree(pszEscapedTableName); 66 70 CPLFree(pszEscapedUnderlyingTableName); … … 79 83 80 84 { 85 this->pszViewName = CPLStrdup(pszViewName); 86 87 osGeomColumn = pszViewGeometry; 88 eGeomFormat = OSGF_SpatiaLite; 89 90 CPLFree( pszFIDColumn ); 91 pszFIDColumn = CPLStrdup( pszViewRowid ); 92 93 osUnderlyingTableName = pszUnderlyingTableName; 94 osUnderlyingGeometryColumn = pszUnderlyingGeometryColumn; 95 96 this->bSpatialiteLoaded = bSpatialiteLoaded; 97 //this->bHasM = bHasM; 98 99 pszEscapedTableName = CPLStrdup(OGRSQLiteEscape(pszViewName)); 100 pszEscapedUnderlyingTableName = CPLStrdup(OGRSQLiteEscape(pszUnderlyingTableName)); 101 102 return CE_None; 103 } 104 105 /************************************************************************/ 106 /* GetLayerDefn() */ 107 /************************************************************************/ 108 109 OGRFeatureDefn* OGRSQLiteViewLayer::GetLayerDefn() 110 { 111 if (poFeatureDefn) 112 return poFeatureDefn; 113 114 EstablishFeatureDefn(); 115 116 if (poFeatureDefn == NULL) 117 { 118 bLayerDefnError = TRUE; 119 120 poFeatureDefn = new OGRFeatureDefn( pszViewName ); 121 poFeatureDefn->Reference(); 122 } 123 124 return poFeatureDefn; 125 } 126 127 /************************************************************************/ 128 /* GetGeomType() */ 129 /************************************************************************/ 130 131 OGRwkbGeometryType OGRSQLiteViewLayer::GetGeomType() 132 { 133 if (poFeatureDefn) 134 return poFeatureDefn->GetGeomType(); 135 136 OGRSQLiteLayer* poUnderlyingLayer = (OGRSQLiteLayer*) poDS->GetLayerByName(osUnderlyingTableName); 137 if (poUnderlyingLayer) 138 return poUnderlyingLayer->GetGeomType(); 139 140 return wkbUnknown; 141 } 142 143 /************************************************************************/ 144 /* EstablishFeatureDefn() */ 145 /************************************************************************/ 146 147 CPLErr OGRSQLiteViewLayer::EstablishFeatureDefn() 148 { 81 149 int rc; 82 150 sqlite3 *hDB = poDS->GetDB(); 83 84 OGRSQLiteLayer* poUnderlyingLayer = (OGRSQLiteLayer*) poDS->GetLayerByName(pszUnderlyingTableName); 151 sqlite3_stmt *hColStmt = NULL; 152 const char *pszSQL; 153 154 OGRSQLiteLayer* poUnderlyingLayer = (OGRSQLiteLayer*) poDS->GetLayerByName(osUnderlyingTableName); 85 155 if (poUnderlyingLayer == NULL) 86 156 { 87 157 CPLError(CE_Failure, CPLE_AppDefined, 88 158 "Cannot find underlying layer %s for view %s", 89 pszUnderlyingTableName, pszViewName);159 osUnderlyingTableName.c_str(), pszViewName); 90 160 return CE_Failure; 91 161 } … … 94 164 CPLError(CE_Failure, CPLE_AppDefined, 95 165 "Underlying layer %s for view %s is not a regular table", 96 pszUnderlyingTableName, pszViewName);166 osUnderlyingTableName.c_str(), pszViewName); 97 167 return CE_Failure; 98 168 } … … 100 170 const char* pszRealUnderlyingGeometryColumn = poUnderlyingLayer->GetGeometryColumn(); 101 171 if ( pszRealUnderlyingGeometryColumn == NULL || 102 !EQUAL(pszRealUnderlyingGeometryColumn, pszUnderlyingGeometryColumn) )172 !EQUAL(pszRealUnderlyingGeometryColumn, osUnderlyingGeometryColumn.c_str()) ) 103 173 { 104 174 CPLError(CE_Failure, CPLE_AppDefined, 105 175 "Underlying layer %s for view %s has not expected geometry column name (%s instead of %s)", 106 pszUnderlyingTableName, pszViewName,176 osUnderlyingTableName.c_str(), pszViewName, 107 177 pszRealUnderlyingGeometryColumn ? pszRealUnderlyingGeometryColumn : "(null)", 108 pszUnderlyingGeometryColumn);178 osUnderlyingGeometryColumn.c_str()); 109 179 return CE_Failure; 110 180 } 111 112 osGeomColumn = pszViewGeometry;113 eGeomFormat = OSGF_SpatiaLite;114 115 CPLFree( pszFIDColumn );116 pszFIDColumn = CPLStrdup( pszViewRowid );117 118 osUnderlyingTableName = pszUnderlyingTableName;119 osUnderlyingGeometryColumn = pszUnderlyingGeometryColumn;120 181 121 182 poSRS = poUnderlyingLayer->GetSpatialRef(); … … 124 185 125 186 this->bHasSpatialIndex = poUnderlyingLayer->HasSpatialIndex(); 126 this->bSpatialiteLoaded = bSpatialiteLoaded;127 //this->bHasM = bHasM;128 129 pszEscapedTableName = CPLStrdup(OGRSQLiteEscape(pszViewName));130 pszEscapedUnderlyingTableName = CPLStrdup(OGRSQLiteEscape(pszUnderlyingTableName));131 132 sqlite3_stmt *hColStmt = NULL;133 const char *pszSQL;134 187 135 188 /* -------------------------------------------------------------------- */ … … 209 262 } 210 263 264 /************************************************************************/ 265 /* GetSpatialRef() */ 266 /************************************************************************/ 267 268 OGRSpatialReference *OGRSQLiteViewLayer::GetSpatialRef() 269 270 { 271 if (HasLayerDefnError()) 272 return NULL; 273 274 return poSRS; 275 } 276 277 /************************************************************************/ 278 /* GetNextFeature() */ 279 /************************************************************************/ 280 281 OGRFeature *OGRSQLiteViewLayer::GetNextFeature() 282 283 { 284 if (HasLayerDefnError()) 285 return NULL; 286 287 return OGRSQLiteLayer::GetNextFeature(); 288 } 211 289 212 290 /************************************************************************/ … … 217 295 218 296 { 297 if (HasLayerDefnError()) 298 return NULL; 299 219 300 /* -------------------------------------------------------------------- */ 220 301 /* If we don't have an explicit FID column, just read through */ … … 305 386 { 306 387 CPLString osSpatialWHERE; 388 389 if (HasLayerDefnError()) 390 return ""; 307 391 308 392 if( poFilterGeom != NULL && bHasSpatialIndex ) … … 422 506 423 507 { 508 if (HasLayerDefnError()) 509 return FALSE; 510 424 511 if (EQUAL(pszCap,OLCFastFeatureCount)) 425 512 return m_poFilterGeom == NULL || osGeomColumn.size() == 0 || … … 445 532 446 533 { 534 if (HasLayerDefnError()) 535 return 0; 536 447 537 if( !TestCapability(OLCFastFeatureCount) ) 448 538 return OGRSQLiteLayer::GetFeatureCount( bForce );
Note:
See TracChangeset
for help on using the changeset viewer.
