From 32248bf576f720789c99c1c5901280be0d4fe3ca Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 19 Sep 2012 18:15:49 +0100 Subject: [PATCH] Support string-list properties in the cache. Not used yet, but will aid in caching joystick and dialog configs. --- src/Navaids/NavDataCache.cxx | 31 ++++++++++++++++++++++++++++++- src/Navaids/NavDataCache.hxx | 5 +++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 4b3cbcee1..3506d64fe 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -422,6 +422,9 @@ public: void prepareQueries() { + clearProperty = prepare("DELETE FROM properties WHERE key=?1"); + writePropertyMulti = prepare("INSERT INTO properties (key, value) VALUES(?,?)"); + #define POSITIONED_COLS "rowid, type, ident, name, airport, lon, lat, elev_m, octree_node" #define AND_TYPED "AND type>=?2 AND type <=?3" statCacheCheck = prepare("SELECT stamp FROM stat_cache WHERE path=?"); @@ -748,6 +751,7 @@ public: stampFileCache, statCacheCheck, loadAirportStmt, loadCommStation, loadPositioned, loadNavaid, loadRunwayStmt; + sqlite3_stmt_ptr writePropertyMulti, clearProperty; sqlite3_stmt_ptr insertPositionedQuery, insertAirport, insertTower, insertRunway, insertCommStation, insertNavaid; @@ -1054,7 +1058,32 @@ void NavDataCache::writeDoubleProperty(const string& key, const double& value) d->execSelect(d->writePropertyQuery); } - +string_list NavDataCache::readStringListProperty(const string& key) +{ + d->reset(d->readPropertyQuery); + sqlite_bind_stdstring(d->readPropertyQuery, 1, key); + string_list result; + while (d->stepSelect(d->readPropertyQuery)) { + result.push_back((char*) sqlite3_column_text(d->readPropertyQuery, 1)); + } + + return result; +} + +void NavDataCache::writeStringListProperty(const string& key, const string_list& values) +{ + d->reset(d->clearProperty); + sqlite_bind_stdstring(d->clearProperty, 1, key); + d->execUpdate(d->clearProperty); + + sqlite_bind_stdstring(d->writePropertyMulti, 1, key); + BOOST_FOREACH(string value, values) { + d->reset(d->writePropertyMulti); + sqlite_bind_stdstring(d->writePropertyMulti, 2, value); + d->execInsert(d->writePropertyMulti); + } +} + bool NavDataCache::isCachedFileModified(const SGPath& path) const { if (!path.exists()) { diff --git a/src/Navaids/NavDataCache.hxx b/src/Navaids/NavDataCache.hxx index e0bb0a98c..19edb91d7 100644 --- a/src/Navaids/NavDataCache.hxx +++ b/src/Navaids/NavDataCache.hxx @@ -25,6 +25,8 @@ #define FG_NAVDATACACHE_HXX #include + +#include // for string_list #include class SGPath; @@ -78,6 +80,9 @@ public: void writeStringProperty(const std::string& key, const std::string& value); void writeDoubleProperty(const std::string& key, const double& value); + string_list readStringListProperty(const std::string& key); + void writeStringListProperty(const std::string& key, const string_list& values); + FGPositioned* loadById(PositionedID guid); PositionedID insertAirport(FGPositioned::Type ty, const std::string& ident,