Skip to content

Commit 2c3f044

Browse files
committed
[WFS provider] Better and translatable error message in case of SQL parsing error
1 parent 9b92100 commit 2c3f044

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/providers/wfs/qgswfsprovider.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,28 @@ bool QgsWFSProvider::processSQL( const QString& sqlString, QString& errorMsg, QS
278278
QgsSQLStatement sql( sqlString );
279279
if ( sql.hasParserError() )
280280
{
281-
errorMsg = tr( "SQL query is invalid: %1" ).arg( sql.parserErrorString() );
281+
QString parserErrorString( sql.parserErrorString() );
282+
QStringList parts( parserErrorString.split( "," ) );
283+
parserErrorString = "";
284+
Q_FOREACH ( const QString& part, parts )
285+
{
286+
QString newPart( part );
287+
if ( part == "syntax error" )
288+
newPart = tr( "Syntax error." );
289+
else if ( part == " unexpected $end" )
290+
newPart = tr( "Missing content at end of string." );
291+
else if ( part.startsWith( " unexpected " ) )
292+
newPart = tr( "%1 is unexpected." ).arg( part.mid( QString( " unexpected " ).size() ) );
293+
else if ( part.startsWith( " expecting " ) )
294+
newPart = tr( "%1 is expected instead." ).arg( part.mid( QString( " expecting " ).size() ) );
295+
if ( !parserErrorString.isEmpty() )
296+
parserErrorString += " ";
297+
parserErrorString += newPart;
298+
}
299+
parserErrorString.replace( " or ", tr( "%1 or %2" ).arg( "", "" ) );
300+
parserErrorString.replace( "COMMA", tr( "comma" ) );
301+
parserErrorString.replace( "IDENTIFIER", tr( "an identifier" ) );
302+
errorMsg = tr( "SQL query is invalid: %1" ).arg( parserErrorString );
282303
return false;
283304
}
284305
if ( !sql.doBasicValidationChecks( errorMsg ) )

0 commit comments

Comments
 (0)