5 using namespace oracle::occi;
11 std::string ts = t.
str();
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;
65 throw(std::runtime_error)
70 boost::ptr_list<LMFUnique>
l;
71 this->checkConnection();
74 Statement* stmt = m_conn->createStatement();
75 std::string sql = fetchAllSql(stmt);
78 cout << m_className +
": Query " + sql << endl;
81 while (rset->next()) {
95 m_conn->terminateStatement(stmt);
98 throw(std::runtime_error(m_className +
"::fetchAll: "+e.getMessage()));
101 cout << m_className <<
": list size = " << l.size() << endl;
115 std::string m_indent =
"";
116 std::string m_trail =
"";
117 m_trail.resize(70 - 31 - n * 2,
'#');
118 m_indent.resize(n*2,
' ');
121 cout << m_indent <<
"#################" << setw(15) << m_className
122 <<
" " << m_trail << endl;
123 cout << m_indent <<
"Address: " <<
this << endl;
124 cout << m_indent <<
"Connection params : " << m_env <<
", " << m_conn << endl;
126 cout << m_indent <<
"ID" << setw(18) <<
": " << m_ID;
128 cout <<
" *** NULL ID ***";
131 cout <<
" INVALID ***";
135 std::map<std::string, std::string>::const_iterator is =
136 m_stringFields.begin();
137 std::map<std::string, std::string>::const_iterator es =
138 m_stringFields.end();
140 std::string
key = is->first;
141 cout << m_indent << key << setw(20 - key.length()) <<
": " << is->second
146 std::map<std::string, int>::const_iterator ii = m_intFields.begin();
147 std::map<std::string, int>::const_iterator ei = m_intFields.end();
149 std::string
key = ii->first;
150 cout << m_indent << key << setw(20 - key.length()) <<
": " << ii->second
154 cout << m_indent <<
"#################" << setw(15) << m_className
155 <<
" " << m_trail << endl;
157 std::map<std::string, LMFUnique*>::const_iterator ik = m_foreignKeys.begin();
158 std::map<std::string, LMFUnique*>::const_iterator ek = m_foreignKeys.end();
160 m_indent.resize((n + 1) * 2,
' ');
162 cout << m_indent <<
"Foreign Key: " << ik->first << endl;
163 ik->second->dump(n + 1);
190 std::map<std::string, std::string>::const_iterator
i = m_stringFields.find(s);
191 if (i != m_stringFields.end()) {
200 std::map<std::string, int>::const_iterator
i = m_intFields.find(s);
201 if (i != m_intFields.end()) {
208 throw(std::runtime_error)
226 this->checkConnection();
230 Statement* stmt = m_conn->createStatement();
232 std::string sql = fetchIdSql(stmt);
235 cout << m_className +
": Query " + sql << endl;
240 m_ID = rset->getInt(1);
245 cout << m_className +
": ID set to " << m_ID << endl;
247 int n = rset->getNumArrayRows();
249 cout << m_className +
": Returned " << n <<
" rows" << endl;
252 throw(std::runtime_error(m_className +
"::fetchID: too many rows returned " +
253 "executing query " + sql));
257 m_conn->terminateStatement(stmt);
259 throw(std::runtime_error(m_className +
"::fetchID: "+e.getMessage()));
266 map<string, LMFUnique*>::iterator
i = m_foreignKeys.begin();
267 map<string, LMFUnique*>::iterator e = m_foreignKeys.end();
269 if (i->second->getID() == 0) {
270 i->second->fetchID();
275 cout << m_className <<
": fetchID:: returning " << m_ID << endl;
281 throw(std::runtime_error)
287 cout << m_className <<
": Setting this object as ID = " <<
id << endl;
289 this->checkConnection();
291 Statement* stmt = m_conn->createStatement();
292 std::string sql = setByIDSql(stmt,
id);
294 throw(std::runtime_error(m_className +
"::setByID: [empty sql])"));
297 cout << m_className +
": " + sql << endl;
306 cout << m_className +
": Setting done. ID set to " << m_ID << endl;
309 throw(std::runtime_error(m_className +
"::setByID: Given id is not in the database"));
311 m_conn->terminateStatement(stmt);
313 throw(std::runtime_error(m_className +
"::setByID: "+e.getMessage()));
318 throw(std::runtime_error)
320 std::map<std::string, LMFUnique*>::const_iterator
i = m_foreignKeys.begin();
321 std::map<std::string, LMFUnique*>::const_iterator e = m_foreignKeys.end();
324 if (i->second->getID() == 0) {
325 i->second->writeDB();
334 throw(std::runtime_error)
344 if (!(this->fetchID())) {
346 this->checkConnection();
349 std::string sql =
"";
351 Statement* stmt = m_conn->createStatement();
353 sql = writeDBSql(stmt);
356 cout << m_className +
": " + sql << endl;
358 stmt->executeUpdate();
361 m_conn->terminateStatement(stmt);
365 throw(std::runtime_error(m_className +
"::writeDB: " + e.getMessage() +
366 " while executing query " + sql));
369 if (this->fetchID() == 0) {
370 throw(std::runtime_error(m_className +
"::writeDB: Failed to write"));
376 std::cout << m_className <<
":: Spent time in writeDB:" <<
377 ((double) (end - start)) / CLOCKS_PER_SEC <<
" s" << endl;
LMFUnique & setInt(std::string key, int value)
oracle::occi::ResultSet ResultSet
virtual LMFUnique * createObject() const
virtual void dump() const
oracle::occi::SQLException SQLException
virtual int writeForeignKeys()
int getInt(std::string fieldname) const
std::string sequencePostfix(Tm t)
oracle::occi::Statement Statement
LMFUnique & setString(std::string key, std::string value)
virtual boost::ptr_list< LMFUnique > fetchAll() const
virtual std::string fetchAllSql(Statement *stmt) const
std::string getString(std::string fieldname) const
void attach(std::string name, LMFUnique *u)