ogrodbcdatasource.cpp

来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 471 行 · 第 1/2 页

CPP
471
字号
                papszGeomCol =                     CSLAddString( papszGeomCol, oStmt.GetColData(1) );            }        }    }            /* -------------------------------------------------------------------- *//*      Otherwise our final resort is to return all tables as           *//*      non-spatial tables.                                             *//* -------------------------------------------------------------------- */    if( papszTables == NULL )    {        CPLODBCStatement oTableList( &oSession );                if( oTableList.GetTables() )        {            while( oTableList.Fetch() )            {                papszTables =                     CSLAddString( papszTables, oTableList.GetColData(2) );                papszGeomCol = CSLAddString(papszGeomCol,"");            }        }    }/* -------------------------------------------------------------------- *//*      If we have an explicit list of requested tables, use them       *//*      (non-spatial).                                                  *//* -------------------------------------------------------------------- */    for( int iTable = 0;          papszTables != NULL && papszTables[iTable] != NULL;          iTable++ )    {        if( strlen(papszGeomCol[iTable]) > 0 )            OpenTable( papszTables[iTable], papszGeomCol[iTable], bUpdate );        else            OpenTable( papszTables[iTable], NULL, bUpdate );    }    CSLDestroy( papszTables );    CSLDestroy( papszGeomCol );/* -------------------------------------------------------------------- *//*      If no explicit list of tables was given, check for a list in    *//*      a geometry_columns table.                                       *//* -------------------------------------------------------------------- */    if ( pszSRSTableName )    {        CPLODBCStatement oSRSList( &oSession );        if ( !pszSRTextCol )            pszSRTextCol = CPLStrdup( "srtext" );        if ( !pszSRIDCol )            pszSRIDCol = CPLStrdup( "srid" );        oSRSList.Append( "SELECT " );        oSRSList.Append( pszSRIDCol );        oSRSList.Append( "," );        oSRSList.Append( pszSRTextCol );        oSRSList.Append( " FROM " );        oSRSList.Append( pszSRSTableName );        CPLDebug( "OGR_ODBC", "ExecuteSQL(%s) to read SRS table",                  oSRSList.GetCommand() );        if ( oSRSList.ExecuteSQL() )        {            int nRows = 256;     // A reasonable number of SRIDs to start from            panSRID = (int *)CPLMalloc( nRows * sizeof(int) );            papoSRS = (OGRSpatialReference **)                CPLMalloc( nRows * sizeof(OGRSpatialReference*) );            while ( oSRSList.Fetch() )            {                char *pszSRID = (char *) oSRSList.GetColData( pszSRIDCol );                if ( !pszSRID )                    continue;                char *pszSRText = (char *) oSRSList.GetColData( pszSRTextCol );                if ( pszSRText )                {                    if ( nKnownSRID > nRows )                    {                        nRows *= 2;                        panSRID = (int *)CPLRealloc( panSRID,                                                     nRows * sizeof(int) );                        papoSRS = (OGRSpatialReference **)                            CPLRealloc( papoSRS,                            nRows * sizeof(OGRSpatialReference*) );                    }                    panSRID[nKnownSRID] = atoi( pszSRID );                    papoSRS[nKnownSRID] = new OGRSpatialReference();                    if ( papoSRS[nKnownSRID]->importFromWkt( &pszSRText )                         != OGRERR_NONE )                    {                        delete papoSRS[nKnownSRID];                        continue;                    }                    nKnownSRID++;                }            }        }    }    if ( pszSRIDCol )        CPLFree( pszSRIDCol );    if ( pszSRTextCol )        CPLFree( pszSRTextCol );    if ( pszSRSTableName )        CPLFree( pszSRSTableName );    return TRUE;}/************************************************************************//*                             OpenTable()                              *//************************************************************************/int OGRODBCDataSource::OpenTable( const char *pszNewName,                                   const char *pszGeomCol,                                  int bUpdate ){/* -------------------------------------------------------------------- *//*      Create the layer object.                                        *//* -------------------------------------------------------------------- */    OGRODBCTableLayer  *poLayer;    poLayer = new OGRODBCTableLayer( this );    if( poLayer->Initialize( pszNewName, pszGeomCol ) )    {        delete poLayer;        return FALSE;    }/* -------------------------------------------------------------------- *//*      Add layer to data source layer list.                            *//* -------------------------------------------------------------------- */    papoLayers = (OGRODBCLayer **)        CPLRealloc( papoLayers,  sizeof(OGRODBCLayer *) * (nLayers+1) );    papoLayers[nLayers++] = poLayer;        return TRUE;}/************************************************************************//*                           TestCapability()                           *//************************************************************************/int OGRODBCDataSource::TestCapability( const char * pszCap ){    if( EQUAL(pszCap,ODsCCreateLayer) )        return TRUE;    else        return FALSE;}/************************************************************************//*                              GetLayer()                              *//************************************************************************/OGRLayer *OGRODBCDataSource::GetLayer( int iLayer ){    if( iLayer < 0 || iLayer >= nLayers )        return NULL;    else        return papoLayers[iLayer];}/************************************************************************//*                             ExecuteSQL()                             *//************************************************************************/OGRLayer * OGRODBCDataSource::ExecuteSQL( const char *pszSQLCommand,                                          OGRGeometry *poSpatialFilter,                                          const char *pszDialect ){/* -------------------------------------------------------------------- *//*      Use generic imlplementation for OGRSQL dialect.                 *//* -------------------------------------------------------------------- */    if( pszDialect != NULL && EQUAL(pszDialect,"OGRSQL") )        return OGRDataSource::ExecuteSQL( pszSQLCommand,                                           poSpatialFilter,                                           pszDialect );/* -------------------------------------------------------------------- *//*      Execute statement.                                              *//* -------------------------------------------------------------------- */    CPLODBCStatement *poStmt = new CPLODBCStatement( &oSession );    poStmt->Append( pszSQLCommand );    if( !poStmt->ExecuteSQL() )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "%s", oSession.GetLastError() );        return NULL;    }/* -------------------------------------------------------------------- *//*      Are there result columns for this statement?                    *//* -------------------------------------------------------------------- */    if( poStmt->GetColCount() == 0 )    {        delete poStmt;        CPLErrorReset();        return NULL;    }/* -------------------------------------------------------------------- *//*      Create a results layer.  It will take ownership of the          *//*      statement.                                                      *//* -------------------------------------------------------------------- */    OGRODBCSelectLayer *poLayer = NULL;            poLayer = new OGRODBCSelectLayer( this, poStmt );    if( poSpatialFilter != NULL )        poLayer->SetSpatialFilter( poSpatialFilter );        return poLayer;}/************************************************************************//*                          ReleaseResultSet()                          *//************************************************************************/void OGRODBCDataSource::ReleaseResultSet( OGRLayer * poLayer ){    delete poLayer;}

⌨️ 快捷键说明

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