?? ogrocitablelayer.cpp
字號:
/* -------------------------------------------------------------------- */ if( poFeature->GetGeometryRef() != NULL ) { OGREnvelope sThisExtent; poFeature->GetGeometryRef()->getEnvelope( &sThisExtent ); sExtent.Merge( sThisExtent ); }/* -------------------------------------------------------------------- *//* Do the actual creation. *//* -------------------------------------------------------------------- */ if( CSLFetchBoolean( papszOptions, "MULTI_LOAD", bNewLayer ) ) return BoundCreateFeature( poFeature ); else return UnboundCreateFeature( poFeature );}/************************************************************************//* UnboundCreateFeature() *//************************************************************************/OGRErr OGROCITableLayer::UnboundCreateFeature( OGRFeature *poFeature ){ OGROCISession *poSession = poDS->GetSession(); char *pszCommand; int i, bNeedComma = FALSE; unsigned int nCommandBufSize;;/* -------------------------------------------------------------------- *//* Prepare SQL statement buffer. *//* -------------------------------------------------------------------- */ nCommandBufSize = 2000; pszCommand = (char *) CPLMalloc(nCommandBufSize);/* -------------------------------------------------------------------- *//* Form the INSERT command. *//* -------------------------------------------------------------------- */ sprintf( pszCommand, "INSERT INTO %s (", poFeatureDefn->GetName() ); if( poFeature->GetGeometryRef() != NULL ) { bNeedComma = TRUE; strcat( pszCommand, pszGeomName ); } if( pszFIDName != NULL ) { if( bNeedComma ) strcat( pszCommand, ", " ); strcat( pszCommand, pszFIDName ); bNeedComma = TRUE; } for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if( !poFeature->IsFieldSet( i ) ) continue; if( !bNeedComma ) bNeedComma = TRUE; else strcat( pszCommand, ", " ); sprintf( pszCommand + strlen(pszCommand), "\"%s\"", poFeatureDefn->GetFieldDefn(i)->GetNameRef() ); } strcat( pszCommand, ") VALUES (" ); CPLAssert( strlen(pszCommand) < nCommandBufSize );/* -------------------------------------------------------------------- *//* Set the geometry *//* -------------------------------------------------------------------- */ bNeedComma = poFeature->GetGeometryRef() != NULL; if( poFeature->GetGeometryRef() != NULL) { OGRGeometry *poGeometry = poFeature->GetGeometryRef(); char szSDO_GEOMETRY[512]; char szSRID[128]; if( nSRID == -1 ) strcpy( szSRID, "NULL" ); else sprintf( szSRID, "%d", nSRID ); if( wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ) { OGRPoint *poPoint = (OGRPoint *) poGeometry; if( nDimension == 2 ) sprintf( szSDO_GEOMETRY, "%s(%d,%s,MDSYS.SDO_POINT_TYPE(%.16g,%.16g,0),NULL,NULL)", SDO_GEOMETRY, 2001, szSRID, poPoint->getX(), poPoint->getY() ); else sprintf( szSDO_GEOMETRY, "%s(%d,%s,MDSYS.SDO_POINT_TYPE(%.16g,%.16g,%.16g),NULL,NULL)", SDO_GEOMETRY, 3001, szSRID, poPoint->getX(), poPoint->getY(), poPoint->getZ() ); } else { int nGType; if( TranslateToSDOGeometry( poFeature->GetGeometryRef(), &nGType ) == OGRERR_NONE ) sprintf( szSDO_GEOMETRY, "%s(%d,%s,NULL,:elem_info,:ordinates)", SDO_GEOMETRY, nGType, szSRID ); else sprintf( szSDO_GEOMETRY, "NULL" ); } if( strlen(pszCommand) + strlen(szSDO_GEOMETRY) > nCommandBufSize - 50 ) { nCommandBufSize = strlen(pszCommand) + strlen(szSDO_GEOMETRY) + 10000; pszCommand = (char *) CPLRealloc(pszCommand, nCommandBufSize ); } strcat( pszCommand, szSDO_GEOMETRY ); }/* -------------------------------------------------------------------- *//* Set the FID. *//* -------------------------------------------------------------------- */ int nOffset = strlen(pszCommand); if( pszFIDName != NULL ) { long nFID; if( bNeedComma ) strcat( pszCommand+nOffset, ", " ); bNeedComma = TRUE; nOffset += strlen(pszCommand+nOffset); nFID = poFeature->GetFID(); if( nFID == -1 ) nFID = iNextFIDToWrite++; sprintf( pszCommand+nOffset, "%ld", nFID ); }/* -------------------------------------------------------------------- *//* Set the other fields. *//* -------------------------------------------------------------------- */ for( i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if( !poFeature->IsFieldSet( i ) ) continue; OGRFieldDefn *poFldDefn = poFeatureDefn->GetFieldDefn(i); const char *pszStrValue = poFeature->GetFieldAsString(i); if( bNeedComma ) strcat( pszCommand+nOffset, ", " ); else bNeedComma = TRUE; if( strlen(pszStrValue) + strlen(pszCommand+nOffset) + nOffset > nCommandBufSize-50 ) { nCommandBufSize = strlen(pszCommand) + strlen(pszStrValue) + 10000; pszCommand = (char *) CPLRealloc(pszCommand, nCommandBufSize ); } if( poFldDefn->GetType() == OFTInteger || poFldDefn->GetType() == OFTReal ) { if( poFldDefn->GetWidth() > 0 && bPreservePrecision && (int) strlen(pszStrValue) > poFldDefn->GetWidth() ) { strcat( pszCommand+nOffset, "NULL" ); ReportTruncation( poFldDefn ); } else strcat( pszCommand+nOffset, pszStrValue ); } else { int iChar; /* We need to quote and escape string fields. */ strcat( pszCommand+nOffset, "'" ); nOffset += strlen(pszCommand+nOffset); for( iChar = 0; pszStrValue[iChar] != '\0'; iChar++ ) { if( poFldDefn->GetWidth() != 0 && bPreservePrecision && iChar >= poFldDefn->GetWidth() ) { ReportTruncation( poFldDefn ); break; } if( pszStrValue[iChar] == '\'' ) { pszCommand[nOffset++] = '\''; pszCommand[nOffset++] = pszStrValue[iChar]; } else pszCommand[nOffset++] = pszStrValue[iChar]; } pszCommand[nOffset] = '\0'; strcat( pszCommand+nOffset, "'" ); } nOffset += strlen(pszCommand+nOffset); } strcat( pszCommand+nOffset, ")" );/* -------------------------------------------------------------------- *//* Prepare statement. *//* -------------------------------------------------------------------- */ OGROCIStatement oInsert( poSession ); int bHaveOrdinates = strstr(pszCommand,":ordinates") != NULL; int bHaveElemInfo = strstr(pszCommand,":elem_info") != NULL; if( oInsert.Prepare( pszCommand ) != CE_None ) { CPLFree( pszCommand ); return OGRERR_FAILURE; } CPLFree( pszCommand );/* -------------------------------------------------------------------- *//* Bind and translate the elem_info if we have some. *//* -------------------------------------------------------------------- */ if( bHaveElemInfo ) { OCIBind *hBindOrd = NULL; int i; OCINumber oci_number; // Create or clear VARRAY if( hElemInfoVARRAY == NULL ) { if( poSession->Failed( OCIObjectNew( poSession->hEnv, poSession->hError, poSession->hSvcCtx, OCI_TYPECODE_VARRAY, poSession->hElemInfoTDO, (dvoid *)NULL, OCI_DURATION_SESSION, FALSE, (dvoid **)&hElemInfoVARRAY), "OCIObjectNew(hElemInfoVARRAY)") ) return OGRERR_FAILURE; } else { sb4 nOldCount; OCICollSize( poSession->hEnv, poSession->hError, hElemInfoVARRAY, &nOldCount ); OCICollTrim( poSession->hEnv, poSession->hError, nOldCount, hElemInfoVARRAY ); } // Prepare the VARRAY of ordinate values. for (i = 0; i < nElemInfoCount; i++) { if( poSession->Failed( OCINumberFromInt( poSession->hError, (dvoid *) (panElemInfo + i), (uword)sizeof(int), OCI_NUMBER_SIGNED, &oci_number), "OCINumberFromInt") ) return OGRERR_FAILURE; if( poSession->Failed( OCICollAppend( poSession->hEnv, poSession->hError, (dvoid *) &oci_number, (dvoid *)0, hElemInfoVARRAY), "OCICollAppend") ) return OGRERR_FAILURE; } // Do the binding. if( poSession->Failed( OCIBindByName( oInsert.GetStatement(), &hBindOrd, poSession->hError, (text *) ":elem_info", (sb4) -1, (dvoid *) 0, (sb4) 0, SQLT_NTY, (dvoid *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (ub4)OCI_DEFAULT), "OCIBindByName(:elem_info)") ) return OGRERR_FAILURE; if( poSession->Failed( OCIBindObject( hBindOrd, poSession->hError, poSession->hElemInfoTDO, (dvoid **)&hElemInfoVARRAY, (ub4 *)0, (dvoid **)0, (ub4 *)0), "OCIBindObject(:elem_info)" ) ) return OGRERR_FAILURE; }/* -------------------------------------------------------------------- *//* Bind and translate the ordinates if we have some. *//* -------------------------------------------------------------------- */ if( bHaveOrdinates ) { OCIBind *hBindOrd = NULL; int i; OCINumber oci_number; // Create or clear VARRAY if( hOrdVARRAY == NULL ) { if( poSession->Failed( OCIObjectNew( poSession->hEnv, poSession->hError, poSession->hSvcCtx, OCI_TYPECODE_VARRAY, poSession->hOrdinatesTDO, (dvoid *)NULL, OCI_DURATION_SESSION, FALSE, (dvoid **)&hOrdVARRAY), "OCIObjectNew(hOrdVARRAY)") ) return OGRERR_FAILURE; } else { sb4 nOldCount; OCICollSize( poSession->hEnv, poSession->hError, hOrdVARRAY, &nOldCount ); OCICollTrim( poSession->hEnv, poSession->hError, nOldCount, hOrdVARRAY ); } // Prepare the VARRAY of ordinate values. for (i = 0; i < nOrdinalCount; i++) { if( poSession->Failed(
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -