"FROM Client,Job WHERE Client.ClientId=Job.ClientId AND JobStatus IN ('T','W') "
"AND Type='B' ORDER BY StartTime DESC LIMIT 20";
-const char *uar_print_jobs =
+const char *uar_print_jobs =
"SELECT DISTINCT JobId,Level,JobFiles,JobBytes,StartTime,VolumeName"
" FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
" WHERE JobId IN (%s) "
#include "cats.h"
/* Get the list of the last recent version with a given jobid list */
-const char *select_recent_version[4] = {
+const char *select_recent_version_with_basejob[4] = {
/* MySQL */
"SELECT max(StartTime), Job.JobId, FileIndex, PathId, FilenameId, LStat, MD5 "
"FROM "
- "(SELECT JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
+ "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
"UNION ALL "
- "SELECT BaseFiles.JobId, PathId, FilenameId, FileIndex, LStat, MD5 "
+ "SELECT File.FileId, BaseFiles.JobId, PathId, FilenameId, File.FileIndex, LStat, MD5 "
"FROM BaseFiles JOIN File USING (FileId) "
"WHERE BaseFiles.JobId IN (%s) "
") AS T JOIN Job USING (JobId) "
"GROUP BY PathId, FilenameId ",
/* Postgresql */
- "SELECT DISTINCT ON (FilenameId, PathId) StartTime, JobId, FileId, FileIndex, PathId, FilenameId, LStat, MD5 "
+ "SELECT DISTINCT ON (FilenameId, PathId) StartTime, JobId, FileId, FileIndex, PathId, "
+ "FilenameId, LStat, MD5 "
"FROM "
- "(SELECT JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
+ "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
"UNION ALL "
- "SELECT BaseFiles.JobId, PathId, FilenameId, FileIndex, LStat, MD5 "
+ "SELECT File.FileId, BaseFiles.JobId, PathId, FilenameId, File.FileIndex, LStat, MD5 "
"FROM BaseFiles JOIN File USING (FileId) "
"WHERE BaseFiles.JobId IN (%s) "
") AS T JOIN Job USING (JobId) "
"ORDER BY FilenameId, PathId, StartTime DESC ",
/* SQLite */
- "SELECT max(StartTime), JobId, FileId, FileIndex, PathId, FilenameId, LStat "
+ "SELECT max(StartTime), JobId, FileIndex, PathId, FilenameId, LStat, MD5 "
"FROM "
- "(SELECT JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
+ "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
"UNION ALL "
- "SELECT BaseFiles.JobId, PathId, FilenameId, FileIndex, LStat, MD5 "
+ "SELECT File.FileId, BaseFiles.JobId, PathId, FilenameId, File.FileIndex, LStat, MD5 "
"FROM BaseFiles JOIN File USING (FileId) "
"WHERE BaseFiles.JobId IN (%s) "
") AS T JOIN Job USING (JobId) "
"GROUP BY PathId, FilenameId ",
/* SQLite3 */
- "SELECT max(StartTime), JobId, FileId, FileIndex, PathId, FilenameId, LStat "
- "(SELECT JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
+ "SELECT max(StartTime), JobId, FileIndex, PathId, FilenameId, LStat, MD5 "
+ "(SELECT FileId, JobId, PathId, FilenameId, FileIndex, LStat, MD5 FROM File WHERE JobId IN (%s) "
"UNION ALL "
- "SELECT BaseFiles.JobId, PathId, FilenameId, FileIndex, LStat, MD5 "
+ "SELECT File.FileId, BaseFiles.JobId, PathId, FilenameId, File.FileIndex, LStat, MD5 "
"FROM BaseFiles JOIN File USING (FileId) "
"WHERE BaseFiles.JobId IN (%s) "
") AS T JOIN Job USING (JobId) "
"GROUP BY PathId, FilenameId "
};
+/* Get the list of the last recent version with a given BaseJob jobid list */
+const char *select_recent_version[4] = {
+ /* MySQL */
+ "SELECT max(StartTime), JobId, FileId, FileIndex, PathId, FilenameId, LStat, MD5 "
+ "FROM File JOIN Job USING (JobId) "
+ "WHERE JobId IN (%s) "
+ "GROUP BY PathId, FilenameId",
+
+ /* Postgresql */
+ "SELECT DISTINCT ON (FilenameId, PathId) StartTime, JobId, FileId, FileIndex, PathId, FilenameId, LStat, MD5 "
+ "FROM File JOIN Job USING (JobId) "
+ "WHERE JobId IN (%s) "
+ "ORDER BY FilenameId, PathId, StartTime DESC",
+
+ /* SQLite */
+ "SELECT max(StartTime), JobId, FileId, FileIndex, PathId, FilenameId, LStat, MD5 "
+ "FROM File JOIN Job USING (JobId) "
+ "WHERE JobId IN (%s) "
+ "GROUP BY PathId, FilenameId",
+
+ /* SQLite3 */
+ "SELECT max(StartTime), JobId, FileId, FileIndex, PathId, FilenameId, LStat, MD5 "
+ "FROM File JOIN Job USING (JobId) "
+ "WHERE JobId IN (%s) "
+ "GROUP BY PathId, FilenameId"
+};
+
/* ====== ua_prune.c */
/* List of SQL commands to create temp table and indicies */
*/
bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids)
{
+ POOL_MEM buf;
bool ret=false;
db_lock(mdb);
goto bail_out;
}
+ Mmsg(buf, select_recent_version[db_type], jobids);
+
Mmsg(mdb->cmd,
"CREATE TEMPORARY TABLE new_basefile%lld AS ( "
//"CREATE TABLE new_basefile%lld AS ( "
- "SELECT Path.Path AS Path, Filename.Name AS Name, File.FileIndex AS FileIndex,"
- "File.JobId AS JobId, File.LStat AS LStat, File.FileId AS FileId, "
- "File.MD5 AS MD5 "
- "FROM ( "
- "SELECT max(FileId) as FileId, PathId, FilenameId "
- "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F "
- "GROUP BY PathId, FilenameId "
- ") AS Temp "
+ "SELECT Path.Path AS Path, Filename.Name AS Name, Temp.FileIndex AS FileIndex,"
+ "Temp.JobId AS JobId, Temp.LStat AS LStat, Temp.FileId AS FileId, "
+ "Temp.MD5 AS MD5 "
+ "FROM ( %s ) AS Temp "
"JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
"JOIN Path ON (Path.PathId = Temp.PathId) "
- "JOIN File ON (File.FileId = Temp.FileId) "
- "WHERE File.FileIndex > 0)",
- (uint64_t)jcr->JobId, jobids);
+ "WHERE Temp.FileIndex > 0)",
+ (uint64_t)jcr->JobId, buf.c_str());
ret = QUERY_DB(jcr, mdb, mdb->cmd);
bail_out:
db_unlock(mdb);