[QGIS Commit] r11771 - trunk/qgis/src/providers/postgres
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Oct 8 10:28:27 EDT 2009
Author: jef
Date: 2009-10-08 10:28:26 -0400 (Thu, 08 Oct 2009)
New Revision: 11771
Modified:
trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
trunk/qgis/src/providers/postgres/qgspostgresprovider.h
Log:
postgres provider:
use same field expression in feature queries and min()/max()/distinct.
char fields were trimmed differently otherwise.
Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp 2009-10-08 13:03:14 UTC (rev 11770)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp 2009-10-08 14:28:26 UTC (rev 11771)
@@ -409,6 +409,31 @@
return "PostgreSQL database with PostGIS extension";
}
+QString QgsPostgresProvider::fieldExpression( const QgsField &fld ) const
+{
+ const QString &type = fld.typeName();
+ if ( type == "money" )
+ {
+ return QString( "cash_out(%1)" ).arg( quotedIdentifier( fld.name() ) );
+ }
+ else if ( type.startsWith( "_" ) )
+ {
+ return QString( "array_out(%1)" ).arg( quotedIdentifier( fld.name() ) );
+ }
+ else if ( type == "bool" )
+ {
+ return QString( "boolout(%1)" ).arg( quotedIdentifier( fld.name() ) );
+ }
+ else if ( type == "geometry" )
+ {
+ return QString( "asewkt(%1)" ).arg( quotedIdentifier( fld.name() ) );
+ }
+ else
+ {
+ return quotedIdentifier( fld.name() ) + "::text";
+ }
+}
+
bool QgsPostgresProvider::declareCursor(
const QString &cursorName,
const QgsAttributeList &fetchAttributes,
@@ -430,31 +455,10 @@
{
const QgsField &fld = field( *it );
- const QString &fieldname = fld.name();
- if ( fieldname == primaryKey )
+ if ( fld.name() == primaryKey )
continue;
- const QString &type = fld.typeName();
- if ( type == "money" )
- {
- query += QString( ",cash_out(%1)" ).arg( quotedIdentifier( fieldname ) );
- }
- else if ( type.startsWith( "_" ) )
- {
- query += QString( ",array_out(%1)" ).arg( quotedIdentifier( fieldname ) );
- }
- else if ( type == "bool" )
- {
- query += QString( ",boolout(%1)" ).arg( quotedIdentifier( fieldname ) );
- }
- else if ( type == "geometry" )
- {
- query += QString( ",asewkt(%1)" ).arg( quotedIdentifier( fieldname ) );
- }
- else
- {
- query += "," + quotedIdentifier( fieldname ) + "::text";
- }
+ query += "," + fieldExpression( fld );
}
query += " from " + mSchemaTableName;
@@ -1698,13 +1702,13 @@
if ( sqlWhereClause.isEmpty() )
{
sql = QString( "select distinct %1 from %2 order by %1" )
- .arg( quotedIdentifier( fld.name() ) )
+ .arg( fieldExpression( fld ) )
.arg( mSchemaTableName );
}
else
{
sql = QString( "select distinct %1 from %2 where %3 order by %1" )
- .arg( quotedIdentifier( fld.name() ) )
+ .arg( fieldExpression( fld ) )
.arg( mSchemaTableName )
.arg( sqlWhereClause );
}
@@ -1718,7 +1722,7 @@
if ( PQresultStatus( res ) == PGRES_TUPLES_OK )
{
for ( int i = 0; i < PQntuples( res ); i++ )
- uniqueValues.append( QString::fromUtf8( PQgetvalue( res, i, 0 ) ) );
+ uniqueValues.append( convertValue( fld.type(), QString::fromUtf8( PQgetvalue( res, i, 0 ) ) ) );
}
}
catch ( PGFieldNotFound )
@@ -1865,13 +1869,13 @@
if ( sqlWhereClause.isEmpty() )
{
sql = QString( "select max(%1) from %2" )
- .arg( quotedIdentifier( fld.name() ) )
+ .arg( fieldExpression( fld ) )
.arg( mSchemaTableName );
}
else
{
sql = QString( "select max(%1) from %2 where %3" )
- .arg( quotedIdentifier( fld.name() ) )
+ .arg( fieldExpression( fld ) )
.arg( mSchemaTableName )
.arg( sqlWhereClause );
}
Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.h
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.h 2009-10-08 13:03:14 UTC (rev 11770)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.h 2009-10-08 14:28:26 UTC (rev 11771)
@@ -341,6 +341,10 @@
*/
QString quotedValue( QString value ) const;
+ /** expression to retrieve value
+ */
+ QString fieldExpression( const QgsField &fld ) const;
+
/** Load the field list
*/
void loadFields();
More information about the QGIS-commit
mailing list