From d6a03873799cf73d25f7231423a01df907ba0c90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mikko=20Kein=C3=A4nen?= Date: Fri, 22 Oct 2010 00:55:38 +0300 Subject: [PATCH] Created temporary data object was not deleted. --- src/db/dbmediaimagecontainer.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/db/dbmediaimagecontainer.cpp b/src/db/dbmediaimagecontainer.cpp index e1f11c3..dd116d0 100644 --- a/src/db/dbmediaimagecontainer.cpp +++ b/src/db/dbmediaimagecontainer.cpp @@ -48,18 +48,27 @@ int DbMediaImageContainer::insertDataObjectToModel(const EmuFrontObject *efo) const MediaImageContainer *mic = dynamic_cast(efo); + if (!mic->getFilePath()) + throw new EmuFrontException("Cannot install media image " + "container to database without a file path object!"); + // check if this media image container is already in the database + + // Two possible solutions: + // * multiple media image containers with matching checksum will not be stored at all + // (only the first instance will be stored) + // * multiple media image containers with matching checksum will be stored + // if each instance is in a different file path + EmuFrontObject *o = getFileByChecksum(mic->getCheckSum()); int fileId = o ? o->getId() : -1; - /*int fileId = getMediaImageContainer(mic->getCheckSum());*/ if (fileId >= 0) { + // ok, we have a matching file, we could still create a new media image instance to the database qDebug() << "Media image container already in db with id " << fileId << "."; + delete o; return fileId; } - if (!mic->getFilePath()) - throw new EmuFrontException("Cannot install media image " - "container to database without a file path object!"); QMap images = mic->getMediaImages(); QList ids = dbMediaImage->storeMediaImages(images); -- 1.7.9.5