11 return ts.substr(2, 2);
16 std::map<std::string, std::string>::const_iterator
i = m_stringFields.find(
key);
17 if (
i != m_stringFields.end()) {
33 std::map<std::string, int>::const_iterator
i = m_intFields.find(
key);
34 if (
i != m_intFields.end()) {
49 std::map<std::string, LMFUnique*>::const_iterator
i = m_foreignKeys.find(
name);
50 if (
i != m_foreignKeys.end()) {
52 m_foreignKeys[
name] = u;
56 m_foreignKeys[
name] = u;
65 std::list<std::unique_ptr<LMFUnique>>
l;
66 this->checkConnection();
69 Statement* stmt = m_conn->createStatement();
73 cout << m_className +
": Query " + sql << endl;
76 while (rset->next() != 0) {
82 o->setByID(rset->getInt(1));
89 throw(std::runtime_error(m_className +
"::fetchAll: " +
e.what()));
94 m_conn->terminateStatement(stmt);
95 }
catch (SQLException&
e) {
96 throw(std::runtime_error(m_className +
"::fetchAll: " +
e.getMessage()));
99 cout << m_className <<
": list size = " <<
l.size() << endl;
113 m_trail.resize(70 - 31 -
n * 2,
'#');
114 m_indent.resize(
n * 2,
' ');
117 cout << m_indent <<
"#################" << setw(15) << m_className <<
" " << m_trail << endl;
118 cout << m_indent <<
"Address: " <<
this << endl;
119 cout << m_indent <<
"Connection params : " << m_env <<
", " << m_conn << endl;
121 cout << m_indent <<
"ID" << setw(18) <<
": " << m_ID;
123 cout <<
" *** NULL ID ***";
126 cout <<
" INVALID ***";
130 std::map<std::string, std::string>::const_iterator is = m_stringFields.begin();
131 std::map<std::string, std::string>::const_iterator es = m_stringFields.end();
134 cout << m_indent <<
key << setw(20 -
key.length()) <<
": " << is->second << endl;
138 std::map<std::string, int>::const_iterator
ii = m_intFields.begin();
139 std::map<std::string, int>::const_iterator ei = m_intFields.end();
142 cout << m_indent <<
key << setw(20 -
key.length()) <<
": " <<
ii->second << endl;
145 cout << m_indent <<
"#################" << setw(15) << m_className <<
" " << m_trail << endl;
147 std::map<std::string, LMFUnique*>::const_iterator ik = m_foreignKeys.begin();
148 std::map<std::string, LMFUnique*>::const_iterator ek = m_foreignKeys.end();
150 m_indent.resize((
n + 1) * 2,
' ');
152 cout << m_indent <<
"Foreign Key: " << ik->first << endl;
153 ik->second->dump(
n + 1);
180 std::map<std::string, std::string>::const_iterator
i = m_stringFields.find(
s);
181 if (
i != m_stringFields.end()) {
190 std::map<std::string, int>::const_iterator
i = m_intFields.find(
s);
191 if (
i != m_intFields.end()) {
214 this->checkConnection();
218 Statement* stmt = m_conn->createStatement();
223 cout << m_className +
": Query " + sql << endl;
227 if (rset->next() != 0) {
228 m_ID = rset->getInt(1);
233 cout << m_className +
": ID set to " << m_ID << endl;
235 int n = rset->getNumArrayRows();
237 cout << m_className +
": Returned " <<
n <<
" rows" << endl;
240 throw(std::runtime_error(m_className +
"::fetchID: too many rows returned " +
"executing query " + sql));
244 m_conn->terminateStatement(stmt);
245 }
catch (SQLException&
e) {
246 throw(std::runtime_error(m_className +
"::fetchID: " +
e.getMessage()));
253 map<string, LMFUnique*>::iterator
i = m_foreignKeys.begin();
254 map<string, LMFUnique*>::iterator
e = m_foreignKeys.end();
256 if (
i->second->getID() == 0) {
257 i->second->fetchID();
262 cout << m_className <<
": fetchID:: returning " << m_ID << endl;
272 cout << m_className <<
": Setting this object as ID = " <<
id << endl;
274 this->checkConnection();
276 Statement* stmt = m_conn->createStatement();
279 throw(std::runtime_error(m_className +
"::setByID: [empty sql])"));
282 cout << m_className +
": " + sql << endl;
286 if (rset->next() != 0) {
291 cout << m_className +
": Setting done. ID set to " << m_ID << endl;
294 throw(std::runtime_error(m_className +
"::setByID: Given id is not in the database"));
296 m_conn->terminateStatement(stmt);
297 }
catch (SQLException&
e) {
298 throw(std::runtime_error(m_className +
"::setByID: " +
e.getMessage()));
303 std::map<std::string, LMFUnique*>::const_iterator
i = m_foreignKeys.begin();
304 std::map<std::string, LMFUnique*>::const_iterator
e = m_foreignKeys.end();
307 if (
i->second->getID() == 0) {
308 i->second->writeDB();
325 if (!(this->fetchID())) {
327 this->checkConnection();
332 Statement* stmt = m_conn->createStatement();
334 sql = writeDBSql(stmt);
337 cout << m_className +
": " + sql << endl;
339 stmt->executeUpdate();
342 m_conn->terminateStatement(stmt);
343 }
catch (SQLException&
e) {
346 throw(std::runtime_error(m_className +
"::writeDB: " +
e.getMessage() +
" while executing query " + sql));
349 if (this->fetchID() == 0) {
350 throw(std::runtime_error(m_className +
"::writeDB: Failed to write"));
356 std::cout << m_className <<
":: Spent time in writeDB:" << ((double)(
end -
start)) / CLOCKS_PER_SEC <<
" s"