sqlite: return success or failure from rtree indexing function and report available tables if the pragma table_info() fails
This commit is contained in:
parent
ef23332622
commit
bdc726a525
2 changed files with 61 additions and 10 deletions
|
@ -197,12 +197,19 @@ void sqlite_datasource::bind() const
|
|||
if (! found_table)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "Sqlite Plugin: could not query table '" << geometry_table_ << "' ";
|
||||
if (using_subquery_) s << " from subquery '" << table_ << "' ";
|
||||
s << "using 'PRAGMA table_info(" << geometry_table_ << ")' ";
|
||||
s << "Sqlite Plugin: could not query table '" << geometry_table_ << "'";
|
||||
if (using_subquery_)
|
||||
{
|
||||
s << " from subquery '" << table_ << "'";
|
||||
}
|
||||
|
||||
std::string sq_err = std::string(sqlite3_errmsg(*(*dataset_)));
|
||||
if (sq_err != "unknown error") s << ": " << sq_err;
|
||||
// report get available tables
|
||||
std::vector<std::string> tables;
|
||||
sqlite_utils::get_tables(dataset_,tables);
|
||||
if (tables.size() > 0)
|
||||
{
|
||||
s << " (available tables for " << dataset_name_ << " are: '" << boost::algorithm::join(tables, ", ") << "')";
|
||||
}
|
||||
|
||||
throw datasource_exception(s.str());
|
||||
}
|
||||
|
@ -228,7 +235,6 @@ void sqlite_datasource::bind() const
|
|||
{
|
||||
dataset_->execute("attach database '" + index_db + "' as " + index_table_);
|
||||
}
|
||||
|
||||
has_spatial_index_ = sqlite_utils::has_rtree(index_table_,dataset_);
|
||||
}
|
||||
|
||||
|
@ -246,8 +252,10 @@ void sqlite_datasource::bind() const
|
|||
<< " FROM ("
|
||||
<< geometry_table_ << ")";
|
||||
boost::shared_ptr<sqlite_resultset> rs = dataset_->execute_query(query.str());
|
||||
sqlite_utils::create_spatial_index(index_db,index_table_,rs,extent_);
|
||||
extent_initialized_ = true;
|
||||
if (sqlite_utils::create_spatial_index(index_db,index_table_,rs,extent_))
|
||||
{
|
||||
extent_initialized_ = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -75,6 +75,47 @@ public:
|
|||
//{
|
||||
return file + ".index";
|
||||
//}
|
||||
}
|
||||
|
||||
static void get_tables(boost::shared_ptr<sqlite_connection> ds,
|
||||
std::vector<std::string> & tables)
|
||||
{
|
||||
std::ostringstream sql;
|
||||
// todo handle finding tables from attached db's
|
||||
sql << " SELECT name FROM sqlite_master"
|
||||
<< " WHERE type IN ('table','view')"
|
||||
<< " AND name NOT LIKE 'sqlite_%'"
|
||||
<< " AND name NOT LIKE 'idx_%'"
|
||||
<< " AND name NOT LIKE '%geometry_columns%'"
|
||||
<< " AND name NOT LIKE '%ref_sys%'"
|
||||
<< " UNION ALL"
|
||||
<< " SELECT name FROM sqlite_temp_master"
|
||||
<< " WHERE type IN ('table','view')"
|
||||
<< " ORDER BY 1";
|
||||
sqlite3_stmt* stmt = 0;
|
||||
const int rc = sqlite3_prepare_v2 (*(*ds), sql.str().c_str(), -1, &stmt, 0);
|
||||
std::clog << "hey\n";
|
||||
if (rc == SQLITE_OK)
|
||||
{
|
||||
std::clog << "a\n";
|
||||
boost::shared_ptr<sqlite_resultset> rs = boost::make_shared<sqlite_resultset>(stmt);
|
||||
while (rs->is_valid() && rs->step_next())
|
||||
{
|
||||
std::clog << "b\n";
|
||||
const int type_oid = rs->column_type(0);
|
||||
if (type_oid == SQLITE_TEXT)
|
||||
{
|
||||
std::clog << "c\n";
|
||||
const char * data = rs->column_text(0);
|
||||
if (data)
|
||||
{
|
||||
|
||||
std::clog << "d\n";
|
||||
tables.push_back(std::string(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void query_extent(boost::shared_ptr<sqlite_resultset> rs,
|
||||
|
@ -111,7 +152,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static void create_spatial_index(std::string const& index_db,
|
||||
static bool create_spatial_index(std::string const& index_db,
|
||||
std::string const& index_table,
|
||||
boost::shared_ptr<sqlite_resultset> rs,
|
||||
mapnik::box2d<double>& extent)
|
||||
|
@ -123,7 +164,7 @@ public:
|
|||
*/
|
||||
|
||||
if (!rs->is_valid())
|
||||
return;
|
||||
return false;
|
||||
|
||||
#if SQLITE_VERSION_NUMBER >= 3005000
|
||||
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
|
||||
|
@ -233,6 +274,7 @@ public:
|
|||
if (one_success)
|
||||
{
|
||||
ds->execute("COMMIT");
|
||||
return true;
|
||||
}
|
||||
else if (!existed)
|
||||
{
|
||||
|
@ -243,6 +285,7 @@ public:
|
|||
}
|
||||
catch (...) {};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool detect_extent(boost::shared_ptr<sqlite_connection> ds,
|
||||
|
|
Loading…
Reference in a new issue