Mercurial > hg > orthanc
comparison OrthancServer/DatabaseWrapper.cpp @ 237:16a4ac70bd8a
last change and export
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 30 Nov 2012 15:45:15 +0100 |
parents | c11273198cef |
children | e4148b0ab1d0 |
comparison
equal
deleted
inserted
replaced
236:6d9be2b470b4 | 237:16a4ac70bd8a |
---|---|
507 s.BindString(3, boost::posix_time::to_iso_string(date)); | 507 s.BindString(3, boost::posix_time::to_iso_string(date)); |
508 s.Run(); | 508 s.Run(); |
509 } | 509 } |
510 | 510 |
511 | 511 |
512 void DatabaseWrapper::GetChanges(Json::Value& target, | 512 void DatabaseWrapper::GetChangesInternal(Json::Value& target, |
513 int64_t since, | 513 SQLite::Statement& s, |
514 unsigned int maxResults) | 514 int64_t since, |
515 { | 515 unsigned int maxResults) |
516 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? ORDER BY seq LIMIT ?"); | 516 { |
517 s.BindInt(0, since); | |
518 s.BindInt(1, maxResults + 1); | |
519 | |
520 Json::Value changes = Json::arrayValue; | 517 Json::Value changes = Json::arrayValue; |
521 int64_t last = 0; | 518 int64_t last = since; |
522 | 519 |
523 while (changes.size() < maxResults && s.Step()) | 520 while (changes.size() < maxResults && s.Step()) |
524 { | 521 { |
525 int64_t seq = s.ColumnInt(0); | 522 int64_t seq = s.ColumnInt(0); |
526 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1)); | 523 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1)); |
541 changes.append(item); | 538 changes.append(item); |
542 } | 539 } |
543 | 540 |
544 target = Json::objectValue; | 541 target = Json::objectValue; |
545 target["Changes"] = changes; | 542 target["Changes"] = changes; |
546 target["PendingChanges"] = (changes.size() == maxResults && s.Step()); | 543 target["Done"] = !(changes.size() == maxResults && s.Step()); |
547 target["LastSeq"] = static_cast<int>(last); | 544 target["Last"] = static_cast<int>(last); |
545 } | |
546 | |
547 | |
548 void DatabaseWrapper::GetChanges(Json::Value& target, | |
549 int64_t since, | |
550 unsigned int maxResults) | |
551 { | |
552 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? ORDER BY seq LIMIT ?"); | |
553 s.BindInt(0, since); | |
554 s.BindInt(1, maxResults + 1); | |
555 GetChangesInternal(target, s, since, maxResults); | |
556 } | |
557 | |
558 void DatabaseWrapper::GetLastChange(Json::Value& target) | |
559 { | |
560 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1"); | |
561 GetChangesInternal(target, s, 0, 1); | |
548 } | 562 } |
549 | 563 |
550 | 564 |
551 void DatabaseWrapper::LogExportedResource(ResourceType resourceType, | 565 void DatabaseWrapper::LogExportedResource(ResourceType resourceType, |
552 const std::string& publicId, | 566 const std::string& publicId, |
572 s.Run(); | 586 s.Run(); |
573 } | 587 } |
574 | 588 |
575 | 589 |
576 void DatabaseWrapper::GetExportedResources(Json::Value& target, | 590 void DatabaseWrapper::GetExportedResources(Json::Value& target, |
591 SQLite::Statement& s, | |
577 int64_t since, | 592 int64_t since, |
578 unsigned int maxResults) | 593 unsigned int maxResults) |
579 { | 594 { |
580 SQLite::Statement s(db_, SQLITE_FROM_HERE, | |
581 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?"); | |
582 s.BindInt(0, since); | |
583 s.BindInt(1, maxResults + 1); | |
584 | |
585 Json::Value changes = Json::arrayValue; | 595 Json::Value changes = Json::arrayValue; |
586 int64_t last = 0; | 596 int64_t last = since; |
587 | 597 |
588 while (changes.size() < maxResults && s.Step()) | 598 while (changes.size() < maxResults && s.Step()) |
589 { | 599 { |
590 int64_t seq = s.ColumnInt(0); | 600 int64_t seq = s.ColumnInt(0); |
591 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1)); | 601 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1)); |
623 | 633 |
624 changes.append(item); | 634 changes.append(item); |
625 } | 635 } |
626 | 636 |
627 target = Json::objectValue; | 637 target = Json::objectValue; |
628 target["Changes"] = changes; | 638 target["Exports"] = changes; |
629 target["PendingChanges"] = (changes.size() == maxResults && s.Step()); | 639 target["Done"] = !(changes.size() == maxResults && s.Step()); |
630 target["LastSeq"] = static_cast<int>(last); | 640 target["Last"] = static_cast<int>(last); |
641 } | |
642 | |
643 | |
644 void DatabaseWrapper::GetExportedResources(Json::Value& target, | |
645 int64_t since, | |
646 unsigned int maxResults) | |
647 { | |
648 SQLite::Statement s(db_, SQLITE_FROM_HERE, | |
649 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?"); | |
650 s.BindInt(0, since); | |
651 s.BindInt(1, maxResults + 1); | |
652 GetExportedResources(target, s, since, maxResults); | |
653 } | |
654 | |
655 | |
656 void DatabaseWrapper::GetLastExportedResource(Json::Value& target) | |
657 { | |
658 SQLite::Statement s(db_, SQLITE_FROM_HERE, | |
659 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); | |
660 GetExportedResources(target, s, 0, 1); | |
631 } | 661 } |
632 | 662 |
633 | 663 |
634 | 664 |
635 | 665 |