Skip to content
Permalink
Browse files
oracle provider: fix support for geometryless tables (fixes #7023)
  • Loading branch information
jef-n committed Jan 29, 2013
1 parent f91f2d4 commit c8859ecbd3fef2de219ca14bc6bcfc19060a5632
@@ -220,17 +220,11 @@ bool QgsOracleConn::tableInfo( bool geometryColumnsOnly, bool userTablesOnly, bo
layerProperty.ownerName = qry.value( 0 ).toString();
layerProperty.tableName = qry.value( 1 ).toString();
layerProperty.geometryColName = qry.value( 2 ).toString();
layerProperty.types = QList<QGis::WkbType>() << ( qry.value( 2 ).isNull() ? QGis::WKBNoGeometry : QGis::WKBUnknown );
layerProperty.srids = QList<int>() << qry.value( 3 ).toInt();
layerProperty.types = QList<QGis::WkbType>() << QGis::WKBUnknown; // detect
layerProperty.isView = qry.value( 4 ).isNull();
layerProperty.pkCols.clear();

if ( allowGeometrylessTables )
{
layerProperty.types << QGis::WKBNoGeometry;
layerProperty.srids << 0;
}

mLayersSupported << layerProperty;
}

@@ -83,13 +83,14 @@ struct QgsOracleLayerProperty
sridString += QString::number( srid );
}

return QString( "%1.%2.%3 type=%4 srid=%5 view=%6 sql=%7" )
return QString( "%1.%2.%3 type=%4 srid=%5 view=%6%7 sql=%8" )
.arg( ownerName )
.arg( tableName )
.arg( geometryColName )
.arg( typeString )
.arg( sridString )
.arg( isView ? "yes" : "no" )
.arg( isView ? QString( " pk=%1" ).arg( pkCols.join( "|" ) ) : "" )
.arg( sql );
}
#endif
@@ -582,11 +582,11 @@ bool QgsOracleProvider::loadFields()
",t.char_used"
",t.data_default"
" FROM all_tab_columns t"
" WHERE t.owner=%1 AND t.table_name=%2 AND t.column_name<>%3"
" WHERE t.owner=%1 AND t.table_name=%2%3"
" ORDER BY t.column_id" )
.arg( quotedValue( mOwnerName ) )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mGeometryColumn ) )
.arg( mGeometryColumn.isEmpty() ? "" : QString( " AND t.column_name<>%1 " ).arg( quotedValue( mGeometryColumn ) ) )
) )
{
while ( qry.next() )
@@ -643,50 +643,53 @@ bool QgsOracleProvider::loadFields()
tr( "Oracle" ) );
}

if ( exec( qry, QString( "SELECT i.index_name,i.domidx_opstatus"
" FROM all_indexes i"
" JOIN all_ind_columns c ON i.owner=c.index_owner AND i.index_name=c.index_name AND c.column_name=%3"
" WHERE i.table_owner=%1 AND i.table_name=%2 AND i.ityp_owner='MDSYS' AND i.ityp_name='SPATIAL_INDEX'" )
.arg( quotedValue( mOwnerName ) )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mGeometryColumn ) ) ) )
if ( !mGeometryColumn.isEmpty() )
{
if ( qry.next() )
if ( exec( qry, QString( "SELECT i.index_name,i.domidx_opstatus"
" FROM all_indexes i"
" JOIN all_ind_columns c ON i.owner=c.index_owner AND i.index_name=c.index_name AND c.column_name=%3"
" WHERE i.table_owner=%1 AND i.table_name=%2 AND i.ityp_owner='MDSYS' AND i.ityp_name='SPATIAL_INDEX'" )
.arg( quotedValue( mOwnerName ) )
.arg( quotedValue( mTableName ) )
.arg( quotedValue( mGeometryColumn ) ) ) )
{
mSpatialIndex = qry.value( 0 ).toString();
if ( qry.value( 1 ).toString() != "VALID" )
if ( qry.next() )
{
mSpatialIndex = qry.value( 0 ).toString();
if ( qry.value( 1 ).toString() != "VALID" )
{
QgsMessageLog::logMessage( tr( "Invalid spatial index %1 on column %2.%3.%4 found - expect poor performance." )
.arg( mSpatialIndex )
.arg( mOwnerName )
.arg( mTableName )
.arg( mGeometryColumn ),
tr( "Oracle" ) );
mSpatialIndex = QString::null;
}
else
{
QgsDebugMsg( QString( "Valid spatial index %1 found" ).arg( mSpatialIndex ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "Invalid spatial index %1 on column %2.%3.%4 found - expect poor performance." )
.arg( mSpatialIndex )
QgsMessageLog::logMessage( tr( "No spatial index on column %1.%2.%3 found - expect poor performance." )
.arg( mOwnerName )
.arg( mTableName )
.arg( mGeometryColumn ),
tr( "Oracle" ) );
mSpatialIndex = QString::null;
}
else
{
QgsDebugMsg( QString( "Valid spatial index %1 found" ).arg( mSpatialIndex ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "No spatial index on column %1.%2.%3 found - expect poor performance." )
QgsMessageLog::logMessage( tr( "Probing for spatial index on column %1.%2.%3 failed [%4]" )
.arg( mOwnerName )
.arg( mTableName )
.arg( mGeometryColumn ),
.arg( mGeometryColumn )
.arg( qry.lastError().text() ),
tr( "Oracle" ) );
}
}
else
{
QgsMessageLog::logMessage( tr( "Probing for spatial index on column %1.%2.%3 failed [%4]" )
.arg( mOwnerName )
.arg( mTableName )
.arg( mGeometryColumn )
.arg( qry.lastError().text() ),
tr( "Oracle" ) );
}

qry.finish();

@@ -708,6 +711,9 @@ bool QgsOracleProvider::loadFields()
if ( field.name() == mGeometryColumn )
continue;

if ( !types.contains( field.name() ) )
continue;

mAttributeFields.append( QgsField( field.name(), field.type(), types.value( field.name() ), field.length(), field.precision(), comments.value( field.name() ) ) );
mDefaultValues.append( defvalues.value( field.name(), QVariant() ) );
}
@@ -85,7 +85,6 @@ QWidget *QgsOracleSourceSelectDelegate::createEditor( QWidget *parent, const QSt
if ( values.size() == 0 )
return 0;


if ( values.size() > 0 )
{
QComboBox *cb = new QComboBox( parent );
@@ -59,10 +59,10 @@ void QgsOracleTableModel::addTableEntry( QgsOracleLayerProperty layerProperty )
QgsDebugMsg( layerProperty.toString() );
#endif

if ( !layerProperty.types.contains( QGis::WKBUnknown ) )
if ( layerProperty.isView && layerProperty.pkCols.isEmpty() )
{
layerProperty.types << ( layerProperty.geometryColName.isEmpty() ? QGis::WKBNoGeometry : QGis::WKBUnknown );
layerProperty.srids << 0;
QgsDebugMsg( "View without pk skipped." );
return;
}

// is there already a root item with the given scheme Name?
@@ -75,7 +75,7 @@ void QgsOracleTableModel::addTableEntry( QgsOracleLayerProperty layerProperty )

QStandardItem *ownerNameItem = new QStandardItem( layerProperty.ownerName );

bool selectable = wkbType != QGis::WKBUnknown && srid != 0;
bool selectable = wkbType == QGis::WKBNoGeometry || ( wkbType != QGis::WKBUnknown && srid != 0 );

QStandardItem *typeItem = new QStandardItem( iconForWkbType( wkbType ), wkbType == QGis::WKBUnknown ? tr( "Select..." ) : QgsOracleConn::displayStringForWkbType( wkbType ) );
typeItem->setData( wkbType == QGis::WKBUnknown, Qt::UserRole + 1 );
@@ -85,9 +85,9 @@ void QgsOracleTableModel::addTableEntry( QgsOracleLayerProperty layerProperty )

QStandardItem *tableItem = new QStandardItem( layerProperty.tableName );
QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName );
QStandardItem *sridItem = new QStandardItem( QString::number( srid ) );
sridItem->setEditable( srid == 0 );
if ( srid == 0 )
QStandardItem *sridItem = new QStandardItem( wkbType != QGis::WKBNoGeometry ? QString::number( srid ) : "" );
sridItem->setEditable( wkbType != QGis::WKBNoGeometry && srid == 0 );
if ( sridItem->isEditable() )
{
sridItem->setText( tr( "Enter..." ) );
sridItem->setFlags( sridItem->flags() | Qt::ItemIsEditable );
@@ -256,10 +256,10 @@ bool QgsOracleTableModel::setData( const QModelIndex &idx, const QVariant &value
bool ok = geomType != QGis::WKBUnknown;

if ( ok && geomType != QGis::WKBNoGeometry )
idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );

int srid = idx.sibling( idx.row(), dbtmSrid ).data().toInt();
ok &= srid != 0;
{
int srid = idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );
ok &= srid != 0;
}

ok &= !idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toBool() ||
idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 2 ).toBool();

0 comments on commit c8859ec

Please sign in to comment.