Skip to content
Permalink
Browse files

Merge pull request #2845 from pvalsecc/column_name_validation

Remove column name validation from virtual layers queries
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Feb 26, 2016
2 parents 58c85bb + 3a714cc commit 8fc5381b7209bbc168cec20bc333d061cdf09372
Showing with 4 additions and 22 deletions.
  1. +0 −19 src/providers/virtual/qgsvirtuallayerqueryparser.cpp
  2. +4 −3 tests/src/python/test_provider_virtual.py
@@ -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 )
{
@@ -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 );
@@ -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")

0 comments on commit 8fc5381

Please sign in to comment.
You can’t perform that action at this time.