00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #include "DbObjects.h"
00089
00090
00091
00092
00093
00094
00095
00096
00097
00101 DOConnection::DOConnection()
00102 : m_handle()
00103 , m_hostname()
00104 , m_password()
00105 , m_username()
00106 , m_database()
00107 {
00108 ConstructorInclude();
00109
00110
00111 }
00112
00113
00117 DOConnection::~DOConnection()
00118 {
00119 DestructorInclude();
00120
00121 mysql_close (&m_handle);
00122 }
00123
00124
00128 void DOConnection::Connect()
00129 {
00130 if (mysql_connect (&m_handle, m_hostname, m_username, m_password) != NULL) {
00131 mysql_select_db (&m_handle, m_database);
00132 }
00133
00134 }
00135
00136
00140 MYSQL* DOConnection::GetHdl()
00141 {
00142 return &m_handle;
00143 }
00144
00145
00146
00147
00151 void DOConnection::ConstructorInclude()
00152 {
00153
00154
00155 _firstQuery = (DOQuery*)0;
00156 _lastQuery = (DOQuery*)0;
00157 _countQuery = 0;
00158 }
00159
00160
00164 void DOConnection::DestructorInclude()
00165 {
00166
00167 { for (DOQuery* item = GetFirstQuery(); item; item = GetFirstQuery())
00168 delete item; }
00169 }
00170
00171
00172
00173
00174 void DOConnection::AddQueryFirst(DOQuery* item)
00175 {
00176
00177 assert(this);
00178
00179 assert(item);
00180 assert(item->_refConnection == (DOConnection*)0);
00181
00182 _countQuery++;
00183
00184 item->_refConnection = this;
00185
00186 if (_firstQuery)
00187 {
00188 _firstQuery->_prevConnection = item;
00189 item->_nextConnection = _firstQuery;
00190 _firstQuery = item;
00191 }
00192 else
00193 _firstQuery = _lastQuery = item;
00194 }
00195
00196 void DOConnection::AddQueryLast(DOQuery* item)
00197 {
00198
00199 assert(this);
00200
00201 assert(item);
00202 assert(item->_refConnection == (DOConnection*)0);
00203
00204 _countQuery++;
00205
00206 item->_refConnection = this;
00207
00208 if (_lastQuery)
00209 {
00210 _lastQuery->_nextConnection = item;
00211 item->_prevConnection = _lastQuery;
00212 _lastQuery = item;
00213 }
00214 else
00215 _firstQuery = _lastQuery = item;
00216 }
00217
00218 void DOConnection::AddQueryAfter(DOQuery* item, DOQuery* pos)
00219 {
00220
00221 assert(this);
00222
00223 assert(item);
00224 assert(item->_refConnection == (DOConnection*)0);
00225
00226 assert(pos);
00227 assert(pos->_refConnection == this);
00228
00229 _countQuery++;
00230
00231 item->_refConnection = this;
00232 item->_prevConnection = pos;
00233 item->_nextConnection = pos->_nextConnection;
00234 pos->_nextConnection = item;
00235
00236 if (item->_nextConnection)
00237 item->_nextConnection->_prevConnection = item;
00238 else
00239 _lastQuery = item;
00240 }
00241
00242 void DOConnection::AddQueryBefore(DOQuery* item, DOQuery* pos)
00243 {
00244
00245 assert(this);
00246
00247 assert(item);
00248 assert(item->_refConnection == (DOConnection*)0);
00249
00250 assert(pos);
00251 assert(pos->_refConnection == this);
00252
00253 _countQuery++;
00254
00255 item->_refConnection = this;
00256 item->_nextConnection = pos;
00257 item->_prevConnection = pos->_prevConnection;
00258 pos->_prevConnection = item;
00259
00260 if (item->_prevConnection)
00261 item->_prevConnection->_nextConnection = item;
00262 else
00263 _firstQuery = item;
00264 }
00265
00266 void DOConnection::RemoveQuery(DOQuery* item)
00267 {
00268
00269 assert(this);
00270
00271 assert(item);
00272 assert(item->_refConnection == this);
00273
00274 DOConnection::QueryIterator::Check(item);
00275
00276 _countQuery--;
00277
00278 if (item->_nextConnection)
00279 item->_nextConnection->_prevConnection = item->_prevConnection;
00280 else
00281 _lastQuery = item->_prevConnection;
00282
00283 if (item->_prevConnection)
00284 item->_prevConnection->_nextConnection = item->_nextConnection;
00285 else
00286 _firstQuery = item->_nextConnection;
00287
00288 item->_prevConnection = (DOQuery*)0;
00289 item->_nextConnection = (DOQuery*)0;
00290 item->_refConnection = (DOConnection*)0;
00291 }
00292
00293 void DOConnection::DeleteAllQuery()
00294 {
00295
00296 assert(this);
00297
00298 for (DOQuery* item = GetFirstQuery(); item; item = GetFirstQuery())
00299 delete item;
00300 }
00301
00302 void DOConnection::ReplaceQuery(DOQuery* item, DOQuery* newItem)
00303 {
00304
00305 assert(this);
00306
00307 assert(item);
00308 assert(item->_refConnection == this);
00309
00310 assert(newItem);
00311 assert(newItem->_refConnection == (DOConnection*)0);
00312
00313 DOConnection::QueryIterator::Check(item, newItem);
00314
00315 if (item->_nextConnection)
00316 item->_nextConnection->_prevConnection = newItem;
00317 else
00318 _lastQuery = newItem;
00319
00320 if (item->_prevConnection)
00321 item->_prevConnection->_nextConnection = newItem;
00322 else
00323 _firstQuery = newItem;
00324
00325 newItem->_nextConnection = item->_nextConnection;
00326 newItem->_prevConnection = item->_prevConnection;
00327 item->_nextConnection = (DOQuery*)0;
00328 item->_prevConnection = (DOQuery*)0;
00329
00330 item->_refConnection = (DOConnection*)0;
00331 newItem->_refConnection = this;
00332 }
00333
00334 DOQuery* DOConnection::GetFirstQuery() const
00335 {
00336
00337 assert(this);
00338 return _firstQuery;
00339 }
00340
00341 DOQuery* DOConnection::GetLastQuery() const
00342 {
00343
00344 assert(this);
00345 return _lastQuery;
00346 }
00347
00348 DOQuery* DOConnection::GetNextQuery(DOQuery* pos) const
00349 {
00350
00351 assert(this);
00352
00353 if (pos == (DOQuery*)0)
00354 return _firstQuery;
00355
00356 assert(pos);
00357 assert(pos->_refConnection == this);
00358
00359 return pos->_nextConnection;
00360 }
00361
00362 DOQuery* DOConnection::GetPrevQuery(DOQuery* pos) const
00363 {
00364
00365 assert(this);
00366
00367 if (pos == (DOQuery*)0)
00368 return _lastQuery;
00369
00370 assert(pos);
00371 assert(pos->_refConnection == this);
00372
00373 return pos->_prevConnection;
00374 }
00375
00376 int DOConnection::GetQueryCount() const
00377 {
00378
00379 assert(this);
00380 return _countQuery;
00381 }
00382
00383 void DOConnection::MoveQueryFirst(DOQuery* item)
00384 {
00385
00386 assert(item);
00387 assert(item->_refConnection);
00388 item->_refConnection->RemoveQuery(item);
00389 AddQueryFirst(item);
00390 }
00391
00392 void DOConnection::MoveQueryLast(DOQuery* item)
00393 {
00394
00395 assert(item);
00396 assert(item->_refConnection);
00397 item->_refConnection->RemoveQuery(item);
00398 AddQueryLast(item);
00399 }
00400
00401 void DOConnection::MoveQueryAfter(DOQuery* item, DOQuery* pos)
00402 {
00403
00404 assert(item);
00405 assert(item->_refConnection);
00406 item->_refConnection->RemoveQuery(item);
00407 AddQueryAfter(item, pos);
00408 }
00409
00410 void DOConnection::MoveQueryBefore(DOQuery* item, DOQuery* pos)
00411 {
00412
00413 assert(item);
00414 assert(item->_refConnection);
00415 item->_refConnection->RemoveQuery(item);
00416 AddQueryBefore(item, pos);
00417 }
00418
00419 void DOConnection::SortQuery(int (*comp)(DOQuery*, DOQuery*))
00420 {
00421
00422 for (DOQuery* a = GetFirstQuery(); a; a = GetNextQuery(a))
00423 {
00424 DOQuery* b = GetNextQuery(a);
00425
00426 while (b && (comp(a, b) > 0))
00427 {
00428 DOQuery* c = GetPrevQuery(a);
00429 while (c && (comp(c, b) > 0))
00430 c = GetPrevQuery(c);
00431
00432 if (c)
00433 MoveQueryAfter(b, c);
00434 else
00435 MoveQueryFirst(b);
00436
00437 b = GetNextQuery(a);
00438 }
00439 }
00440 }
00441
00442 DOConnection::QueryIterator* DOConnection::QueryIterator::_first = 0;
00443 DOConnection::QueryIterator* DOConnection::QueryIterator::_last = 0;
00444
00445 DOConnection::QueryIterator::QueryIterator(
00446 const DOConnection* iterConnection,
00447 int (DOQuery::*method)() const,
00448 DOQuery* refQuery)
00449 {
00450 assert(iterConnection);
00451
00452 _iterConnection = iterConnection;
00453 _refQuery = _prevQuery = _nextQuery = refQuery;
00454 _prev = (QueryIterator*)0;
00455 _next = (QueryIterator*)0;
00456 _method = method;
00457 if (_last)
00458 {
00459 _last->_next = this;
00460 _prev = _last;
00461 _last = this;
00462 }
00463 else
00464 _first = _last = this;
00465 }
00466
00467 DOConnection::QueryIterator::QueryIterator(
00468 const DOConnection& iterConnection,
00469 int (DOQuery::*method)() const,
00470 DOQuery* refQuery)
00471 {
00472 assert(&iterConnection);
00473
00474 _iterConnection = &iterConnection;
00475 _refQuery = _prevQuery = _nextQuery = refQuery;
00476 _prev = (QueryIterator*)0;
00477 _next = (QueryIterator*)0;
00478 _method = method;
00479 if (_last)
00480 {
00481 _last->_next = this;
00482 _prev = _last;
00483 _last = this;
00484 }
00485 else
00486 _first = _last = this;
00487 }
00488
00489 DOConnection::QueryIterator::QueryIterator(
00490 const QueryIterator& iterator,
00491 int (DOQuery::*method)() const)
00492 {
00493 _iterConnection = iterator._iterConnection;
00494 _refQuery = iterator._refQuery;
00495 _prevQuery = iterator._prevQuery;
00496 _nextQuery = iterator._nextQuery;
00497 _prev = (QueryIterator*)0;
00498 _next = (QueryIterator*)0;
00499 _method = method;
00500 if (_last)
00501 {
00502 _last->_next = this;
00503 _prev = _last;
00504 _last = this;
00505 }
00506 else
00507 _first = _last = this;
00508 }
00509
00510 DOConnection::QueryIterator::~QueryIterator()
00511 {
00512 if (_next)
00513 _next->_prev = _prev;
00514 else
00515 _last = _prev;
00516
00517 if (_prev)
00518 _prev->_next = _next;
00519 else
00520 _first = _next;
00521 }
00522
00523 void DOConnection::QueryIterator::Check(DOQuery* itemQuery)
00524 {
00525 for (QueryIterator* item = _first; item; item = item->_next)
00526 {
00527 if (item->_prevQuery == itemQuery)
00528 {
00529 item->_prevQuery = item->_iterConnection->GetNextQuery(item->_prevQuery);
00530 item->_refQuery = 0;
00531 }
00532 if (item->_nextQuery == itemQuery)
00533 {
00534 item->_nextQuery = item->_iterConnection->GetPrevQuery(item->_nextQuery);
00535 item->_refQuery = 0;
00536 }
00537 }
00538 }
00539
00540 void DOConnection::QueryIterator::Check(DOQuery* itemQuery, DOQuery* newItemQuery)
00541 {
00542 for (QueryIterator* item = _first; item; item = item->_next)
00543 {
00544 if (item->_refQuery == itemQuery)
00545 {
00546 item->_refQuery = item->_prevQuery = item->_nextQuery = newItemQuery;
00547 }
00548 if (item->_prevQuery == itemQuery)
00549 {
00550 item->_prevQuery = newItemQuery;
00551 item->_refQuery = 0;
00552 }
00553 if (item->_nextQuery == itemQuery)
00554 {
00555 item->_nextQuery = newItemQuery;
00556 item->_refQuery = 0;
00557 }
00558 }
00559 }
00560
00561
00562
00563
00564