Merge branch 'master' into gsoc-crundel

This commit is contained in:
Dane Springmeyer 2011-11-09 17:49:20 -08:00
commit aff0fdc821
3 changed files with 84 additions and 42 deletions

View file

@ -37,6 +37,7 @@
#include <boost/make_shared.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/operations.hpp>
// sqlite
extern "C" {
@ -130,16 +131,17 @@ public:
int flags;
#endif
bool existed = boost::filesystem::exists(index_db);
boost::shared_ptr<sqlite_connection> ds = boost::make_shared<sqlite_connection>(index_db,flags);
ds->execute("PRAGMA synchronous=OFF");
ds->execute("BEGIN TRANSACTION");
// first drop the index if it already exists
std::ostringstream spatial_index_drop_sql;
spatial_index_drop_sql << "DROP TABLE IF EXISTS " << index_table;
ds->execute(spatial_index_drop_sql.str());
ds->execute("PRAGMA synchronous=OFF");
ds->execute("BEGIN TRANSACTION");
// create the spatial index
std::ostringstream create_idx;
create_idx << "create virtual table "
@ -156,6 +158,9 @@ public:
prepared_index_statement ps(ds,insert_idx.str());
bool one_success = false;
try
{
bool first = true;
while (rs->is_valid() && rs->step_next())
{
@ -206,11 +211,39 @@ public:
}
ps.step_next();
one_success = true;
}
}
}
}
catch (mapnik::datasource_exception const& ex)
{
ds->execute("ROLLBACK");
if (!existed)
{
try
{
boost::filesystem::remove(index_db);
}
catch (...) {};
}
throw mapnik::datasource_exception(ex.what());
}
if (one_success)
{
ds->execute("COMMIT");
}
else if (!existed)
{
ds->execute("ROLLBACK");
try
{
boost::filesystem::remove(index_db);
}
catch (...) {};
}
}
static bool detect_extent(boost::shared_ptr<sqlite_connection> ds,
bool has_spatial_index,

BIN
tests/data/sqlite/empty.db Normal file

Binary file not shown.

View file

@ -196,6 +196,15 @@ if 'sqlite' in mapnik2.DatasourceCache.instance().plugin_names():
eq_(feature['rowid'],1)
eq_(feature['fips'],u'AC')
def test_empty_db():
ds = mapnik2.SQLite(file='../data/sqlite/empty.db',
table='empty',
)
fs = ds.featureset()
feature = fs.next()
eq_(feature,None)
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]