Skip to content

Commit

Permalink
Consider srid to avoid mixed geometry errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 28, 2021
1 parent 385f73e commit a0f0823
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1239,13 +1239,6 @@ QString QgsPostgresConn::quotedValue( const QVariant &value )
case QVariant::List:
return quotedList( value.toList() );

case QVariant::UserType:
if ( value.canConvert<QgsGeometry>() )
{
QgsGeometry geom = value.value<QgsGeometry>();
return QString( "ST_GeomFromText('%1')" ).arg( geom.asWkt() );
}

case QVariant::Double:
case QVariant::String:
default:
Expand Down
7 changes: 7 additions & 0 deletions src/providers/postgres/qgspostgresexpressioncompiler.cpp
Expand Up @@ -44,6 +44,13 @@ QString QgsPostgresExpressionCompiler::quotedValue( const QVariant &value, bool
case QVariant::Double:
return value.toString();

case QVariant::UserType:
if ( value.canConvert<QgsGeometry>() )
{
QgsGeometry geom = value.value<QgsGeometry>();
return QString( "ST_GeomFromText('%1',%2)" ).arg( geom.asWkt() ).arg( mRequestedSrid.isEmpty() ? mDetectedSrid : mRequestedSrid );
}

default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/providers/testqgspostgresexpressioncompiler.cpp
Expand Up @@ -54,7 +54,7 @@ void TestQgsPostgresExpressionCompiler::testGeometryFromWkt()
QgsSqlExpressionCompiler::Result r = compiler.compile( &exp );
QCOMPARE( r, QgsSqlExpressionCompiler::Complete );
QString sql = compiler.result();
QCOMPARE( sql, QStringLiteral( "ST_Intersects(\"geom\",ST_GeomFromText('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))'))" ) );
QCOMPARE( sql, QStringLiteral( "ST_Intersects(\"geom\",ST_GeomFromText('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))',4326))" ) );
}

QGSTEST_MAIN( TestQgsPostgresExpressionCompiler )
Expand Down

0 comments on commit a0f0823

Please sign in to comment.