Skip to content

Commit 3a714cc

Browse files
author
Patrick Valsecchi
committedFeb 26, 2016
Remove column name validation from virtual layers queries
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.
1 parent 4a1cc33 commit 3a714cc

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed
 

‎src/providers/virtual/qgsvirtuallayerqueryparser.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ namespace QgsVirtualLayerQueryParser
9393
return defs;
9494
}
9595

96-
bool isValidColumnName( const QString& columnName )
97-
{
98-
// identifier name with possible accents
99-
static QRegExp columnNameRx( "[a-zA-Z_\x80-\xFF][a-zA-Z0-9_\x80-\xFF]*" );
100-
101-
return columnNameRx.exactMatch( columnName );
102-
}
103-
10496
// set the type of the column type, given its text representation
10597
void setColumnDefType( const QString& columnType, ColumnDef& d )
10698
{
@@ -172,17 +164,6 @@ namespace QgsVirtualLayerQueryParser
172164
{
173165
QString columnName = q.columnText( 1 );
174166

175-
if ( !isValidColumnName( columnName ) )
176-
{
177-
qWarning() << "Invalid name: " << columnName;
178-
hasInvalidName = true;
179-
180-
// add an unnamed column
181-
ColumnDef d;
182-
tableDef << d;
183-
break;
184-
}
185-
186167
columns << columnName;
187168

188169
QString columnType = q.columnText( 2 );

‎tests/src/python/test_provider_virtual.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,11 @@ def test_sql3(self):
508508
QgsMapLayerRegistry.instance().addMapLayer(l2)
509509

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.