Skip to content

Commit

Permalink
Quote layer name in virtual layers creation
Browse files Browse the repository at this point in the history
Fixes #45347
  • Loading branch information
elpaso authored and nyalldawson committed Oct 1, 2021
1 parent b54001c commit e0e38cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/providers/virtual/qgsvirtuallayerprovider.cpp
Expand Up @@ -469,7 +469,7 @@ bool QgsVirtualLayerProvider::createIt()

void QgsVirtualLayerProvider::createVirtualTable( QgsVectorLayer *vlayer, const QString &vname )
{
const QString createStr = QStringLiteral( "DROP TABLE IF EXISTS \"%1\"; CREATE VIRTUAL TABLE \"%1\" USING QgsVLayer(%2);" ).arg( vname, vlayer->id() );
const QString createStr = QStringLiteral( "DROP TABLE IF EXISTS \"%1\"; CREATE VIRTUAL TABLE \"%1\" USING QgsVLayer('%2');" ).arg( vname, vlayer->id() );
Sqlite::Query::exec( mSqlite.get(), createStr );
}

Expand Down
13 changes: 13 additions & 0 deletions tests/src/python/test_provider_virtual.py
Expand Up @@ -1353,6 +1353,19 @@ def test_int64(self):
feat = next(vl.getFeatures())
self.assertEqual(feat.attribute('fldlonglong'), bigint)

def test_layer_starting_with_digit(self):
"""Test issue GH #45347"""

project = QgsProject.instance()
project.clear()
layer = QgsVectorLayer('Point?crs=epsg:4326&field=fid:integer', '1_layer', 'memory')
project.addMapLayers([layer])

df = QgsVirtualLayerDefinition()
df.setQuery('select * from "1_layer"')
vl = QgsVectorLayer(df.toString(), "1_layer_virtual", "virtual")
self.assertTrue(vl.isValid())


if __name__ == '__main__':
unittest.main()

0 comments on commit e0e38cc

Please sign in to comment.