Skip to content

Commit ac1fbfa

Browse files
author
jef
committed
update postgis support to use st_ variants instead of old deprecated
(and now removed) versions. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15023 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7c2d6f0 commit ac1fbfa

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/app/postgres/qgspgsourceselect.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
328328

329329
if ( typeName == "POINT" )
330330
{
331-
geomFilter = QString( "GeometryType(\"%1\") IN ('POINT','MULTIPOINT')" ).arg( geomColumnName );
331+
geomFilter = QString( "st_geometrytype(\"%1\") IN ('POINT','MULTIPOINT')" ).arg( geomColumnName );
332332
}
333333
else if ( typeName == "LINESTRING" )
334334
{
335-
geomFilter = QString( "GeometryType(\"%1\") IN ('LINESTRING','MULTILINESTRING')" ).arg( geomColumnName );
335+
geomFilter = QString( "st_geometrytype(\"%1\") IN ('LINESTRING','MULTILINESTRING')" ).arg( geomColumnName );
336336
}
337337
else if ( typeName == "POLYGON" )
338338
{
339-
geomFilter = QString( "GeometryType(\"%1\") IN ('POLYGON','MULTIPOLYGON')" ).arg( geomColumnName );
339+
geomFilter = QString( "st_geometrytype(\"%1\") IN ('POLYGON','MULTIPOLYGON')" ).arg( geomColumnName );
340340
}
341341

342342
if ( !geomFilter.isEmpty() && !sql.contains( geomFilter ) )
@@ -941,9 +941,9 @@ void QgsGeomColumnTypeThread::getLayerTypes()
941941
{
942942
QString query = QString( "select distinct "
943943
"case"
944-
" when geometrytype(%1) IN ('POINT','MULTIPOINT') THEN 'POINT'"
945-
" when geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
946-
" when geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
944+
" when st_geometrytype(%1) IN ('POINT','MULTIPOINT') THEN 'POINT'"
945+
" when st_geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
946+
" when st_geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
947947
" end "
948948
"from " ).arg( "\"" + columns[i] + "\"" );
949949
if ( mUseEstimatedMetadata )

src/plugins/spit/qgsshapefile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ bool QgsShapeFile::insertLayer( QString dbname, QString schema, QString primary_
435435
values += val;
436436
}
437437
query += "," + QgsPgUtil::quotedIdentifier( geom_col );
438-
values += QString( ",GeometryFromText(%1,%2)" )
438+
values += QString( ",st_geometryfromtext(%1,%2)" )
439439
.arg( QgsPgUtil::quotedValue( geometry ) )
440440
.arg( srid );
441441

src/providers/postgres/qgspostgresprovider.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,14 @@ void QgsPostgresProvider::select( QgsAttributeList fetchAttributes, QgsRectangle
569569
{
570570
// Contributed by #qgis irc "creeping"
571571
// This version actually invokes PostGIS's use of spatial indexes
572-
whereClause = QString( "%1 && setsrid('BOX3D(%2)'::box3d,%3) and intersects(%1,setsrid('BOX3D(%2)'::box3d,%3))" )
572+
whereClause = QString( "%1 && st_setsrid('BOX3D(%2)'::box3d,%3) and st_intersects(%1,st_setsrid('BOX3D(%2)'::box3d,%3))" )
573573
.arg( quotedIdentifier( geometryColumn ) )
574574
.arg( rect.asWktCoordinates() )
575575
.arg( srid );
576576
}
577577
else
578578
{
579-
whereClause = QString( "%1 && setsrid('BOX3D(%2)'::box3d,%3)" )
579+
whereClause = QString( "%1 && st_setsrid('BOX3D(%2)'::box3d,%3)" )
580580
.arg( quotedIdentifier( geometryColumn ) )
581581
.arg( rect.asWktCoordinates() )
582582
.arg( srid );
@@ -2032,12 +2032,12 @@ bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList& enumValues, c
20322032
enumValues.clear();
20332033

20342034
//is it a domain type with a check constraint?
2035-
QString domainSql = QString( "SELECT domain_name from information_schema.columns where table_name = %1 and column_name = %2" ).arg( quotedValue( mTableName ) ).arg( quotedValue( attributeName ) );
2035+
QString domainSql = QString( "SELECT domain_name from information_schema.columns where table_name=%1 and column_name=%2" ).arg( quotedValue( mTableName ) ).arg( quotedValue( attributeName ) );
20362036
Result domainResult = connectionRO->PQexec( domainSql );
20372037
if ( PQresultStatus( domainResult ) == PGRES_TUPLES_OK && PQntuples( domainResult ) > 0 )
20382038
{
20392039
//a domain type
2040-
QString domainCheckDefinitionSql = QString( "SELECT consrc FROM pg_constraint where conname = (SELECT constraint_name FROM information_schema.domain_constraints WHERE domain_name = %1)" ).arg( quotedValue( PQgetvalue( domainResult, 0, 0 ) ) );
2040+
QString domainCheckDefinitionSql = QString( "SELECT consrc FROM pg_constraint where conname=(SELECT constraint_name FROM information_schema.domain_constraints WHERE domain_name=%1)" ).arg( quotedValue( PQgetvalue( domainResult, 0, 0 ) ) );
20412041
Result domainCheckRes = connectionRO->PQexec( domainCheckDefinitionSql );
20422042
if ( PQresultStatus( domainCheckRes ) == PGRES_TUPLES_OK && PQntuples( domainCheckRes ) > 0 )
20432043
{
@@ -2048,7 +2048,7 @@ bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList& enumValues, c
20482048
//normally, postgresql creates that if the contstraint has been specified as 'VALUE in ('a', 'b', 'c', 'd')
20492049

20502050
//todo: ANY must occure before ARRAY
2051-
int anyPos = checkDefinition.indexOf( "VALUE = ANY" );
2051+
int anyPos = checkDefinition.indexOf( "VALUE=ANY" );
20522052
int arrayPosition = checkDefinition.lastIndexOf( "ARRAY[" );
20532053
int closingBracketPos = checkDefinition.indexOf( "]", arrayPosition + 6 );
20542054

@@ -2274,7 +2274,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
22742274
if ( !geometryColumn.isNull() )
22752275
{
22762276
insert += quotedIdentifier( geometryColumn );
2277-
values += QString( "GeomFromWKB($%1%2,%3)" )
2277+
values += QString( "st_geomfromwkb($%1%2,%3)" )
22782278
.arg( offset )
22792279
.arg( connectionRW->useWkbHex() ? "" : "::bytea" )
22802280
.arg( srid );
@@ -2346,7 +2346,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
23462346
}
23472347
else if ( fit->typeName() == "geometry" )
23482348
{
2349-
values += QString( "%1geomfromewkt(%2)" ).arg( delim ).arg( quotedValue( it->toString() ) );
2349+
values += QString( "%1st_geomfromewkt(%2)" ).arg( delim ).arg( quotedValue( it->toString() ) );
23502350
}
23512351
else if ( fit->typeName() == "geography" )
23522352
{
@@ -2362,7 +2362,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
23622362
// value is not unique => add parameter
23632363
if ( fit->typeName() == "geometry" )
23642364
{
2365-
values += QString( "%1geomfromewkt($%2)" ).arg( delim ).arg( defaultValues.size() + offset );
2365+
values += QString( "%1st_geomfromewkt($%2)" ).arg( delim ).arg( defaultValues.size() + offset );
23662366
}
23672367
else if ( fit->typeName() == "geography" )
23682368
{
@@ -2632,7 +2632,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
26322632
else
26332633
first = false;
26342634

2635-
sql += QString( fld.typeName() == "geometry" ? "%1=geomfromewkt(%2)" :
2635+
sql += QString( fld.typeName() == "geometry" ? "%1=st_geomfromewkt(%2)" :
26362636
fld.typeName() == "geography" ? "%1=st_geographyfromewkt(%2)" :
26372637
"%1=%2" )
26382638
.arg( quotedIdentifier( fld.name() ) )
@@ -2695,7 +2695,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
26952695
// Start the PostGIS transaction
26962696
connectionRW->PQexecNR( "BEGIN" );
26972697

2698-
QString update = QString( "UPDATE %1 SET %2=GeomFromWKB($1%3,%4) WHERE %5=$2" )
2698+
QString update = QString( "UPDATE %1 SET %2=st_geomfromwkb($1%3,%4) WHERE %5=$2" )
26992699
.arg( mQuery )
27002700
.arg( quotedIdentifier( geometryColumn ) )
27012701
.arg( connectionRW->useWkbHex() ? "" : "::bytea" )
@@ -2879,7 +2879,7 @@ QgsRectangle QgsPostgresProvider::extent()
28792879
{
28802880
if ( QString::fromUtf8( PQgetvalue( result, 0, 0 ) ).toInt() > 0 )
28812881
{
2882-
sql = QString( "select estimated_extent(%1,%2,%3)" )
2882+
sql = QString( "select st_estimated_extent(%1,%2,%3)" )
28832883
.arg( quotedValue( mSchemaName ) )
28842884
.arg( quotedValue( mTableName ) )
28852885
.arg( quotedValue( geometryColumn ) );
@@ -2907,7 +2907,7 @@ QgsRectangle QgsPostgresProvider::extent()
29072907

29082908
if ( ext.isEmpty() )
29092909
{
2910-
sql = QString( "select extent(%1) from %2" )
2910+
sql = QString( "select st_extent(%1) from %2" )
29112911
.arg( quotedIdentifier( geometryColumn ) )
29122912
.arg( mQuery );
29132913

@@ -3125,7 +3125,7 @@ bool QgsPostgresProvider::getGeometryDetails()
31253125
// Didn't find what we need in the geometry_columns table, so
31263126
// get stuff from the relevant column instead. This may (will?)
31273127
// fail if there is no data in the relevant table.
3128-
sql = QString( "select srid(%1), geometrytype(%1) from %2" )
3128+
sql = QString( "select st_srid(%1),st_geometrytype(%1) from %2" )
31293129
.arg( quotedIdentifier( geometryColumn ) )
31303130
.arg( mQuery );
31313131

@@ -3154,9 +3154,9 @@ bool QgsPostgresProvider::getGeometryDetails()
31543154
// check to see if there is a unique geometry type
31553155
sql = QString( "select distinct "
31563156
"case"
3157-
" when geometrytype(%1) IN ('POINT','MULTIPOINT') THEN 'POINT'"
3158-
" when geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
3159-
" when geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
3157+
" when st_geometrytype(%1) IN ('POINT','MULTIPOINT') THEN 'POINT'"
3158+
" when st_geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
3159+
" when st_geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
31603160
" end "
31613161
"from " ).arg( quotedIdentifier( geometryColumn ) );
31623162
if ( mUseEstimatedMetadata )

0 commit comments

Comments
 (0)