9 #include "RelationalAccess/ICursor.h"
10 #include "RelationalAccess/IQuery.h"
11 #include "RelationalAccess/ISessionProxy.h"
12 #include "RelationalAccess/ISchema.h"
13 #include "RelationalAccess/ITable.h"
14 #include "RelationalAccess/ITableDescription.h"
15 #include "RelationalAccess/IColumn.h"
17 #include "RelationalAccess/SchemaException.h"
18 #include "CoralBase/Exception.h"
19 #include "CoralBase/AttributeList.h"
20 #include "CoralBase/Attribute.h"
26 ,
const std::string& nodeName
27 ,
const std::string& tagId
28 ,
const std::string& connName)
32 , m_queryCount(nullptr)
33 , m_accessSvc(accessSvc)
34 , m_nodeName(nodeName)
36 , m_connName(connName)
52 m_accessSvc->msg() << MSG::WARNING <<
"RDBQuery cannot be executed more than once! Query: "
68 m_accessSvc->msg() << MSG::ERROR <<
"Cannot connect to the database: "
70 throw std::runtime_error(
"Cannot connect to the database " +
m_connName);
77 for (
char&
ch : upperName) {
78 ch = std::toupper (
static_cast<unsigned int>(
ch));
95 for(
int i=0;
i<dataTableDesc.numberOfColumns(); ++
i) {
96 m_query->addToOutputList(upperName+
"_DATA."+dataTableDesc.columnDescription(
i).name());
100 m_queryCount->addToOutputList(
"COUNT("+upperName+
"_DATA_ID)",
"SUMREC");
103 m_query->addToTableList(upperName +
"_DATA");
104 m_query->addToTableList(upperName +
"_DATA2TAG");
110 m_query->addToOrderList(upperName +
"_DATA." + upperName +
"_DATA_ID");
118 bindsData.extend<std::string>(
"tagID");
120 std::string queryStructCondition = upperName +
"_DATA2TAG." + upperName +
"_TAG_ID =:tagID";
121 m_queryCount->setCondition(queryStructCondition , bindsData);
123 queryStructCondition +=
" AND " + upperName +
"_DATA." + upperName +
"_DATA_ID=" + upperName +
"_DATA2TAG." + upperName +
"_DATA_ID";
124 m_query->setCondition(queryStructCondition , bindsData);
126 bindsData[0].data<std::string>() =
m_tagId;
129 m_query->setMemoryCacheSize(1);
133 while(cursorCount.next()) {
135 m_size = cursorCount.currentRow()[
"SUMREC"].data<
long>();
142 catch(coral::SchemaException&
se) {
143 m_accessSvc->msg() << MSG::WARNING <<
"QUERY: Schema Exception : " + std::string(
se.what()) <<
endmsg;
146 m_accessSvc->msg() << MSG::WARNING <<
"QUERY: Exception : " + std::string(
e.what()) <<
endmsg;