/* * epicsChannel.cc * * Created on: July 25, 2014 * Author: Hovanes Egiyan */ #include "epicsChannel.hh" // SQL string to find some useful parameters for the channel QString epicsChannel::sqlFindChannelProps = "SELECT " " Crate.crateid as crid, Crate.name as crname, " " Crate.Function as crFunction, Crate.host as crhost, " " Module.slot as mslot, Module.type as mtype, " " Channel.channel as chnum, Channel.col_name as chtype " " FROM Channel JOIN " " Module ON Channel.moduleid = Module.moduleid, " " Crate ON Module.crateid = Crate.crateid " " WHERE Channel.chanid='%1' "; epicsChannel::epicsChannel( string uri, string name, dbSubsystem* subPtr, int chID ) : baseEpicsChannel(name), dbObject( uri ), chanID( chID ), subsystemPtr(subPtr) { // cout << "Received pointer " << hex << subPtr << " , assigned " << subsystemPtr << dec << endl; if( chID < 1 ) return; checkDB(); QSqlQuery query(db); // Search for the crate in the DB for this particular channel using unique ID QString sqlString = sqlFindChannelProps.arg(chanID); // qWarning() << sqlString << endl; query.prepare(sqlString); query.exec(); // qDebug() << "The query has been executed" << endl; if (dbObject::sqlSize(query) > 1) { // Raise an exception if there are too many rows from the previous SQL // There has to be only one entry in the table for each unique id stringstream errMsg; errMsg << "Error: Too many crates for the id " << chanID << " , to be exact there are " << dbObject::sqlSize(query); qWarning() << errMsg.str().c_str() << endl; throw StringException(errMsg.str()); } query.next(); crateName = query.value(1).toString().toStdString(); string crateType = query.value(2).toString().toStdString(); crateHost = query.value(3).toString().toStdString(); slotNumber = query.value(4).toInt(); string boardType = query.value(5).toString().toStdString(); chanNum = query.value(6).toInt(); chanType = query.value(7).toString().toStdString(); return; }