From 4555e117e7d36ce233e443fba6653379f29d79d0 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Thu, 20 Nov 2014 18:30:20 +0100 Subject: [PATCH 1/3] Add test case for missing columns in SQLite datasource. Refs #2579 --- tests/python_tests/sqlite_test.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/python_tests/sqlite_test.py b/tests/python_tests/sqlite_test.py index f384fccae..9cbfd1374 100644 --- a/tests/python_tests/sqlite_test.py +++ b/tests/python_tests/sqlite_test.py @@ -368,6 +368,25 @@ if 'sqlite' in mapnik.DatasourceCache.plugin_names(): eq_(len(feat.geometries()),1) eq_(feat.geometries()[0].to_wkt(),'Point(0 0)') + def test_db_with_one_untyped_column(): + # form up an in-memory test db + wkb = '010100000000000000000000000000000000000000' + ds = mapnik.SQLite(file=':memory:', + table='test1', + initdb=''' + create table test1 (geometry BLOB, untyped); + insert into test1 values (x'%s', 'untyped'); + ''' % wkb, + extent='-180,-60,180,60', + use_spatial_index=False, + key_field='rowid' + ) + + # ensure the untyped column is found + eq_(len(ds.fields()),2) + eq_(ds.fields(),['rowid', 'untyped']) + eq_(ds.field_types(),['int', 'str']) + def test_that_64bit_int_fields_work(): ds = mapnik.SQLite(file='../data/sqlite/64bit_int.sqlite', From 07a07c6268d14adb5793b45abd462c03f1ea4ad9 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Thu, 20 Nov 2014 18:48:31 +0100 Subject: [PATCH 2/3] Default to string type when column type could not be determined. Refs #2579 --- plugins/input/sqlite/sqlite_utils.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/input/sqlite/sqlite_utils.hpp b/plugins/input/sqlite/sqlite_utils.hpp index 06832f6e0..060f6ad33 100644 --- a/plugins/input/sqlite/sqlite_utils.hpp +++ b/plugins/input/sqlite/sqlite_utils.hpp @@ -700,6 +700,7 @@ public: { // "Column Affinity" says default to "Numeric" but for now we pass.. //desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double)); + desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String)); #ifdef MAPNIK_LOG // Do not fail when we specify geometry_field in XML file @@ -707,8 +708,9 @@ public: { MAPNIK_LOG_DEBUG(sqlite) << "Column '" << std::string(fld_name) - << "' unhandled due to unknown type: " - << fld_type; + << "' unhandled due to unknown type: '" + << fld_type + << "', using String"; } #endif } From e7cf55222c6edd72b9ee155a3cc77ba23befe59f Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Thu, 20 Nov 2014 18:58:20 +0100 Subject: [PATCH 3/3] Add test case for missing columns in SQLite datasource, using subquery. Refs #2579 --- tests/python_tests/sqlite_test.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/python_tests/sqlite_test.py b/tests/python_tests/sqlite_test.py index 9cbfd1374..270f350cd 100644 --- a/tests/python_tests/sqlite_test.py +++ b/tests/python_tests/sqlite_test.py @@ -387,6 +387,25 @@ if 'sqlite' in mapnik.DatasourceCache.plugin_names(): eq_(ds.fields(),['rowid', 'untyped']) eq_(ds.field_types(),['int', 'str']) + def test_db_with_one_untyped_column_using_subquery(): + # form up an in-memory test db + wkb = '010100000000000000000000000000000000000000' + ds = mapnik.SQLite(file=':memory:', + table='(SELECT rowid, geometry, untyped FROM test1)', + initdb=''' + create table test1 (geometry BLOB, untyped); + insert into test1 values (x'%s', 'untyped'); + ''' % wkb, + extent='-180,-60,180,60', + use_spatial_index=False, + key_field='rowid' + ) + + # ensure the untyped column is found + eq_(len(ds.fields()),3) + eq_(ds.fields(),['rowid', 'untyped', 'rowid']) + eq_(ds.field_types(),['int', 'str', 'int']) + def test_that_64bit_int_fields_work(): ds = mapnik.SQLite(file='../data/sqlite/64bit_int.sqlite',