14 m_writeStmt =
nullptr;
31 if (run_seq != m_run_seq) {
43 this->checkConnection();
48 Statement* stmt = m_conn->createStatement();
50 "SELECT sequence_id from ECAL_sequence_DAT "
51 "WHERE ecal_config_id = :id1 "
52 " and sequence_num = :id2 ");
53 stmt->setInt(1, m_ecal_config_id);
54 stmt->setInt(2, m_seq_num);
56 ResultSet* rset = stmt->executeQuery();
59 m_ID = rset->getInt(1);
63 m_conn->terminateStatement(stmt);
65 throw(std::runtime_error(
"ODRunConfigSeqInfo::fetchID: " +
e.getMessage()));
72 this->checkConnection();
77 Statement* stmt = m_conn->createStatement();
78 stmt->setSQL(
"SELECT max(sequence_id) FROM ecal_sequence_dat ");
79 ResultSet* rset = stmt->executeQuery();
82 m_ID = rset->getInt(1);
86 m_conn->terminateStatement(stmt);
88 throw(std::runtime_error(
"ODRunConfigSeqInfo::fetchIDLast: " +
e.getMessage()));
96 this->checkConnection();
100 cout <<
"ODRunConfigSeqInfo::setByID called for id " <<
id << endl;
103 Statement* stmt = m_conn->createStatement();
106 "SELECT ecal_config_id, sequence_num, num_of_cycles, sequence_type_def_id, description FROM ECAL_sequence_DAT "
107 "WHERE sequence_id = :1 ");
110 ResultSet* rset = stmt->executeQuery();
112 m_ecal_config_id = rset->getInt(1);
113 m_seq_num = rset->getInt(2);
114 m_cycles = rset->getInt(3);
115 int seq_def_id = rset->getInt(4);
116 m_description = rset->getString(5);
118 m_run_seq.setConnection(m_env, m_conn);
119 m_run_seq.setByID(seq_def_id);
121 throw(std::runtime_error(
"ODRunConfigSeqInfo::setByID: Given config_id is not in the database"));
123 m_conn->terminateStatement(stmt);
125 throw(std::runtime_error(
"ODRunConfigSeqInfo::setByID: " +
e.getMessage()));
130 this->checkConnection();
133 m_writeStmt = m_conn->createStatement();
135 "INSERT INTO ECAL_SEQUENCE_DAT ( ecal_config_id, "
136 "sequence_num, num_of_cycles, sequence_type_def_id, description ) "
137 "VALUES (:1, :2, :3 , :4, :5 )");
139 throw(std::runtime_error(
"ODRunConfigSeqInfo::prepareWrite(): " +
e.getMessage()));
143 this->checkConnection();
144 this->checkPrepare();
152 m_run_seq.setConnection(m_env, m_conn);
153 int seq_def_id = m_run_seq.writeDB();
155 m_writeStmt->setInt(1, this->getEcalConfigId());
156 m_writeStmt->setInt(2, this->getSequenceNumber());
157 m_writeStmt->setInt(3, this->getNumberOfCycles());
158 m_writeStmt->setInt(4, seq_def_id);
159 m_writeStmt->setString(5, this->getDescription());
161 m_writeStmt->executeUpdate();
164 throw(std::runtime_error(
"ODRunConfigSeqInfo::writeDB(): " +
e.getMessage()));
166 if (!this->fetchID()) {
167 throw(std::runtime_error(
"ODRunConfigSeqInfo::writeDB: Failed to write"));
169 cout <<
"ODRunConfigSeqInfo::writeDB>> done inserting ODRunConfigSeqInfo with id=" << m_ID << endl;
182 this->checkConnection();
184 if (
result->getId() == 0) {
191 "SELECT ecal_config_id, sequence_num, num_of_cycles, "
192 "sequence_type_def_id, description FROM ECAL_sequence_DAT WHERE sequence_id = :1 ");
194 m_readStmt->setInt(1,
result->getId());
195 ResultSet* rset = m_readStmt->executeQuery();
199 result->setEcalConfigId(rset->getInt(1));
200 result->setSequenceNumber(rset->getInt(2));
201 result->setNumberOfCycles(rset->getInt(3));
202 int seq_def_id = rset->getInt(4);
204 m_run_seq.setConnection(m_env, m_conn);
205 m_run_seq.setByID(seq_def_id);
206 result->setDescription(rset->getString(5));
209 throw(std::runtime_error(
"ODRunConfigSeqInfo::fetchData(): " +
e.getMessage()));