/** @file ModifyGeneric.cpp & @author Brian Magill @datecreated 1/08/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 for writing data to a generic Level 1 table */ #include #include #include #include #include "ModifyGeneric.h" #include "GATS_DB_Exception.h" #include "GATS_Utilities.hpp" using namespace std; using namespace gatsDBpp; using namespace GATS_Utilities; void ModifyGeneric::insertIntoTable(int event, int signal_no, string param, double value) const { vector columns; columns.push_back(ColData(event) ); columns.push_back(ColData(signal_no) ); columns.push_back(ColData(param) ); columns.push_back(ColData(value) ); insertIntoTable(columns); } void ModifyGeneric::insertIntoTable(int event, int signal_no, string param, int value) const { vector columns; columns.push_back(ColData(event) ); columns.push_back(ColData(signal_no) ); columns.push_back(ColData(param) ); columns.push_back(ColData(value) ); insertIntoTable(columns); } void ModifyGeneric::insertIntoTable(int event, string param, double value) const { vector columns; columns.push_back(ColData(event) ); columns.push_back(ColData(param) ); columns.push_back(ColData(value) ); insertIntoTable(columns); } void ModifyGeneric::insertIntoTable(int event, std::string param, vector const &array) const { unsigned long numSig = array.size(); const unsigned long TypeSize = 8; vector columns; columns.push_back(ColData(event) ); columns.push_back(ColData(param) ); columns.push_back(ColData(reinterpret_cast(&array[0]), TypeSize*numSig, true) ); insertIntoTable(columns); } void ModifyGeneric::insertIntoTable(int event, int signal_no, vector const &array) const { unsigned long numSig = array.size(); const unsigned long TypeSize = 8; vector columns; columns.push_back(ColData(event) ); columns.push_back(ColData(signal_no) ); columns.push_back(ColData(reinterpret_cast(&array[0]), TypeSize*numSig, true) ); insertIntoTable(columns); } /// /// @brief /// /// /// void ModifyGeneric::insertIntoTable(vector const & data) const { string errstr; unsigned long i; if (data.size() != fieldNames.size() ) { errstr = "ModifyGeneric::insertTable Error: " + string("number of data fields does not match number of columns for table ") + tableName; throw runtime_error(errstr); } try { vector > dataRow; for(i = 0; i < data.size(); i++) {dataRow.push_back( pair(fieldNames[i], data[i]) ); } dbConn->InsertIntoTable(tableName.c_str(), dataRow ); } catch (exception &ex) { errstr = "ModifyGeneric::insertTable Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } } /// /// @brief sets up entries to update the ModifyGeneric table. /// /// @param event - SOFIE event number /// bool ModifyGeneric::eventExists(long event) const { try { GATS_DB_Results results; string strSQL = "SELECT COUNT(*) FROM " + tableName + " WHERE Event = " + ConvertToString(event); results = dbConn->Query(strSQL.c_str()); if (results.size() > 0 ) return (results[0][0].asLong() > 0); else return false; } catch (exception &ex) { string errstr = "ModifyGeneric::eventExists Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } } /// /// @brief deletes entries for an event from the ModifyGeneric table. /// /// @param event - SOFIE event number /// void ModifyGeneric::deleteEvent(long event) const { try { GATS_DB_Results results; string strSQL = "DELETE FROM " + tableName + " WHERE Event = " + ConvertToString(event); results = dbConn->Query(strSQL.c_str()); } catch (exception &ex) { string errstr = "ModifyGeneric::deleteEvent Error: " + string(ex.what() ) + string(" for table ") + tableName; throw runtime_error(errstr); } } void ModifyGeneric::dumpColNames() const { cout << "Structure of " << tableName << endl; cout << "----------------------------" << endl; unsigned long i; for (i = 0; i < fieldNames.size(); i++) cout << "Column " << i << ": " << fieldNames[i] << endl; // cout << "Column 1: " << name_1 << endl; // cout << "Column 2: " << name_2 << endl; // cout << "Column 3: " << name_3 << endl; // cout << "Column 4: " << name_4 << endl; cout << endl; }