Skip to content

Commit

Permalink
Remove column name validation from virtual layers queries
Browse files Browse the repository at this point in the history
The query already went through the Sqlite query parser. So why not
trusting it? This was in the way of group by queries with count(*)
in the output fields.
  • Loading branch information
Patrick Valsecchi committed Feb 26, 2016
1 parent 4a1cc33 commit 3a714cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
19 changes: 0 additions & 19 deletions src/providers/virtual/qgsvirtuallayerqueryparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ namespace QgsVirtualLayerQueryParser
return defs;
}

bool isValidColumnName( const QString& columnName )
{
// identifier name with possible accents
static QRegExp columnNameRx( "[a-zA-Z_\x80-\xFF][a-zA-Z0-9_\x80-\xFF]*" );

return columnNameRx.exactMatch( columnName );
}

// set the type of the column type, given its text representation
void setColumnDefType( const QString& columnType, ColumnDef& d )
{
Expand Down Expand Up @@ -172,17 +164,6 @@ namespace QgsVirtualLayerQueryParser
{
QString columnName = q.columnText( 1 );

if ( !isValidColumnName( columnName ) )
{
qWarning() << "Invalid name: " << columnName;
hasInvalidName = true;

// add an unnamed column
ColumnDef d;
tableDef << d;
break;
}

columns << columnName;

QString columnType = q.columnText( 2 );
Expand Down
7 changes: 4 additions & 3 deletions tests/src/python/test_provider_virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,11 @@ def test_sql3(self):
QgsMapLayerRegistry.instance().addMapLayer(l2)

# unnamed column
query = QUrl.toPercentEncoding("SELECT 42")
query = QUrl.toPercentEncoding("SELECT count(*)")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), False)
self.assertEqual("Result column #1 has no name" in l4.dataProvider().error().message(), True)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().fields().at(0).name(), "count(*)")
self.assertEqual(l4.dataProvider().fields().at(0).type(), QVariant.Int)

def test_sql_field_types(self):
query = QUrl.toPercentEncoding("SELECT 42 as t, 'ok'||'ok' as t2, GeomFromText('') as t3, 3.14*2 as t4")
Expand Down

0 comments on commit 3a714cc

Please sign in to comment.