14 m_writeStmt =
nullptr;
29 this->checkConnection();
31 m_readStmt = m_conn->createStatement();
32 m_readStmt->setSQL(
"select COND2CONF_INFO_SQ.NextVal from DUAL ");
33 ResultSet* rset = m_readStmt->executeQuery();
34 while (rset->next()) {
38 m_conn->terminateStatement(m_readStmt);
42 throw(std::runtime_error(
std::string(
"ODBadXTInfo::fetchNextId(): ") +
e.getMessage()));
47 this->checkConnection();
51 next_id = fetchNextId();
55 m_writeStmt = m_conn->createStatement();
56 m_writeStmt->setSQL(
"INSERT INTO " + getTable() +
57 " ( rec_id, tag, version) "
58 " VALUES ( :1, :2, :3 ) ");
60 m_writeStmt->setInt(1, next_id);
64 throw(std::runtime_error(
std::string(
"ODBadXTInfo::prepareWrite(): ") +
e.getMessage()));
72 for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
73 if (ci->first ==
"VERSION")
74 setVersion(atoi(ci->second.c_str()));
75 if (ci->first ==
"TAG")
76 setConfigTag(ci->second);
81 this->checkConnection();
86 m_writeStmt->setString(2, this->getConfigTag());
87 m_writeStmt->setInt(3, this->getVersion());
89 m_writeStmt->executeUpdate();
92 throw(std::runtime_error(
std::string(
"ODBadXTInfo::writeDB(): ") +
e.getMessage()));
95 if (!this->fetchID()) {
96 throw(std::runtime_error(
"ODBadXTInfo::writeDB: Failed to write"));
98 int old_version = this->getVersion();
99 m_readStmt = m_conn->createStatement();
100 this->fetchData(
this);
101 m_conn->terminateStatement(m_readStmt);
102 if (this->getVersion() != old_version)
103 std::cout <<
"ODBadXTInfo>>WARNING version is " << getVersion() << endl;
108 this->checkConnection();
110 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
111 throw(std::runtime_error(
"ODBadXTInfo::fetchData(): no Id defined for this ODBadXTInfo "));
115 if (
result->getId() != 0) {
116 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where rec_id = :1 ");
117 m_readStmt->setInt(1,
result->getId());
118 }
else if (!
result->getConfigTag().empty()) {
119 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where tag=:1 AND version=:2 ");
120 m_readStmt->setString(1,
result->getConfigTag());
121 m_readStmt->setInt(2,
result->getVersion());
124 throw(std::runtime_error(
"ODBadXTInfo::fetchData(): no Id defined for this record "));
127 ResultSet* rset = m_readStmt->executeQuery();
133 result->setId(rset->getInt(1));
134 result->setConfigTag(rset->getString(2));
135 result->setVersion(rset->getInt(3));
138 throw(std::runtime_error(
std::string(
"ODBadXTInfo::fetchData(): ") +
e.getMessage()));
148 this->checkConnection();
151 Statement* stmt = m_conn->createStatement();
152 stmt->setSQL(
"SELECT rec_id FROM " + getTable() +
"WHERE tag=:1 and version=:2 ");
154 stmt->setString(1, getConfigTag());
155 stmt->setInt(2, getVersion());
157 ResultSet* rset = stmt->executeQuery();
160 m_ID = rset->getInt(1);
164 m_conn->terminateStatement(stmt);
166 throw(std::runtime_error(
std::string(
"ODBadXTInfo::fetchID: ") +
e.getMessage()));