@@ -1054,6 +1054,55 @@ const DBImgInfoList DBManager::getInfosForKeyword(int UID, const QString &keywor
10541054 return infos;
10551055}
10561056
1057+ bool DBManager::updateImgPath (const QString &oldPath, const QString &newPath)
1058+ {
1059+ QString oldHash = LibUnionImage_NameSpace::hashByString (oldPath);
1060+ QString newHash = LibUnionImage_NameSpace::hashByString (newPath);
1061+
1062+ QMutexLocker mutex (&m_dbMutex);
1063+
1064+ // 更新 AlbumTable3 表的 PathHash
1065+ if (!m_query->exec (" BEGIN IMMEDIATE TRANSACTION" )) {
1066+ qDebug () << m_query->lastError ();
1067+ return false ;
1068+ }
1069+ QString updateAlbumQs = " UPDATE AlbumTable3 SET PathHash=:newHash WHERE PathHash=:oldHash" ;
1070+ if (!m_query->prepare (updateAlbumQs)) {
1071+ // 处理错误
1072+ }
1073+ m_query->bindValue (" :newHash" , newHash);
1074+ m_query->bindValue (" :oldHash" , oldHash);
1075+ if (!m_query->exec ()) {
1076+ return false ;
1077+ }
1078+ if (!m_query->exec (" COMMIT" )) {
1079+ qDebug () << m_query->lastError ();
1080+ return false ;
1081+ }
1082+
1083+ // 更新 ImageTable3 表的 PathHash 和 filePath
1084+ if (!m_query->exec (" BEGIN IMMEDIATE TRANSACTION" )) {
1085+ qDebug () << m_query->lastError ();
1086+ return false ;
1087+ }
1088+ QString updateImageQs = " UPDATE ImageTable3 SET PathHash=:newHash, filePath=:newPath WHERE PathHash=:oldHash" ;
1089+ if (!m_query->prepare (updateImageQs)) {
1090+ // 处理错误
1091+ }
1092+ m_query->bindValue (" :newHash" , newHash);
1093+ m_query->bindValue (" :newPath" , newPath);
1094+ m_query->bindValue (" :oldHash" , oldHash);
1095+ if (!m_query->exec ()) {
1096+ // 处理错误
1097+ return false ;
1098+ }
1099+ if (!m_query->exec (" COMMIT" )) {
1100+ // qDebug() << m_query->lastError();
1101+ return false ;
1102+ }
1103+ return true ;
1104+ }
1105+
10571106const QMultiMap<QString, QString> DBManager::getAllPathAlbumNames () const
10581107{
10591108 QMutexLocker mutex (&m_dbMutex);
0 commit comments