Skip to content
Permalink
Browse files
postgres fixes:
- allow editing of where clause in database selection dialog
- don't open query builder with invalid layer
- reallow oid type as primary key type
- preset where clause with current one in query builder
- actually show error message when QgsPostgresProvider::getGeometryDetails() fails



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11767 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 8, 2009
1 parent 27d4369 commit bda3d75b7989ffbf6e149417af1fa7fe447e92de
Showing with 57 additions and 28 deletions.
  1. +1 −1 i18n/qgis_de.ts
  2. +1 −1 src/app/qgsdbtablemodel.cpp
  3. +16 −11 src/app/qgspgsourceselect.cpp
  4. +24 −9 src/app/qgspgsourceselect.h
  5. +2 −0 src/app/qgsquerybuilder.cpp
  6. +13 −6 src/providers/postgres/qgspostgresprovider.cpp
@@ -17347,7 +17347,7 @@ p, li { white-space: pre-wrap; }
<message>
<location filename="../src/providers/postgres/qgspostgresprovider.cpp" line="2899"/>
<source>Unable to get feature type and srid</source>
<translation>Kann den Fearture-Typ und die SRID nicht ermitteln</translation>
<translation>Kann den Objekttyp und die SRID nicht ermitteln</translation>
</message>
<message>
<location filename="../src/providers/postgres/qgspostgresprovider.cpp" line="2188"/>
@@ -73,7 +73,7 @@ void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString t
pkItem->setData( pkCols );
pkItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
QStandardItem* sqlItem = new QStandardItem( sql );
sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );

childItemList.push_back( schemaNameItem );
childItemList.push_back( tableItem );
@@ -67,7 +67,7 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl )

mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );

mTablesTreeView->setItemDelegateForColumn( QgsDbTableModel::dbtmPkCol, new QgsPgSourceSelectDelegate( this ) );
mTablesTreeView->setItemDelegate( new QgsPgSourceSelectDelegate( this ) );

QSettings settings;
mTablesTreeView->setSelectionMode( settings.value( "/qgis/addPostgisDC", false ).toBool() ?
@@ -325,9 +325,9 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
}

uri += QString( " table=\"%1\".\"%2\" (%3) sql=%4" )
.arg( schemaName ).arg( tableName )
.arg( geomColumnName )
.arg( sql );
.arg( schemaName ).arg( tableName )
.arg( geomColumnName )
.arg( sql );

return uri;
}
@@ -341,7 +341,7 @@ void QgsPgSourceSelect::addTables()
QModelIndexList::const_iterator selected_it = selectedIndices.constBegin();
for ( ; selected_it != selectedIndices.constEnd(); ++selected_it )
{
if ( !selected_it->parent().isValid() || selected_it->column()>0 )
if ( !selected_it->parent().isValid() || selected_it->column() > 0 )
{
//top level items only contain the schema names
continue;
@@ -501,18 +501,23 @@ QString QgsPgSourceSelect::connectionInfo()

void QgsPgSourceSelect::setSql( const QModelIndex &index )
{
QgsDebugMsg( QString("%1,%2").arg( index.row() ).arg( index.column() ) );
if ( !index.parent().isValid() )
{
QgsDebugMsg( "schema item found" );
return;
}

QgsVectorLayer *vlayer = new QgsVectorLayer( layerURI( mProxyModel.mapToSource( index ) ), "querybuilder", "postgres" );

if ( !vlayer->isValid() )
{
delete vlayer;
return;
}

// create a query builder object
QgsQueryBuilder *gb = new QgsQueryBuilder( vlayer, this );
if( gb->exec() )
if ( gb->exec() )
{
mTableModel.setSql( mProxyModel.mapToSource( index ), gb->sql() );
}
@@ -537,7 +542,7 @@ QStringList QgsPgSourceSelect::pkCandidates( PGconn *pg, QString schemaName, QSt
QStringList cols;
cols << QString::null;

QString sql = QString( "select attname from pg_attribute join pg_type on atttypid=pg_type.oid WHERE pg_type.typname='int4' AND attrelid=regclass('\"%1\".\"%2\"')" ).arg( schemaName ).arg( viewName );
QString sql = QString( "select attname from pg_attribute join pg_type on atttypid=pg_type.oid WHERE pg_type.typname IN ('int4','oid') AND attrelid=regclass('\"%1\".\"%2\"')" ).arg( schemaName ).arg( viewName );
QgsDebugMsg( sql );
PGresult *colRes = PQexec( pg, sql.toUtf8() );

@@ -614,7 +619,7 @@ bool QgsPgSourceSelect::getTableInfo( PGconn *pg, bool searchGeometryColumnsOnly
as = type = "WAITING";
}

mTableModel.addTableEntry( type, schemaName, tableName, column, relkind=="v" ? pkCandidates( pg, schemaName, tableName ) : QStringList(), "" );
mTableModel.addTableEntry( type, schemaName, tableName, column, relkind == "v" ? pkCandidates( pg, schemaName, tableName ) : QStringList(), "" );
n++;
}
}
@@ -694,7 +699,7 @@ bool QgsPgSourceSelect::getTableInfo( PGconn *pg, bool searchGeometryColumnsOnly

addSearchGeometryColumn( schema, table, column );
//details.push_back(geomPair(fullDescription(schema, table, column, "WAITING"), "WAITING"));
mTableModel.addTableEntry( "Waiting", schema, table, column, relkind=="v" ? pkCandidates( pg, schema, table ) : QStringList(), "" );
mTableModel.addTableEntry( "Waiting", schema, table, column, relkind == "v" ? pkCandidates( pg, schema, table ) : QStringList(), "" );
n++;
}
}
@@ -1,5 +1,5 @@
/***************************************************************************
qgdbsourceselect.h - description
qgpgsourceselect.h - description
-------------------
begin : Sat Jun 22 2002
copyright : (C) 2002 by Gary E.Sherman
@@ -53,13 +53,25 @@ class QgsPgSourceSelectDelegate : public QItemDelegate
const QStyleOptionViewItem &option,
const QModelIndex &index ) const
{
QStringList values = index.data( Qt::UserRole + 1 ).toStringList();
if ( index.column() == QgsDbTableModel::dbtmSql )
{
QLineEdit *le = new QLineEdit( parent );
le->setText( index.data( Qt::DisplayRole ).toString() );
return le;
}

if( values.size()> 0 )

if ( index.column() == QgsDbTableModel::dbtmPkCol )
{
QComboBox *cb = new QComboBox( parent );
cb->addItems( values );
return cb;
QStringList values = index.data( Qt::UserRole + 1 ).toStringList();

if ( values.size() > 0 )
{
QComboBox *cb = new QComboBox( parent );
cb->addItems( values );
cb->setCurrentIndex( cb->findText( index.data( Qt::DisplayRole ).toString() ) );
return cb;
}
}

return NULL;
@@ -68,9 +80,12 @@ class QgsPgSourceSelectDelegate : public QItemDelegate
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QComboBox *cb = dynamic_cast<QComboBox *>( editor );
if ( !cb )
return;
model->setData( index, cb->currentText() );
if ( cb )
model->setData( index, cb->currentText() );

QLineEdit *le = dynamic_cast<QLineEdit *>( editor );
if ( le )
model->setData( index, le->text() );
}
};

@@ -39,6 +39,8 @@ QgsQueryBuilder::QgsQueryBuilder( QgsVectorLayer *layer,
mOrigSubsetString = layer->subsetString();

lblDataUri->setText( layer->publicSource() );
txtSQL->setText( mOrigSubsetString );

populateFields();
}

@@ -1054,10 +1054,15 @@ QString QgsPostgresProvider::getPrimaryKey()

Result result = connectionRO->PQexec( sql );

if ( PQresultStatus( result ) != PGRES_TUPLES_OK ||
PQntuples( result ) != 1 ||
QString( PQgetvalue( result, 0, 0 ) ) != "int4" ||
!uniqueData( mSchemaName, mTableName, primaryKey ) )
QString type;
if ( PQresultStatus( result ) == PGRES_TUPLES_OK &&
PQntuples( result ) == 1 )
{
type = PQgetvalue( result, 0, 0 );
}

if (( type != "int4" && type != "oid" ) ||
!uniqueData( mSchemaName, mTableName, primaryKey ) )
{
primaryKey = "";
}
@@ -2901,8 +2906,10 @@ bool QgsPostgresProvider::getGeometryDetails()
}
else // something went wrong...
{
log.prepend( tr( "Qgis was unable to determine the type and srid of column %1 in %2. The database communication log was:\n" )
.arg( geometryColumn ).arg( mSchemaTableName ) );
log.prepend( tr( "Qgis was unable to determine the type and srid of column %1 in %2. The database communication log was:\n%3" )
.arg( geometryColumn )
.arg( mSchemaTableName )
.arg( QString::fromUtf8( PQresultErrorMessage( result ) ) ) );
showMessageBox( tr( "Unable to get feature type and srid" ), log );
}

0 comments on commit bda3d75

Please sign in to comment.