diff --git a/src/DIRAC/TransformationSystem/DB/TransformationDB.py b/src/DIRAC/TransformationSystem/DB/TransformationDB.py index 35929d2faab..3aeb8a9bc4e 100755 --- a/src/DIRAC/TransformationSystem/DB/TransformationDB.py +++ b/src/DIRAC/TransformationSystem/DB/TransformationDB.py @@ -434,8 +434,7 @@ def _getTransformationID(self, transName, connection=False): return S_OK(res["Value"][0][0]) def __deleteTransformation(self, transID, connection=False): - req = "DELETE FROM Transformations WHERE TransformationID=%d;" % transID - return self._update(req, conn=connection) + return self._update(f"DELETE FROM Transformations WHERE TransformationID={transID};", conn=connection) def __updateFilterQueries(self, connection=False): """Get filters for all defined input streams in all the transformations.""" @@ -738,12 +737,9 @@ def __addFilesToTransformation(self, transID, fileIDs, connection=False): fileIDs.remove(tupleIn[0]) if not fileIDs: return S_OK([]) - req = "INSERT INTO TransformationFiles (TransformationID,FileID,LastUpdate,InsertedTime) VALUES" - for fileID in fileIDs: - req = "%s (%d,%d,UTC_TIMESTAMP(),UTC_TIMESTAMP())," % (req, transID, fileID) - req = req.rstrip(",") - res = self._update(req, conn=connection) - if not res["OK"]: + values = [(transID, fileID) for fileID in fileIDs] + req = "INSERT INTO TransformationFiles (TransformationID,FileID,LastUpdate,InsertedTime) VALUES (%s, %s, UTC_TIMESTAMP(), UTC_TIMESTAMP())" + if not (res := self._updatemany(req, values, conn=connection))["OK"]: return res return S_OK(fileIDs) @@ -801,11 +797,9 @@ def __assignTransformationFile(self, transID, taskID, se, fileIDs, connection=Fa res = self._update(req, conn=connection) if not res["OK"]: gLogger.error("Failed to assign file to task", res["Message"]) - fileTuples = [] - for fileID in fileIDs: - fileTuples.append("(%d,%d,%d)" % (transID, fileID, taskID)) - req = f"INSERT INTO TransformationFileTasks (TransformationID,FileID,TaskID) VALUES {','.join(fileTuples)}" - res = self._update(req, conn=connection) + values = [(transID, fileID, taskID) for fileID in fileIDs] + req = "INSERT INTO TransformationFileTasks (TransformationID,FileID,TaskID) VALUES (%s, %s, %s)" + res = self._updatemany(req, values, conn=connection) if not res["OK"]: gLogger.error("Failed to assign file to task", res["Message"]) return res