Skip to content
Permalink
Browse files

[FEATURE] allow non-numeric keys in postgres and oracle views

  • Loading branch information
jef-n committed Mar 31, 2013
1 parent 9f8d386 commit 04d1611eb425c63a4f8ddf6d8404443c42914d46
@@ -157,7 +157,7 @@ QStringList QgsOracleConn::pkCandidates( QString ownerName, QString viewName )
QStringList cols;

QSqlQuery qry( mDatabase );
if ( !exec( qry, QString( "SELECT column_name FROM all_tab_columns WHERE owner=%1 AND table_name=%2 AND data_type='NUMBER' AND data_scale=0" )
if ( !exec( qry, QString( "SELECT column_name FROM all_tab_columns WHERE owner=%1 AND table_name=%2" )
.arg( quotedValue( ownerName ) ).arg( quotedValue( viewName ) ) ) )
{
QgsMessageLog::logMessage( tr( "SQL:%1\nerror:%2\n" ).arg( qry.lastQuery() ).arg( qry.lastError().text() ), tr( "Oracle" ) );
@@ -918,23 +918,14 @@ bool QgsOracleProvider::determinePrimaryKey()
{
const QgsField &fld = mAttributeFields.at( idx );

if ( fld.type() == QVariant::Int ||
fld.type() == QVariant::LongLong ||
( fld.type() == QVariant::Double && fld.precision() == 0 ) )
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
mPrimaryKeyType = pktInt;
mPrimaryKeyAttrs << idx;
}
else
{
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "Oracle" ) );
}
mPrimaryKeyType = ( fld.type() == QVariant::Int || fld.type() == QVariant::LongLong || ( fld.type() == QVariant::Double && fld.precision() == 0 ) ) ? pktInt : pktFidMap;
mPrimaryKeyAttrs << idx;
}
else
{
QgsMessageLog::logMessage( tr( "Type '%1' of primary key field '%2' for view invalid." ).arg( fld.typeName() ).arg( primaryKey ), tr( "Oracle" ) );
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "Oracle" ) );
}
}
else
@@ -273,7 +273,7 @@ QStringList QgsPostgresConn::pkCandidates( QString schemaName, QString viewName
{
QStringList cols;

QString sql = QString( "SELECT attname FROM pg_attribute JOIN pg_type ON atttypid=pg_type.oid WHERE pg_type.typname IN ('int2','int4','int8','oid','serial','serial8') AND attrelid=regclass('%1.%2')" )
QString sql = QString( "SELECT attname FROM pg_attribute JOIN pg_type ON atttypid=pg_type.oid WHERE attrelid=regclass('%1.%2')" )
.arg( quotedIdentifier( schemaName ) )
.arg( quotedIdentifier( viewName ) );
QgsDebugMsg( sql );
@@ -1035,21 +1035,14 @@ bool QgsPostgresProvider::determinePrimaryKey()

if ( idx >= 0 )
{
if ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong )
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
if ( mUseEstimatedMetadata || uniqueData( mQuery, primaryKey ) )
{
mPrimaryKeyType = pktInt;
mPrimaryKeyAttrs << idx;
}
else
{
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "PostGIS" ) );
}
mPrimaryKeyType = ( mAttributeFields[idx].type() == QVariant::Int || mAttributeFields[idx].type() == QVariant::LongLong ) ? pktInt : pktFidMap;
mPrimaryKeyAttrs << idx;
}
else
{
QgsMessageLog::logMessage( tr( "Type '%1' of primary key field '%2' for view invalid." ).arg( mAttributeFields[idx].typeName() ).arg( primaryKey ), tr( "PostGIS" ) );
QgsMessageLog::logMessage( tr( "Primary key field '%1' for view not unique." ).arg( primaryKey ), tr( "PostGIS" ) );
}
}
else

0 comments on commit 04d1611

Please sign in to comment.
You can’t perform that action at this time.