diff --git a/gdal/ogr/ogrsf_frmts/nas/nashandler.cpp b/gdal/ogr/ogrsf_frmts/nas/nashandler.cpp index 9b044b04460d..1093580f0b5f 100644 --- a/gdal/ogr/ogrsf_frmts/nas/nashandler.cpp +++ b/gdal/ogr/ogrsf_frmts/nas/nashandler.cpp @@ -456,7 +456,7 @@ void NASHandler::endElement(const XMLCh* const uri, { int iId = poState->m_poFeature->GetClass()->GetPropertyIndex( "gml_id" ); const GMLProperty *poIdProp = poState->m_poFeature->GetProperty(iId); -#if DEBUG_VERBOSE +#ifdef DEBUG_VERBOSE char *pszOldGeom = CPLSerializeXMLTree( poState->m_poFeature->GetGeometryList()[0] ); CPLDebug("NAS", "Overwriting other geometry (%s; replace:%s; with:%s)", diff --git a/gdal/ogr/ogrsf_frmts/nas/nasreader.cpp b/gdal/ogr/ogrsf_frmts/nas/nasreader.cpp index ee7d8732a025..d1a60fb07411 100644 --- a/gdal/ogr/ogrsf_frmts/nas/nasreader.cpp +++ b/gdal/ogr/ogrsf_frmts/nas/nasreader.cpp @@ -625,21 +625,6 @@ void NASReader::SetFeaturePropertyDirectly( const char *pszElement, } return; } -#if 0 - else if( strcmp(poClass->GetProperty(iProperty)->GetName(),"signaturnummer") == 0 || - strcmp(poClass->GetProperty(iProperty)->GetName(),"anlass") == 0 ) - { - if( isalpha( pszValue[0] ) && isalpha( pszValue[1] ) && isdigit( pszValue[2] ) ) - { - poFeature->SetPropertyDirectly( iProperty, CPLStrdup( pszValue+2 ) ); -#ifdef DEBUG_VERBOSE - CPLDebug( "NAS", "Skipping two letter prefix of '%s'", pszValue ); -#endif - CPLFree(pszValue); - return; - } - } -#endif else if( strcmp(poClass->GetProperty(iProperty)->GetName(),"kartendarstellung") == 0 || strcmp(poClass->GetProperty(iProperty)->GetName(),"rechtsbehelfsverfahren") == 0 ) { diff --git a/gdal/ogr/ogrsf_frmts/oci/ogr_oci.h b/gdal/ogr/ogrsf_frmts/oci/ogr_oci.h index 96d52f555db1..8c6335790925 100644 --- a/gdal/ogr/ogrsf_frmts/oci/ogr_oci.h +++ b/gdal/ogr/ogrsf_frmts/oci/ogr_oci.h @@ -464,6 +464,8 @@ class OGROCITableLayer : public OGROCIWritableLayer // following methods are not base class overrides int IsValid() { return bValidTable; } + + int GetMaxFID(); }; /************************************************************************/ @@ -516,6 +518,7 @@ class OGROCIDataSource : public OGRDataSource const char *GetName() { return pszName; } int GetLayerCount() { return nLayers; } OGRLayer *GetLayer( int ); + OGRLayer *GetLayerByName(const char * pszName); virtual OGRErr DeleteLayer(int); virtual OGRLayer *CreateLayer( const char *, diff --git a/gdal/ogr/ogrsf_frmts/oci/ogrocidatasource.cpp b/gdal/ogr/ogrsf_frmts/oci/ogrocidatasource.cpp index fd67b3eb2b92..64c275b1a263 100644 --- a/gdal/ogr/ogrsf_frmts/oci/ogrocidatasource.cpp +++ b/gdal/ogr/ogrsf_frmts/oci/ogrocidatasource.cpp @@ -419,7 +419,7 @@ void OGROCIDataSource::DeleteLayer( const char *pszLayerName ) if( iLayer == nLayers ) { CPLDebug( "OCI", "DeleteLayer: %s not found in layer list." \ - " Layer * not* deleted.", pszLayerName ); + " Layer *not* deleted.", pszLayerName ); return; } @@ -964,3 +964,49 @@ int OGROCIDataSource::FetchSRSId( OGRSpatialReference * poSRS ) else return nSRSId; } + + +/************************************************************************/ +/* GetLayerByName() */ +/************************************************************************/ + +OGRLayer *OGROCIDataSource::GetLayerByName( const char *pszName ) + +{ + OGROCILayer *poLayer; + int i, count; + + if ( !pszName ) + return NULL; + + count = GetLayerCount(); + + /* first a case sensitive check */ + for( i = 0; i < count; i++ ) + { + poLayer = papoLayers[i]; + + if( strcmp( pszName, poLayer->GetName() ) == 0 ) + { + return poLayer; + } + } + + char *pszSafeLayerName = CPLStrdup( pszName ); + poSession->CleanName( pszSafeLayerName ); + + /* then case insensitive and laundered */ + for( i = 0; i < count; i++ ) + { + poLayer = papoLayers[i]; + + if( EQUAL( pszSafeLayerName, poLayer->GetName() ) ) + { + break; + } + } + + CPLFree( pszSafeLayerName ); + + return i < count ? poLayer : NULL; +} diff --git a/gdal/ogr/ogrsf_frmts/oci/ogrocitablelayer.cpp b/gdal/ogr/ogrsf_frmts/oci/ogrocitablelayer.cpp index 8dbbb8a4f34f..4b6282532fd6 100644 --- a/gdal/ogr/ogrsf_frmts/oci/ogrocitablelayer.cpp +++ b/gdal/ogr/ogrsf_frmts/oci/ogrocitablelayer.cpp @@ -59,7 +59,7 @@ OGROCITableLayer::OGROCITableLayer( OGROCIDataSource *poDSIn, bNewLayer = bNewLayerIn; iNextShapeId = 0; - iNextFIDToWrite = 1; + iNextFIDToWrite = -1; bValidTable = FALSE; if( bNewLayerIn ) @@ -154,6 +154,9 @@ OGRFeatureDefn *OGROCITableLayer::ReadTableDefinition( const char * pszTable ) poDefn->Reference(); + CPLString osQuotedTableName; + osQuotedTableName.Printf( "\"%s\"", pszTable ); + /* -------------------------------------------------------------------- */ /* Split out the owner if available. */ /* -------------------------------------------------------------------- */ @@ -175,20 +178,20 @@ OGRFeatureDefn *OGROCITableLayer::ReadTableDefinition( const char * pszTable ) OCIParam *hAttrList = NULL; nStatus = - OCIDescribeAny( poSession->hSvcCtx, poSession->hError, - (dvoid *) pszTable, strlen(pszTable), OCI_OTYPE_NAME, + OCIDescribeAny( poSession->hSvcCtx, poSession->hError, + (dvoid *) osQuotedTableName.c_str(), osQuotedTableName.length(), OCI_OTYPE_NAME, OCI_DEFAULT, OCI_PTYPE_TABLE, poSession->hDescribe ); if( poSession->Failed( nStatus, "OCIDescribeAny" ) ) { CPLErrorReset(); nStatus = OCIDescribeAny(poSession->hSvcCtx, poSession->hError, - (dvoid *)pszTable, strlen(pszTable), OCI_OTYPE_NAME, + (dvoid *) osQuotedTableName.c_str(), osQuotedTableName.length(), OCI_OTYPE_NAME, OCI_DEFAULT, OCI_PTYPE_VIEW, poSession->hDescribe ); if( poSession->Failed( nStatus, "OCIDescribeAny" ) ) return poDefn; } - + if( poSession->Failed( OCIAttrGet( poSession->hDescribe, OCI_HTYPE_DESCRIBE, &hAttrParam, 0, OCI_ATTR_PARAM, poSession->hError ), @@ -264,13 +267,13 @@ OGRFeatureDefn *OGROCITableLayer::ReadTableDefinition( const char * pszTable ) char **papszResult; int iDim = -1; - oDimCmd.Append( "SELECT COUNT(*) FROM ALL_SDO_GEOM_METADATA u," ); - oDimCmd.Append( " TABLE(u.diminfo) t" ); - oDimCmd.Append( " WHERE u.table_name = '" ); - oDimCmd.Append( osTableName ); - oDimCmd.Append( "' AND u.column_name = '" ); - oDimCmd.Append( pszGeomName ); - oDimCmd.Append( "'" ); + oDimCmd.Append( "SELECT COUNT(*) FROM ALL_SDO_GEOM_METADATA u," ); + oDimCmd.Append( " TABLE(u.diminfo) t" ); + oDimCmd.Append( " WHERE u.table_name = '" ); + oDimCmd.Append( osTableName ); + oDimCmd.Append( "' AND u.column_name = '" ); + oDimCmd.Append( pszGeomName ); + oDimCmd.Append( "'" ); oDimStatement.Execute( oDimCmd.GetString() ); @@ -283,7 +286,7 @@ OGRFeatureDefn *OGROCITableLayer::ReadTableDefinition( const char * pszTable ) char **papszResult2; CPLErrorReset(); - + oDimCmd2.Appendf( 1024, "select m.sdo_index_dims\n" "from all_sdo_index_metadata m, all_sdo_index_info i\n" @@ -302,8 +305,8 @@ OGRFeatureDefn *OGROCITableLayer::ReadTableDefinition( const char * pszTable ) } else { - // we want to clear any errors to avoid confusing the application. - CPLErrorReset(); + // we want to clear any errors to avoid confusing the application. + CPLErrorReset(); } } else @@ -770,7 +773,7 @@ OGRErr OGROCITableLayer::CreateFeature( OGRFeature *poFeature ) poFeature->GetGeometryRef()->getEnvelope( &sThisExtent ); - if( !sExtent.Contains( sThisExtent ) ) + if( !sExtent.Contains( sThisExtent ) ) { sExtent.Merge( sThisExtent ); bExtentUpdated = true; @@ -807,7 +810,7 @@ OGRErr OGROCITableLayer::UnboundCreateFeature( OGRFeature *poFeature ) /* -------------------------------------------------------------------- */ /* Form the INSERT command. */ /* -------------------------------------------------------------------- */ - sprintf( pszCommand, "INSERT INTO %s (", poFeatureDefn->GetName() ); + sprintf( pszCommand, "INSERT INTO \"%s\"(\"", poFeatureDefn->GetName() ); if( poFeature->GetGeometryRef() != NULL ) { @@ -818,7 +821,7 @@ OGRErr OGROCITableLayer::UnboundCreateFeature( OGRFeature *poFeature ) if( pszFIDName != NULL ) { if( bNeedComma ) - strcat( pszCommand, ", " ); + strcat( pszCommand, "\",\"" ); strcat( pszCommand, pszFIDName ); bNeedComma = TRUE; @@ -833,13 +836,13 @@ OGRErr OGROCITableLayer::UnboundCreateFeature( OGRFeature *poFeature ) if( !bNeedComma ) bNeedComma = TRUE; else - strcat( pszCommand, ", " ); + strcat( pszCommand, "\",\"" ); - sprintf( pszCommand + strlen(pszCommand), "\"%s\"", + sprintf( pszCommand + strlen(pszCommand), "%s", poFeatureDefn->GetFieldDefn(i)->GetNameRef() ); } - strcat( pszCommand, ") VALUES (" ); + strcat( pszCommand, "\") VALUES (" ); CPLAssert( strlen(pszCommand) < nCommandBufSize ); @@ -1337,12 +1340,12 @@ void OGROCITableLayer::UpdateLayerExtents() " FROM ALL_SDO_GEOM_METADATA m, table(m.diminfo) d" " where m.table_name = UPPER('%s') and m.COLUMN_NAME = UPPER('%s')", osTableName.c_str(), pszGeomName ); - + if( osOwner != "" ) { oCommand.Appendf(500, " AND OWNER = UPPER('%s')", osOwner.c_str() ); } - + oCommand.Append(" ) "); OGROCISession *poSession = poDS->GetSession(); @@ -1439,7 +1442,7 @@ void OGROCITableLayer::UpdateLayerExtents() } else - { + { /* -------------------------------------------------------------------- */ /* Prepare dimension update statement. */ /* -------------------------------------------------------------------- */ @@ -1585,19 +1588,32 @@ int OGROCITableLayer::AllocAndBindForWrite(int eType) /* Collect the INSERT statement. */ /* -------------------------------------------------------------------- */ OGROCIStringBuf oCmdBuf; - - oCmdBuf.Append( "INSERT INTO " ); + + oCmdBuf.Append( "INSERT INTO \"" ); oCmdBuf.Append( poFeatureDefn->GetName() ); + oCmdBuf.Append( "\"(\"" ); + oCmdBuf.Append( pszFIDName ); - if (eType == wkbNone) - oCmdBuf.Append( " VALUES ( :fid" ); - else - oCmdBuf.Append( " VALUES ( :fid, :geometry" ); + if (eType != wkbNone) + { + oCmdBuf.Append( "\",\"" ); + oCmdBuf.Append( pszGeomName ); + } for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { - oCmdBuf.Append( ", " ); + oCmdBuf.Append( "\",\"" ); + oCmdBuf.Append( poFeatureDefn->GetFieldDefn(i)->GetNameRef() ); + } + oCmdBuf.Append( "\") VALUES ( :fid " ); + + if (eType != wkbNone) + oCmdBuf.Append( ", :geometry" ); + + for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) + { + oCmdBuf.Append( ", " ); oCmdBuf.Appendf( 20, " :field_%d", i ); } @@ -1760,16 +1776,16 @@ OGRErr OGROCITableLayer::BoundCreateFeature( OGRFeature *poFeature ) if( nWriteCacheMax == 0 ) { int eType; - if( poFeature->GetGeometryRef() == NULL ) - { - eType = wkbNone; - } - else - { + if( poFeature->GetGeometryRef() == NULL ) + { + eType = wkbNone; + } + else + { eType = 1; /* PJH: properly, this should be the gType from the geometry */ - /* but the actual value does not matter, so long as it is */ - /* not wkbNone */ - } + /* but the actual value does not matter, so long as it is */ + /* not wkbNone */ + } if( !AllocAndBindForWrite(eType) ) return OGRERR_FAILURE; } @@ -1882,6 +1898,7 @@ OGRErr OGROCITableLayer::BoundCreateFeature( OGRFeature *poFeature ) } } + psInd->sdo_gtype = OCI_IND_NOTNULL; OCINumberFromInt( poSession->hError, &nGType, (uword)sizeof(int), OCI_NUMBER_SIGNED, &(psGeom->sdo_gtype) ); @@ -1891,7 +1908,14 @@ OGRErr OGROCITableLayer::BoundCreateFeature( OGRFeature *poFeature ) /* Set the FID. */ /* -------------------------------------------------------------------- */ if( poFeature->GetFID() == OGRNullFID ) + { + if( iNextFIDToWrite < 0 ) + { + iNextFIDToWrite = GetMaxFID() + 1; + } + poFeature->SetFID( iNextFIDToWrite++ ); + } panWriteFIDs[iCache] = poFeature->GetFID(); @@ -2075,3 +2099,22 @@ void OGROCITableLayer::CreateSpatialIndex() } } } + +int OGROCITableLayer::GetMaxFID() +{ + if( pszFIDName == NULL ) + return 0; + + OGROCIStringBuf sCmd; + OGROCIStatement oSelect( poDS->GetSession() ); + + sCmd.Appendf( 10000, "SELECT MAX(\"%s\") FROM \"%s\"", + pszFIDName, + poFeatureDefn->GetName() + ); + + oSelect.Execute( sCmd.GetString() ); + + char **papszResult = oSelect.SimpleFetchRow(); + return CSLCount(papszResult) == 1 ? atoi( papszResult[0] ) : 0; +}