Skip to content

Commit

Permalink
Merge pull request #2845 from pvalsecc/column_name_validation
Browse files Browse the repository at this point in the history
Remove column name validation from virtual layers queries
  • Loading branch information
Hugo Mercier committed Feb 26, 2016
2 parents 58c85bb + 3a714cc commit 8fc5381
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
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
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 8fc5381

Please sign in to comment.