Skip to content

Commit 8fc5381

Browse files
author
Hugo Mercier
committed
Merge pull request #2845 from pvalsecc/column_name_validation
Remove column name validation from virtual layers queries
2 parents 58c85bb + 3a714cc commit 8fc5381

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

src/providers/virtual/qgsvirtuallayerqueryparser.cpp

-19
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

+4-3
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)