@@ -1814,31 +1814,69 @@ QString QgsPostgresProvider::paramValue( QString fieldValue, const QString &defa
18141814
18151815QString QgsPostgresProvider::geomParam ( int offset ) const
18161816{
1817+ // TODO: retrive these at construction time
1818+ QString toponame;
1819+ long layer_id;
1820+
1821+ if ( mSpatialColType == sctTopoGeometry )
1822+ {
1823+ QString sql = QString ( " SELECT t.name, l.layer_id FROM topology.layer l, topology.topology t "
1824+ " WHERE l.topology_id = t.id AND l.schema_name=%1 "
1825+ " AND l.table_name=%2 AND l.feature_column=%3" )
1826+ .arg ( quotedValue ( mSchemaName ) )
1827+ .arg ( quotedValue ( mTableName ) )
1828+ .arg ( quotedValue ( mGeometryColumn ) );
1829+ QgsPostgresResult result = mConnectionRO ->PQexec ( sql );
1830+ if ( result.PQresultStatus () != PGRES_TUPLES_OK )
1831+ {
1832+ throw PGException ( result ); // we should probably not do this
1833+ }
1834+ if ( result.PQntuples () < 1 )
1835+ {
1836+ QgsMessageLog::logMessage ( tr ( " Could not find topology of layer %1.%2.%3" )
1837+ .arg ( quotedValue ( mSchemaName ) )
1838+ .arg ( quotedValue ( mTableName ) )
1839+ .arg ( quotedValue ( mGeometryColumn ) ),
1840+ tr ( " PostGIS" ) );
1841+ }
1842+ toponame = result.PQgetvalue ( 0 , 0 );
1843+ layer_id = result.PQgetvalue ( 0 , 1 ).toLong ();
1844+
1845+ }
1846+
18171847 QString geometry;
18181848
18191849 bool forceMulti = false ;
18201850
1821- switch ( geometryType () )
1822- {
1823- case QGis::WKBPoint:
1824- case QGis::WKBLineString:
1825- case QGis::WKBPolygon:
1826- case QGis::WKBPoint25D:
1827- case QGis::WKBLineString25D:
1828- case QGis::WKBPolygon25D:
1829- case QGis::WKBUnknown:
1830- case QGis::WKBNoGeometry:
1831- forceMulti = false ;
1832- break ;
1851+ if ( mSpatialColType != sctTopoGeometry )
1852+ {
1853+ switch ( geometryType () )
1854+ {
1855+ case QGis::WKBPoint:
1856+ case QGis::WKBLineString:
1857+ case QGis::WKBPolygon:
1858+ case QGis::WKBPoint25D:
1859+ case QGis::WKBLineString25D:
1860+ case QGis::WKBPolygon25D:
1861+ case QGis::WKBUnknown:
1862+ case QGis::WKBNoGeometry:
1863+ forceMulti = false ;
1864+ break ;
18331865
1834- case QGis::WKBMultiPoint:
1835- case QGis::WKBMultiLineString:
1836- case QGis::WKBMultiPolygon:
1837- case QGis::WKBMultiPoint25D:
1838- case QGis::WKBMultiLineString25D:
1839- case QGis::WKBMultiPolygon25D:
1840- forceMulti = true ;
1841- break ;
1866+ case QGis::WKBMultiPoint:
1867+ case QGis::WKBMultiLineString:
1868+ case QGis::WKBMultiPolygon:
1869+ case QGis::WKBMultiPoint25D:
1870+ case QGis::WKBMultiLineString25D:
1871+ case QGis::WKBMultiPolygon25D:
1872+ forceMulti = true ;
1873+ break ;
1874+ }
1875+ }
1876+
1877+ if ( mSpatialColType == sctTopoGeometry )
1878+ {
1879+ geometry += QString ( " toTopoGeom(" );
18421880 }
18431881
18441882 if ( forceMulti )
@@ -1857,6 +1895,13 @@ QString QgsPostgresProvider::geomParam( int offset ) const
18571895 geometry += " )" ;
18581896 }
18591897
1898+ if ( mSpatialColType == sctTopoGeometry )
1899+ {
1900+ geometry += QString ( " ,%1,%2)" )
1901+ .arg ( quotedValue (toponame) )
1902+ .arg ( layer_id );
1903+ }
1904+
18601905 return geometry;
18611906}
18621907
0 commit comments