]> git.mxchange.org Git - flightgear.git/commitdiff
Move cache schema into its own file.
authorJames Turner <zakalawe@mac.com>
Mon, 30 Sep 2013 17:02:27 +0000 (18:02 +0100)
committerJames Turner <zakalawe@mac.com>
Mon, 30 Sep 2013 20:55:43 +0000 (21:55 +0100)
src/Navaids/CMakeLists.txt
src/Navaids/CacheSchema.h [new file with mode: 0644]
src/Navaids/NavDataCache.cxx

index 1d33ea12f1f4b6262a6ed36440124798fb1260ef..78d05287f671969a9d65a1e59fc63c0297cca007 100644 (file)
@@ -38,6 +38,7 @@ set(HEADERS
     NavDataCache.hxx
     PositionedOctree.hxx
     PolyLine.hxx
+    CacheSchema.h
     )
 
 flightgear_component(Navaids "${SOURCES}" "${HEADERS}")
diff --git a/src/Navaids/CacheSchema.h b/src/Navaids/CacheSchema.h
new file mode 100644 (file)
index 0000000..e977ab6
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef FG_NAVCACHE_SCHEMA_HXX
+#define FG_NAVCACHE_SCHEMA_HXX
+
+const int SCHEMA_VERSION = 9;
+
+#define SCHEMA_SQL \
+"CREATE TABLE properties (key VARCHAR, value VARCHAR);" \
+"CREATE TABLE stat_cache (path VARCHAR unique, stamp INT);"\
+\
+"CREATE TABLE positioned (type INT, ident VARCHAR collate nocase," \
+    "name VARCHAR collate nocase, airport INT64, lon FLOAT, lat FLOAT," \
+    "elev_m FLOAT, octree_node INT, cart_x FLOAT, cart_y FLOAT, cart_z FLOAT);" \
+\
+"CREATE INDEX pos_octree ON positioned(octree_node);" \
+"CREATE INDEX pos_ident ON positioned(ident collate nocase);" \
+"CREATE INDEX pos_name ON positioned(name collate nocase);" \
+"CREATE INDEX pos_apt_type ON positioned(airport, type);"\
+\
+"CREATE TABLE airport (has_metar BOOL);" \
+"CREATE TABLE comm (freq_khz INT,range_nm INT);" \
+"CREATE INDEX comm_freq ON comm(freq_khz);" \
+\
+"CREATE TABLE runway (heading FLOAT, length_ft FLOAT, width_m FLOAT," \
+    "surface INT, displaced_threshold FLOAT,stopway FLOAT,reciprocal INT64,ils INT64);" \
+"CREATE TABLE navaid (freq INT,range_nm INT,multiuse FLOAT, runway INT64,colocated INT64);" \
+"CREATE INDEX navaid_freq ON navaid(freq);" \
+\
+"CREATE TABLE octree (children INT);" \
+\
+"CREATE TABLE airway (ident VARCHAR collate nocase, network INT);" \
+"CREATE INDEX airway_ident ON airway(ident);" \
+\
+"CREATE TABLE airway_edge (network INT,airway INT64,a INT64,b INT64);" \
+"CREATE INDEX airway_edge_from ON airway_edge(a);" \
+\
+"CREATE TABLE taxi_node (hold_type INT,on_runway BOOL,pushback BOOL);" \
+"CREATE TABLE parking (heading FLOAT,radius INT,gate_type VARCHAR," \
+    "airlines VARCHAR,pushback INT64);" \
+"CREATE TABLE groundnet_edge (airport INT64,a INT64,b INT64);" \
+"CREATE INDEX groundnet_edge_airport ON groundnet_edge(airport);" \
+"CREATE INDEX groundnet_edge_from ON groundnet_edge(a);"
+
+#endif
+
index 7896225431171f136b2271b33ccd1fab112d6141..da943aa28a0cf6652492b232c14365e96ad06821 100644 (file)
@@ -72,6 +72,7 @@
 #include "poidb.hxx"
 #include <Airports/parking.hxx>
 #include <Airports/gnnode.hxx>
+#include "CacheSchema.h"
 
 using std::string;
 
@@ -81,7 +82,7 @@ using std::string;
 namespace {
 
 const int MAX_RETRIES = 10;
-const int SCHEMA_VERSION = 8;
+    
 const int CACHE_SIZE_KBYTES= 32 * 1024;
     
 // bind a std::string to a sqlite statement. The std::string must live the
@@ -422,116 +423,17 @@ public:
     execSelect(stmt);
     reset(stmt);
   }
-  
+    
   void initTables()
   {
-    runSQL("CREATE TABLE properties ("
-           "key VARCHAR,"
-           "value VARCHAR"
-           ")");
-    
-    runSQL("CREATE TABLE stat_cache ("
-           "path VARCHAR unique,"
-           "stamp INT"
-           ")");
-    
-    runSQL("CREATE TABLE positioned ("
-           "type INT,"
-           "ident VARCHAR collate nocase,"
-           "name VARCHAR collate nocase,"
-           "airport INT64,"
-           "lon FLOAT,"
-           "lat FLOAT,"
-           "elev_m FLOAT,"
-           "octree_node INT,"
-           "cart_x FLOAT,"
-           "cart_y FLOAT,"
-           "cart_z FLOAT"
-           ")");
-    
-    runSQL("CREATE INDEX pos_octree ON positioned(octree_node)");
-    runSQL("CREATE INDEX pos_ident ON positioned(ident collate nocase)");
-    runSQL("CREATE INDEX pos_name ON positioned(name collate nocase)");
-    // allow efficient querying of 'all ATIS at this airport' or
-    // 'all towers at this airport'
-    runSQL("CREATE INDEX pos_apt_type ON positioned(airport, type)");
-    
-    runSQL("CREATE TABLE airport ("
-           "has_metar BOOL"
-           ")"
-           );
-    
-    runSQL("CREATE TABLE comm ("
-           "freq_khz INT,"
-           "range_nm INT"
-           ")"
-           );
-    
-    runSQL("CREATE INDEX comm_freq ON comm(freq_khz)");
-    
-    runSQL("CREATE TABLE runway ("
-           "heading FLOAT,"
-           "length_ft FLOAT,"
-           "width_m FLOAT,"
-           "surface INT,"
-           "displaced_threshold FLOAT,"
-           "stopway FLOAT,"
-           "reciprocal INT64,"
-           "ils INT64"
-           ")"
-           );
-    
-    runSQL("CREATE TABLE navaid ("
-           "freq INT,"
-           "range_nm INT,"
-           "multiuse FLOAT,"
-           "runway INT64,"
-           "colocated INT64"
-           ")"
-           );
-    
-    runSQL("CREATE INDEX navaid_freq ON navaid(freq)");
-    
-    runSQL("CREATE TABLE octree (children INT)");
-    
-    runSQL("CREATE TABLE airway ("
-           "ident VARCHAR collate nocase,"
-           "network INT" // high-level or low-level
-           ")");
-    
-    runSQL("CREATE INDEX airway_ident ON airway(ident)");
-    
-    runSQL("CREATE TABLE airway_edge ("
-           "network INT,"
-           "airway INT64,"
-           "a INT64,"
-           "b INT64"
-           ")");
-    
-    runSQL("CREATE INDEX airway_edge_from ON airway_edge(a)");
-    
-    runSQL("CREATE TABLE taxi_node ("
-           "hold_type INT,"
-           "on_runway BOOL,"
-           "pushback BOOL"
-           ")");
-    
-    runSQL("CREATE TABLE parking ("
-           "heading FLOAT,"
-           "radius INT,"
-           "gate_type VARCHAR,"
-           "airlines VARCHAR,"
-           "pushback INT64"
-           ")");
-    
-    runSQL("CREATE TABLE groundnet_edge ("
-           "airport INT64,"
-           "a INT64,"
-           "b INT64"
-           ")");
-    
-    runSQL("CREATE INDEX groundnet_edge_airport ON groundnet_edge(airport)");
-    runSQL("CREATE INDEX groundnet_edge_from ON groundnet_edge(a)");
+      string_list commands = simgear::strutils::split(SCHEMA_SQL, ";");
+      BOOST_FOREACH(std::string sql, commands) {
+          if (sql.empty()) {
+              continue;
+          }
+          
+          runSQL(sql);
+      } // of commands in scheme loop
   }
   
   void prepareQueries()