12 return ts.substr(2, 2);
17 std::map<std::string, std::string>::const_iterator
i =
18 m_stringFields.find(key);
19 if (i != m_stringFields.end()) {
21 if (i->second != value) {
35 std::map<std::string, int>::const_iterator
i = m_intFields.find(key);
36 if (i != m_intFields.end()) {
38 if (i->second != value) {
51 std::map<std::string, LMFUnique *>::const_iterator
i =
52 m_foreignKeys.find(name);
53 if (i != m_foreignKeys.end()) {
55 m_foreignKeys[
name] = u;
59 m_foreignKeys[
name] = u;
70 boost::ptr_list<LMFUnique>
l;
71 this->checkConnection();
74 Statement* stmt = m_conn->createStatement();
78 cout << m_className +
": Query " + sql << endl;
81 while (rset->next() != 0) {
94 catch (boost::bad_pointer &
e) {
95 throw(std::runtime_error(m_className +
"::fetchAll: " +
101 m_conn->terminateStatement(stmt);
104 throw(std::runtime_error(m_className +
"::fetchAll: "+e.getMessage()));
107 cout << m_className <<
": list size = " << l.size() << endl;
123 m_trail.resize(70 - 31 - n * 2,
'#');
124 m_indent.resize(n*2,
' ');
127 cout << m_indent <<
"#################" << setw(15) << m_className
128 <<
" " << m_trail << endl;
129 cout << m_indent <<
"Address: " <<
this << endl;
130 cout << m_indent <<
"Connection params : " << m_env <<
", " << m_conn << endl;
132 cout << m_indent <<
"ID" << setw(18) <<
": " << m_ID;
134 cout <<
" *** NULL ID ***";
137 cout <<
" INVALID ***";
141 std::map<std::string, std::string>::const_iterator is =
142 m_stringFields.begin();
143 std::map<std::string, std::string>::const_iterator es =
144 m_stringFields.end();
147 cout << m_indent << key << setw(20 - key.length()) <<
": " << is->second
152 std::map<std::string, int>::const_iterator
ii = m_intFields.begin();
153 std::map<std::string, int>::const_iterator ei = m_intFields.end();
156 cout << m_indent << key << setw(20 - key.length()) <<
": " << ii->second
160 cout << m_indent <<
"#################" << setw(15) << m_className
161 <<
" " << m_trail << endl;
163 std::map<std::string, LMFUnique*>::const_iterator ik = m_foreignKeys.begin();
164 std::map<std::string, LMFUnique*>::const_iterator ek = m_foreignKeys.end();
166 m_indent.resize((n + 1) * 2,
' ');
168 cout << m_indent <<
"Foreign Key: " << ik->first << endl;
169 ik->second->dump(n + 1);
196 std::map<std::string, std::string>::const_iterator
i = m_stringFields.find(s);
197 if (i != m_stringFields.end()) {
206 std::map<std::string, int>::const_iterator
i = m_intFields.find(s);
207 if (i != m_intFields.end()) {
232 this->checkConnection();
236 Statement* stmt = m_conn->createStatement();
241 cout << m_className +
": Query " + sql << endl;
245 if (rset->next() != 0) {
246 m_ID = rset->getInt(1);
251 cout << m_className +
": ID set to " << m_ID << endl;
253 int n = rset->getNumArrayRows();
255 cout << m_className +
": Returned " << n <<
" rows" << endl;
258 throw(std::runtime_error(m_className +
"::fetchID: too many rows returned " +
259 "executing query " + sql));
263 m_conn->terminateStatement(stmt);
265 throw(std::runtime_error(m_className +
"::fetchID: "+e.getMessage()));
272 map<string, LMFUnique*>::iterator
i = m_foreignKeys.begin();
273 map<string, LMFUnique*>::iterator e = m_foreignKeys.end();
275 if (i->second->getID() == 0) {
276 i->second->fetchID();
281 cout << m_className <<
": fetchID:: returning " << m_ID << endl;
293 cout << m_className <<
": Setting this object as ID = " <<
id << endl;
295 this->checkConnection();
297 Statement* stmt = m_conn->createStatement();
300 throw(std::runtime_error(m_className +
"::setByID: [empty sql])"));
303 cout << m_className +
": " + sql << endl;
307 if (rset->next() != 0) {
312 cout << m_className +
": Setting done. ID set to " << m_ID << endl;
315 throw(std::runtime_error(m_className +
"::setByID: Given id is not in the database"));
317 m_conn->terminateStatement(stmt);
319 throw(std::runtime_error(m_className +
"::setByID: "+e.getMessage()));
326 std::map<std::string, LMFUnique*>::const_iterator
i = m_foreignKeys.begin();
327 std::map<std::string, LMFUnique*>::const_iterator
e = m_foreignKeys.end();
330 if (i->second->getID() == 0) {
331 i->second->writeDB();
350 if (!(this->fetchID())) {
352 this->checkConnection();
357 Statement* stmt = m_conn->createStatement();
359 sql = writeDBSql(stmt);
362 cout << m_className +
": " + sql << endl;
364 stmt->executeUpdate();
367 m_conn->terminateStatement(stmt);
371 throw(std::runtime_error(m_className +
"::writeDB: " + e.getMessage() +
372 " while executing query " + sql));
375 if (this->fetchID() == 0) {
376 throw(std::runtime_error(m_className +
"::writeDB: Failed to write"));
382 std::cout << m_className <<
":: Spent time in writeDB:" <<
383 ((double) (end - start)) / CLOCKS_PER_SEC <<
" s" << endl;
def getParameters(parameters)
virtual boost::ptr_list< LMFUnique > fetchAll() const noexcept(false)
LMFUnique & setInt(std::string key, int value)
std::string sequencePostfix(const Tm &t)
oracle::occi::ResultSet ResultSet
virtual LMFUnique * createObject() const
virtual void dump() const
oracle::occi::SQLException SQLException
int getInt(std::string fieldname) const
void setByID(int id) noexcept(false)
oracle::occi::Statement Statement
int fetchID() noexcept(false)
LMFUnique & setString(std::string key, std::string value)
virtual int writeDB() noexcept(false)
virtual std::string fetchAllSql(Statement *stmt) const
std::string getString(std::string fieldname) const
virtual int writeForeignKeys() noexcept(false)
void attach(std::string name, LMFUnique *u)