Opened 14 years ago

Closed 12 years ago

#2026 closed defect (fixed)

ogr2ogr PG:driver cannot read schema "public" qualified layers

Reported by: hdus Owned by: warmerdam
Priority: normal Milestone: 1.7.0
Component: default Version: 1.4.0
Severity: normal Keywords:
Cc: pka

Description

ogr2ogr and ogrinfo do not find layers in public schema when table name is given with "public".<table>.

Change History (2)

comment:1 Changed 14 years ago by pka

For backwards compatibility, the internal layer name is not qualified with the schema name, if it is the current_schema(). This seems to be a problem with the current version of QGIS and maybe GRASS.

OGRPGTableLayer::ReadTableDefinition:

/*      Parse the returned table information.                           */
/* -------------------------------------------------------------------- */
    char szLayerName[256];
    if ( pszSchemaNameIn && osCurrentSchema != pszSchemaNameIn )
    {
        sprintf( szLayerName, "%s.%s", pszSchemaNameIn, pszTableIn );
        sprintf( pszSqlTableName, "\"%s\".\"%s\"", pszSchemaNameIn, pszTableIn );
    }
    else
    {
        //no prefix for current_schema in layer name, for backwards compatibility
        strcpy( szLayerName, pszTableIn );
        sprintf( pszSqlTableName, "\"%s\"", pszTableIn );
    }

    OGRFeatureDefn *poDefn = new OGRFeatureDefn( szLayerName );

ogrinfo.cpp:

/*      Process each data source layer.                                 */
/* -------------------------------------------------------------------- */
    CPLDebug( "OGR", "GetLayerCount() = %d\n", poDS->GetLayerCount() );

    for( int iRepeat = 0; iRepeat < nRepeatCount; iRepeat++ )
    {
        for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
        {
            OGRLayer        *poLayer = poDS->GetLayer(iLayer);
...
            else if( bAllLayers
                     || CSLFindString( papszLayers,
                                   poLayer->GetLayerDefn()->GetName() ) != -1 )
            {
...
                ReportOnLayer( poLayer, pszWHERE, poSpatialFilter );
            }

I can't see a clean backwards compatible solution for this, right now. Mateusz?

comment:2 Changed 12 years ago by Even Rouault

Milestone: 1.7.0
Resolution: fixed
Status: newclosed

r17908 /trunk/gdal/apps/ogrinfo.cpp: Preserve order of source layers specified on ogrinfo command line, and use GetLayerByName?() which enables to read some hidden layers like public.<table> layers from a PG database (#2922, #2026)

Note: See TracTickets for help on using tickets.