⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrocitablelayer.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* -------------------------------------------------------------------- *//*      Prepare the delete command, and execute.  We don't check the    *//*      error result of the execute, since attempting to Set a          *//*      non-existing feature may be OK.                                 *//* -------------------------------------------------------------------- */    OGROCIStringBuf     oCmdText;    OGROCIStatement     oCmdStatement( poDS->GetSession() );    oCmdText.Appendf( strlen(poFeatureDefn->GetName())+strlen(pszFIDName)+100,                      "DELETE FROM %s WHERE \"%s\" = %d",                      poFeatureDefn->GetName(),                       pszFIDName,                       poFeature->GetFID() );    oCmdStatement.Execute( oCmdText.GetString() );    return CreateFeature( poFeature );}/************************************************************************//*                           CreateFeature()                            *//************************************************************************/OGRErr OGROCITableLayer::CreateFeature( OGRFeature *poFeature ){/* -------------------------------------------------------------------- *//*      Add extents of this geometry to the existing layer extents.     *//* -------------------------------------------------------------------- */    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,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -