comparison OrthancServer/DatabaseWrapper.cpp @ 232:5368bbe813cf

refactoring of attachments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Nov 2012 14:22:27 +0100
parents 8098448bd827
children c11273198cef
comparison
equal deleted inserted replaced
231:8098448bd827 232:5368bbe813cf
374 } 374 }
375 } 375 }
376 376
377 377
378 378
379 void DatabaseWrapper::AttachFile(int64_t id, 379 void DatabaseWrapper::AddAttachment(int64_t id,
380 AttachedFileType contentType, 380 const FileInfo& attachment)
381 const std::string& fileUuid,
382 uint64_t compressedSize,
383 uint64_t uncompressedSize,
384 CompressionType compressionType)
385 { 381 {
386 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?)"); 382 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?)");
387 s.BindInt(0, id); 383 s.BindInt(0, id);
384 s.BindInt(1, attachment.GetFileType());
385 s.BindString(2, attachment.GetUuid());
386 s.BindInt(3, attachment.GetCompressedSize());
387 s.BindInt(4, attachment.GetUncompressedSize());
388 s.BindInt(5, attachment.GetCompressionType());
389 s.Run();
390 }
391
392 bool DatabaseWrapper::LookupAttachment(FileInfo& attachment,
393 int64_t id,
394 FileType contentType)
395 {
396 SQLite::Statement s(db_, SQLITE_FROM_HERE,
397 "SELECT uuid, uncompressedSize, compressionType, compressedSize FROM AttachedFiles WHERE id=? AND fileType=?");
398 s.BindInt(0, id);
388 s.BindInt(1, contentType); 399 s.BindInt(1, contentType);
389 s.BindString(2, fileUuid);
390 s.BindInt(3, compressedSize);
391 s.BindInt(4, uncompressedSize);
392 s.BindInt(5, compressionType);
393 s.Run();
394 }
395
396 bool DatabaseWrapper::LookupFile(int64_t id,
397 AttachedFileType contentType,
398 std::string& fileUuid,
399 uint64_t& compressedSize,
400 uint64_t& uncompressedSize,
401 CompressionType& compressionType)
402 {
403 SQLite::Statement s(db_, SQLITE_FROM_HERE,
404 "SELECT uuid, compressedSize, uncompressedSize, compressionType FROM AttachedFiles WHERE id=? AND fileType=?");
405 s.BindInt(0, id);
406 s.BindInt(1, contentType);
407 400
408 if (!s.Step()) 401 if (!s.Step())
409 { 402 {
410 return false; 403 return false;
411 } 404 }
412 else 405 else
413 { 406 {
414 fileUuid = s.ColumnString(0); 407 attachment = FileInfo(s.ColumnString(0),
415 compressedSize = s.ColumnInt(1); 408 contentType,
416 uncompressedSize = s.ColumnInt(2); 409 s.ColumnInt(1),
417 compressionType = static_cast<CompressionType>(s.ColumnInt(3)); 410 static_cast<CompressionType>(s.ColumnInt(2)),
411 s.ColumnInt(3));
418 return true; 412 return true;
419 } 413 }
420 } 414 }
421 415
422 void DatabaseWrapper::SetMainDicomTags(int64_t id, 416 void DatabaseWrapper::SetMainDicomTags(int64_t id,