rework save routines

This commit is contained in:
Herwig Birke
2018-07-25 09:24:14 +02:00
parent fc79a3e7a0
commit f72e46308c
7 changed files with 218 additions and 162 deletions
+10 -3
View File
@@ -192,9 +192,11 @@ bool cChapterList::save()
querySelect.prepare("SELECT id FROM chapter WHERE _rowid_=(SELECT MAX(_rowid_) FROM chapter);");
queryDelete.prepare("DELETE FROM chapter WHERE id=:id;");
for(int x = count()-1;x >= 0;x--)
cChapterList::iterator chapterIterator = begin();
while(chapterIterator != end())
{
cChapter* lpChapter = at(x);
cChapter* lpChapter = *chapterIterator;
if(lpChapter->deleted())
{
@@ -205,7 +207,7 @@ bool cChapterList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpChapter);
lpChapter = 0;
}
else if(lpChapter->id() != -1)
{
@@ -244,6 +246,11 @@ bool cChapterList::save()
querySelect.next();
lpChapter->setID(querySelect.value("id").toInt());
}
if(!lpChapter)
chapterIterator = erase(chapterIterator);
else
chapterIterator++;
}
return(true);
+29 -21
View File
@@ -511,9 +511,11 @@ bool cCharacterList::save()
imageDelete.prepare("DELETE FROM characterImage WHERE characterID=:characterID;");
imageAdd.prepare("INSERT INTO characterImage (characterID, name, description, image) VALUES (:characterID, :name, :description, :image);");
for(int x = 0;x < count();x++)
cCharacterList::iterator characterIterator = begin();
while(characterIterator != end())
{
cCharacter* lpCharacter = at(x);
cCharacter* lpCharacter = *characterIterator;
if(lpCharacter->deleted())
{
@@ -524,7 +526,7 @@ bool cCharacterList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpCharacter);
lpCharacter = 0;
}
else if(lpCharacter->id() != -1)
{
@@ -602,28 +604,34 @@ bool cCharacterList::save()
lpCharacter->setID(querySelect.value("id").toInt());
}
imageDelete.bindValue(":characterID", lpCharacter->id());
if(!imageDelete.exec())
if(!lpCharacter)
characterIterator = erase(characterIterator);
else
{
myDebug << imageDelete.lastError().text();
return(false);
}
QList<cImage*> images = lpCharacter->images();
for(int x = 0;x < images.count();x++)
{
cImage* lpImage = images.at(x);
imageAdd.bindValue(":characterID", lpCharacter->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
imageDelete.bindValue(":characterID", lpCharacter->id());
if(!imageDelete.exec())
{
myDebug << imageAdd.lastError().text();
myDebug << imageDelete.lastError().text();
return(false);
}
QList<cImage*> images = lpCharacter->images();
for(int x = 0;x < images.count();x++)
{
cImage* lpImage = images.at(x);
imageAdd.bindValue(":characterID", lpCharacter->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
{
myDebug << imageAdd.lastError().text();
return(false);
}
}
characterIterator++;
}
}
+29 -21
View File
@@ -206,9 +206,11 @@ bool cObjectList::save()
imageDelete.prepare("DELETE FROM objectImage WHERE objectID=:objectID;");
imageAdd.prepare("INSERT INTO objectImage (objectID, name, description, image) VALUES (:objectID, :name, :description, :image);");
for(int x = count()-1;x >= 0;x--)
cObjectList::iterator objectIterator = begin();
while(objectIterator != end())
{
cObject* lpObject = at(x);
cObject* lpObject = *objectIterator;
if(lpObject->deleted())
{
@@ -219,7 +221,7 @@ bool cObjectList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpObject);
lpObject = 0;
}
else if(lpObject->id() != -1)
{
@@ -255,28 +257,34 @@ bool cObjectList::save()
lpObject->setID(querySelect.value("id").toInt());
}
imageDelete.bindValue(":objectID", lpObject->id());
if(!imageDelete.exec())
if(!lpObject)
objectIterator = erase(objectIterator);
else
{
myDebug << imageDelete.lastError().text();
return(false);
}
QList<cImage*> images = lpObject->images();
for(int x = 0;x < images.count();x++)
{
cImage* lpImage = images.at(x);
imageAdd.bindValue(":objectID", lpObject->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
imageDelete.bindValue(":objectID", lpObject->id());
if(!imageDelete.exec())
{
myDebug << imageAdd.lastError().text();
myDebug << imageDelete.lastError().text();
return(false);
}
QList<cImage*> images = lpObject->images();
for(int x = 0;x < images.count();x++)
{
cImage* lpImage = images.at(x);
imageAdd.bindValue(":objectID", lpObject->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
{
myDebug << imageAdd.lastError().text();
return(false);
}
}
objectIterator++;
}
}
+10 -3
View File
@@ -167,9 +167,11 @@ bool cPartList::save()
querySelect.prepare("SELECT id FROM part WHERE _rowid_=(SELECT MAX(_rowid_) FROM part);");
queryDelete.prepare("DELETE FROM part WHERE id=:id;");
for(int x = count()-1;x >= 0;x--)
cPartList::iterator partIterator = begin();
while(partIterator != end())
{
cPart* lpPart = at(x);
cPart* lpPart = *partIterator;
if(lpPart->deleted())
{
@@ -180,7 +182,7 @@ bool cPartList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpPart);
lpPart = 0;
}
else if(lpPart->id() != -1)
{
@@ -217,6 +219,11 @@ bool cPartList::save()
querySelect.next();
lpPart->setID(querySelect.value("id").toInt());
}
if(!lpPart)
partIterator = erase(partIterator);
else
partIterator++;
}
return(true);
+29 -21
View File
@@ -218,9 +218,11 @@ bool cPlaceList::save()
imageDelete.prepare("DELETE FROM placeImage WHERE placeID=:placeID;");
imageAdd.prepare("INSERT INTO placeImage (placeID, name, description, image) VALUES (:placeID, :name, :description, :image);");
for(int x = count()-1;x >= 0;x--)
cPlaceList::iterator placeIterator = begin();
while(placeIterator != end())
{
cPlace* lpPlace = at(x);
cPlace* lpPlace = *placeIterator;
if(lpPlace->deleted())
{
@@ -231,7 +233,7 @@ bool cPlaceList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpPlace);
lpPlace = 0;
}
else if(lpPlace->id() != -1)
{
@@ -269,28 +271,34 @@ bool cPlaceList::save()
lpPlace->setID(querySelect.value("id").toInt());
}
imageDelete.bindValue(":placeID", lpPlace->id());
if(!imageDelete.exec())
if(!lpPlace)
placeIterator = erase(placeIterator);
else
{
myDebug << imageDelete.lastError().text();
return(false);
}
QList<cImage*> images = lpPlace->images();
for(int x = 0;x < images.count();x++)
{
cImage* lpImage = images.at(x);
imageAdd.bindValue(":placeID", lpPlace->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
imageDelete.bindValue(":placeID", lpPlace->id());
if(!imageDelete.exec())
{
myDebug << imageAdd.lastError().text();
myDebug << imageDelete.lastError().text();
return(false);
}
QList<cImage*> images = lpPlace->images();
for(int x = 0;x < images.count();x++)
{
cImage* lpImage = images.at(x);
imageAdd.bindValue(":placeID", lpPlace->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
{
myDebug << imageAdd.lastError().text();
return(false);
}
}
placeIterator++;
}
}
+61 -53
View File
@@ -353,9 +353,11 @@ bool cRechercheList::save()
placeDelete.prepare("DELETE FROM recherchePlace WHERE rechercheID=:rechercheID;");
placeAdd.prepare("INSERT INTO recherchePlace (rechercheID, placeID, description) VALUES (:rechercheID, :placeID, :description);");
for(int x = count()-1;x >= 0;x--)
cRechercheList::iterator rechercheIterator = begin();
while(rechercheIterator != end())
{
cRecherche* lpRecherche = at(x);
cRecherche* lpRecherche = *rechercheIterator;
imageDelete.bindValue(":rechercheID", lpRecherche->id());
if(!imageDelete.exec())
@@ -394,7 +396,7 @@ bool cRechercheList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpRecherche);
lpRecherche = 0;
}
else if(lpRecherche->id() != -1)
{
@@ -430,72 +432,78 @@ bool cRechercheList::save()
lpRecherche->setID(querySelect.value("id").toInt());
}
QList<cImage*> images = lpRecherche->images();
for(int x = 0;x < images.count();x++)
if(!lpRecherche)
rechercheIterator = erase(rechercheIterator);
else
{
cImage* lpImage = images.at(x);
QList<cImage*> images = lpRecherche->images();
imageAdd.bindValue(":rechercheID", lpRecherche->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
for(int x = 0;x < images.count();x++)
{
myDebug << imageAdd.lastError().text();
return(false);
cImage* lpImage = images.at(x);
imageAdd.bindValue(":rechercheID", lpRecherche->id());
imageAdd.bindValue(":name", lpImage->name());
imageAdd.bindValue(":description", textDocument2Blob(lpImage->description()));
imageAdd.bindValue(":image", image2Blob(lpImage->image()));
if(!imageAdd.exec())
{
myDebug << imageAdd.lastError().text();
return(false);
}
}
}
QList<cCharacterDescription*> characters = lpRecherche->characterList();
QList<cCharacterDescription*> characters = lpRecherche->characterList();
for(int x = 0;x < characters.count();x++)
{
cCharacterDescription* lpCharacterDescription = characters.at(x);
cCharacter* lpCharacter = lpCharacterDescription->character();
characterAdd.bindValue(":rechercheID", lpRecherche->id());
characterAdd.bindValue(":characterID", lpCharacter->id());
characterAdd.bindValue(":description", textDocument2Blob(lpCharacterDescription->description()));
if(!characterAdd.exec())
for(int x = 0;x < characters.count();x++)
{
myDebug << characterAdd.lastError().text();
return(false);
cCharacterDescription* lpCharacterDescription = characters.at(x);
cCharacter* lpCharacter = lpCharacterDescription->character();
characterAdd.bindValue(":rechercheID", lpRecherche->id());
characterAdd.bindValue(":characterID", lpCharacter->id());
characterAdd.bindValue(":description", textDocument2Blob(lpCharacterDescription->description()));
if(!characterAdd.exec())
{
myDebug << characterAdd.lastError().text();
return(false);
}
}
}
QList<cObjectDescription*> objects = lpRecherche->objectList();
QList<cObjectDescription*> objects = lpRecherche->objectList();
for(int x = 0;x < objects.count();x++)
{
cObjectDescription* lpObjectDescription = objects.at(x);
cObject* lpObject = lpObjectDescription->object();
objectAdd.bindValue(":rechercheID", lpRecherche->id());
objectAdd.bindValue(":objectID", lpObject->id());
objectAdd.bindValue(":description", textDocument2Blob(lpObjectDescription->description()));
if(!objectAdd.exec())
for(int x = 0;x < objects.count();x++)
{
myDebug << objectAdd.lastError().text();
return(false);
cObjectDescription* lpObjectDescription = objects.at(x);
cObject* lpObject = lpObjectDescription->object();
objectAdd.bindValue(":rechercheID", lpRecherche->id());
objectAdd.bindValue(":objectID", lpObject->id());
objectAdd.bindValue(":description", textDocument2Blob(lpObjectDescription->description()));
if(!objectAdd.exec())
{
myDebug << objectAdd.lastError().text();
return(false);
}
}
}
QList<cPlaceDescription*> places = lpRecherche->placeList();
QList<cPlaceDescription*> places = lpRecherche->placeList();
for(int x = 0;x < places.count();x++)
{
cPlaceDescription* lpPlaceDescription = places.at(x);
cPlace* lpPlace = lpPlaceDescription->place();
placeAdd.bindValue(":rechercheID", lpRecherche->id());
placeAdd.bindValue(":placeID", lpPlace->id());
placeAdd.bindValue(":description", textDocument2Blob(lpPlaceDescription->description()));
if(!placeAdd.exec())
for(int x = 0;x < places.count();x++)
{
myDebug << placeAdd.lastError().text();
return(false);
cPlaceDescription* lpPlaceDescription = places.at(x);
cPlace* lpPlace = lpPlaceDescription->place();
placeAdd.bindValue(":rechercheID", lpRecherche->id());
placeAdd.bindValue(":placeID", lpPlace->id());
placeAdd.bindValue(":description", textDocument2Blob(lpPlaceDescription->description()));
if(!placeAdd.exec())
{
myDebug << placeAdd.lastError().text();
return(false);
}
}
rechercheIterator++;
}
}
+50 -40
View File
@@ -10,6 +10,8 @@
#include <QSqlQuery>
#include <QSqlError>
#include <QMutableListIterator>
cScene::cScene(qint32 iID, QObject *parent) :
QObject(parent),
@@ -471,9 +473,11 @@ bool cSceneList::save()
objectDelete.prepare("DELETE FROM sceneObject WHERE sceneID=:sceneID;");
objectAdd.prepare("INSERT INTO sceneObject (sceneID, objectID, description) VALUES (:sceneID, :objectID, :description);");
for(int x = count()-1;x >= 0;x--)
cSceneList::iterator sceneIterator = begin();
while(sceneIterator != end())
{
cScene* lpScene = at(x);
cScene* lpScene = *sceneIterator;
characterDelete.bindValue(":sceneID", lpScene->id());
if(!characterDelete.exec())
@@ -505,7 +509,7 @@ bool cSceneList::save()
myDebug << queryDelete.lastError().text();
return(false);
}
this->removeOne(lpScene);
lpScene = 0;
}
else if(lpScene->id() != -1)
{
@@ -553,55 +557,61 @@ bool cSceneList::save()
lpScene->setID(querySelect.value("id").toInt());
}
QList<cCharacterDescription*> character = lpScene->characterList();
for(int x = 0;x < character.count();x++)
if(!lpScene)
sceneIterator = erase(sceneIterator);
else
{
cCharacterDescription* lpCharacter = character.at(x);
QList<cCharacterDescription*> character = lpScene->characterList();
characterAdd.bindValue(":sceneID", lpScene->id());
characterAdd.bindValue(":characterID", lpCharacter->character()->id());
characterAdd.bindValue(":description", textDocument2Blob(lpCharacter->description()));
if(!characterAdd.exec())
for(int x = 0;x < character.count();x++)
{
myDebug << characterAdd.lastError().text();
return(false);
cCharacterDescription* lpCharacter = character.at(x);
characterAdd.bindValue(":sceneID", lpScene->id());
characterAdd.bindValue(":characterID", lpCharacter->character()->id());
characterAdd.bindValue(":description", textDocument2Blob(lpCharacter->description()));
if(!characterAdd.exec())
{
myDebug << characterAdd.lastError().text();
return(false);
}
}
}
QList<cPlaceDescription*> place = lpScene->placeList();
QList<cPlaceDescription*> place = lpScene->placeList();
for(int x = 0;x < place.count();x++)
{
cPlaceDescription* lpPlace = place.at(x);
placeAdd.bindValue(":sceneID", lpScene->id());
placeAdd.bindValue(":placeID", lpPlace->place()->id());
placeAdd.bindValue(":description", textDocument2Blob(lpPlace->description()));
if(!placeAdd.exec())
for(int x = 0;x < place.count();x++)
{
myDebug << placeAdd.lastError().text();
return(false);
cPlaceDescription* lpPlace = place.at(x);
placeAdd.bindValue(":sceneID", lpScene->id());
placeAdd.bindValue(":placeID", lpPlace->place()->id());
placeAdd.bindValue(":description", textDocument2Blob(lpPlace->description()));
if(!placeAdd.exec())
{
myDebug << placeAdd.lastError().text();
return(false);
}
}
}
QList<cObjectDescription*> object = lpScene->objectList();
QList<cObjectDescription*> object = lpScene->objectList();
for(int x = 0;x < object.count();x++)
{
cObjectDescription* lpObject = object.at(x);
objectAdd.bindValue(":sceneID", lpScene->id());
objectAdd.bindValue(":objectID", lpObject->object()->id());
objectAdd.bindValue(":description", textDocument2Blob(lpObject->description()));
if(!objectAdd.exec())
for(int x = 0;x < object.count();x++)
{
myDebug << objectAdd.lastError().text();
return(false);
cObjectDescription* lpObject = object.at(x);
objectAdd.bindValue(":sceneID", lpScene->id());
objectAdd.bindValue(":objectID", lpObject->object()->id());
objectAdd.bindValue(":description", textDocument2Blob(lpObject->description()));
if(!objectAdd.exec())
{
myDebug << objectAdd.lastError().text();
return(false);
}
}
sceneIterator++;
}
}