Skip to content

Commit

Permalink
postgres provider: avoid quering layer_styles if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 12, 2015
1 parent 12739c2 commit 1c64363
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3581,6 +3581,12 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
return "";
}

QgsPostgresResult result = conn->PQexec( "SELECT COUNT(*) FROM information_schema.tables WHERE table_name='layer_styles'" );
if ( result.PQgetvalue( 0, 0 ).toInt() == 0 )
{
return "";
}

QString selectQmlQuery = QString( "SELECT styleQML"
" FROM layer_styles"
" WHERE f_table_catalog=%1"
Expand All @@ -3594,10 +3600,11 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
.arg( QgsPostgresConn::quotedValue( dsUri.table() ) )
.arg( QgsPostgresConn::quotedValue( dsUri.geometryColumn() ) );

QgsPostgresResult result = conn->PQexec( selectQmlQuery, false );
result = conn->PQexec( selectQmlQuery );

QString style = result.PQntuples() == 1 ? result.PQgetvalue( 0, 0 ) : "";
conn->unref();

return style;
}

Expand Down

0 comments on commit 1c64363

Please sign in to comment.