/** @class MetaSingleValue @author Brian Magill @datecreated 3/06/2007 $Date:$ $Revision:$ @copyright (©) Copyright 2006 by GATS Inc. 11864 Canon Blvd., Suite 101, Newport News, VA 23606 All Rights Reserved. No part of this software or publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without the prior written permission of GATS Inc. @brief Class returns a vector of data associated with a given table parameter */ //---------------------------------------------------------------------- // #include #include #include #include "EventVar.h" #include "MetaSingleValue.h" #include "GATS_DB_Exception.h" #include "GATS_Utilities.hpp" #include "Vec2Val.hpp" //#include "SOFIELevel1DBUtilities.h" using namespace std; using namespace gatsDBpp; //using namespace GATS_Utilities; bool MetaSingleValue::TableExists(std::string tableName) const { try { GATS_DB_Results results; string strSQL = "SELECT COUNT(*) FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) return (results[0][0].asLong() > 0); else return false; } catch (exception &ex) { string errstr = "MetaSingleValue::TableExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; bool MetaSingleValue::EntryExists(string tableName, string Parameter) const { try { GATS_DB_Results results; string strSQL = "SELECT COUNT(*) FROM " + metaTable + " WHERE TableName = '" + tableName + "' AND Parameter = '" + Parameter + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) return (results[0][0].asLong() > 0); else return false; } catch (exception &ex) { string errstr = "MetaSingleValue::TableExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } }; string MetaSingleValue::getEntryName(string tableName, string Parameter) const { string varName; string strErr; try { GATS_DB_Results results; string strSQL = "SELECT Assoc_Entity FROM " + metaTable + " WHERE TableName = '" + tableName +"'" + " AND Parameter = '" + Parameter +"'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) varName = results[0][0].asString(); else varName = ""; } catch (exception &ex) { string errstr = "MetaSingleValue::getEntryName() Error: " + string(ex.what() ) + string(" for table ") + tableName + " and Parameter " + Parameter; throw runtime_error(errstr); } return varName; } double MetaSingleValue::getData(string tableName, string Parameter) const { //vector outVector; EventVar varArray; string strErr; string varName; try { // EventVar varArray; // varName = getEntryName(tableName, Parameter); if (varName.size() < 1) { strErr = string("No entry "); throw runtime_error(strErr); } switch (inEvent->EventVarExists(varName) ) { case DOUBLE: { inEvent->getEventVar(varName, varArray); } break; case NOVAR: strErr = string("No entry for ") + varName + string(" in ouput Event object"); throw runtime_error(strErr); break; case INTEGER: { strErr = string("Error ") + varName + string(" is an integer array! Expecting double type."); throw runtime_error(strErr); break; } break; case FLOAT: { strErr = string("Error ") + varName + string(" is a float array! Expecting double type."); throw runtime_error(strErr); break; } break; default: throw runtime_error("programming error in Event::EventVarExists(). Bad Type!"); } return varArray[0]; } catch (exception &ex) { string errstr = "MetaSingleValue::getData() Error: " + string(ex.what() ) + string(" for table ") + tableName + " and Parameter " + Parameter; throw runtime_error(errstr); } }; vector MetaSingleValue::getParameterList(std::string tableName) const { string strErr; vector paramList; try { GATS_DB_Results results; string strSQL = "SELECT Parameter FROM " + metaTable + " WHERE TableName = '" + tableName + "'"; results = dbConn->Query(strSQL.c_str()); if (results.size() > 0) for(unsigned long i = 0; i < results.size(); i++) { paramList.push_back(results[i][0].asString()); } else { strErr = string("No entry for table ") + tableName; throw runtime_error(strErr); } } catch (exception &ex) { strErr = "MetaSingleValue::getParameterList() Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(strErr); } return paramList; }; vector MetaSingleValue::getTableList() const { string strErr; vector TableList; try { GATS_DB_Results results; string strSQL = "SELECT DISTINCT TableName FROM " + metaTable; results = dbConn->Query(strSQL.c_str()); for(unsigned long i = 0; i < results.size(); i++) { TableList.push_back(results[i][0].asString()); } } catch (exception &ex) { strErr = "MetaSingleValue::getTableList() Error: " + string(ex.what()); throw runtime_error(strErr); } return TableList; };