Added program to output data from sql db
authorltracy
Tue, 07 Apr 2009 16:52:07 -0700
changeset 4315 24321b91c50b
parent 4314 edd3003429c7
child 4316 7f236cc1d990
Added program to output data from sql db
scratch/read-dat-sql.cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scratch/read-dat-sql.cc	Tue Apr 07 16:52:07 2009 -0700
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2008 University of Washington
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Leonard Tracy <lentracy@u.washington.edu>
+ *
+ *
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/uan-module.h"
+#include "ns3/node-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/helper-module.h"
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <sqlite3.h>
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE("ReadDatSql");
+
+
+std::ofstream mlfile;
+
+static int
+dataCallback(void *vd, int32_t argc, char **argv, char **cname)
+{
+  NS_ASSERT(mlfile.is_open());
+
+  for(int32_t i=0;i<argc;i++)
+    {
+      std::cout << "Column: " << cname[i] << " is " << argv[i] << std::endl;
+      mlfile << argv[i] << " ";
+    }
+  mlfile << std::endl;
+  return 0;
+}
+static int
+tapIdCallback(void *vti, int32_t argc, char **argv, char **cname)
+{
+
+
+  NS_ASSERT(argc == 1);
+
+  uint32_t *ti = (uint32_t *) vti;
+  *ti = std::atoi(argv[0]);
+  return 0;
+}
+int
+main(int argc, char **argv)
+{
+  LogComponentEnable("ReadDatSql", LOG_LEVEL_ALL);
+
+  std::string mlfilename = "sqlbhout.txt";
+  std::string cfgfile = "sqltst.cfg";
+  std::string dbfile = "sqldbtest.db";
+
+  uint32_t srcDepth = 10;
+  uint32_t recDepth = 10;
+  uint32_t range = 100;
+  uint32_t freq = 10000;
+
+  CommandLine cmd;
+  cmd.AddValue("MlFile", "File to write PDP to", mlfilename);
+  cmd.AddValue("CfgFile", "CFG file to read", cfgfile);
+  cmd.AddValue("SrcDepth", "Source depth", srcDepth);
+  cmd.AddValue("RecDepth", "Receiver depth", recDepth);
+  cmd.AddValue("Range", "Range", range);
+  cmd.AddValue("Freq", "Frequency", freq);
+  cmd.AddValue("DbFile", "Db filename", dbfile);
+  cmd.Parse(argc, argv);
+
+  mlfile.open(mlfilename.c_str());
+
+  BhRespManager &man = BhRespManager::GetInstance();
+  man.Configure(cfgfile);
+
+  BhIndex bi = man.MakeIndex(freq, srcDepth, recDepth, range);
+
+  std::ostringstream sql;
+  sqlite3 *sqldb;
+  sqlite3_open(dbfile.c_str(), &sqldb);
+
+  sql << "SELECT tapid FROM indextable WHERE "
+      << "srcdepth = " << bi.m_SrcDepthM << " AND "
+      << "recdepth = " << bi.m_RecDepthM << " AND "
+      << "range = " << bi.m_RangeM << " AND "
+      << "freq = " << bi.m_FreqHz << ";";
+
+  uint32_t tapid;
+  int32_t rc;
+
+  char *err;
+  rc = sqlite3_exec(sqldb, sql.str().c_str(), &tapIdCallback, &tapid, &err);
+  if(rc)
+    {
+      NS_FATAL_ERROR("Error: " << err);
+    }
+
+  sql.str("");
+
+  sql << "SELECT delay, realamp, imagamp FROM taptable WHERE "
+      << "tapid = " << tapid << ";";
+
+  rc = sqlite3_exec(sqldb, sql.str().c_str(), &dataCallback, 0, &err);
+  if(rc)
+    {
+      NS_FATAL_ERROR("Error: " << err);
+    }
+
+
+}
+