From: Eric Bollengier Date: Wed, 24 May 2017 20:26:52 +0000 (+0200) Subject: Fix bvfs queries X-Git-Tag: Release-7.9.0~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=522c562002a64bfd43d2fde42add2e2873509f14;p=bacula%2Fbacula Fix bvfs queries --- diff --git a/bacula/src/cats/bvfs.c b/bacula/src/cats/bvfs.c index 6b97bb21f9..b395c58ecb 100644 --- a/bacula/src/cats/bvfs.c +++ b/bacula/src/cats/bvfs.c @@ -892,12 +892,12 @@ void Bvfs::get_all_file_versions(DBId_t pathid, FileId_t fnid, const char *clien POOL_MEM query; - Mmsg(query,// 1 2 3 -"SELECT 'V', File.PathId, File.FilenameId, File.JobId, " -// 4 5 6 + Mmsg(query,// 1 2 3 4 +"SELECT 'V', File.PathId, File.FilenameId, 0, File.JobId, " +// 5 6 7 "File.LStat, File.FileId, File.Md5, " -// 7 8 - "Media.VolumeName, Media.InChanger " +// 8 9 + "Media.VolumeName, Media.InChanger " "FROM File, Job, Client, JobMedia, Media " "WHERE File.FilenameId = %s " "AND File.PathId=%s " @@ -1102,8 +1102,8 @@ void Bvfs::ls_special_dirs() edit_uint64(pwd_id, ed1), jobids, ed1); POOL_MEM query2; - Mmsg(query2,// 1 2 3 4 5 -"SELECT 'D', tmp.PathId, tmp.Path, JobId, LStat, FileId, FileIndex " + Mmsg(query2,// 1 2 3 4 5 6 +"SELECT 'D', tmp.PathId, 0, tmp.Path, JobId, LStat, FileId, FileIndex " "FROM %s AS tmp LEFT JOIN ( " // get attributes if any "SELECT File1.PathId AS PathId, File1.JobId AS JobId, " "File1.LStat AS LStat, File1.FileId AS FileId, " @@ -1152,7 +1152,7 @@ bool Bvfs::ls_dirs() /* Then we get all the dir entries from File ... */ Mmsg(query, // 0 1 2 3 4 5 6 -"SELECT 'D', PathId, Path, JobId, LStat, FileId, FileIndex FROM ( " +"SELECT 'D', PathId, 0, Path, JobId, LStat, FileId, FileIndex FROM ( " "SELECT Path1.PathId AS PathId, Path1.Path AS Path, " "lower(Path1.Path) AS lpath, " "listfile1.JobId AS JobId, listfile1.LStat AS LStat, " @@ -1363,10 +1363,10 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink, if (*fileid) { /* Select files with their direct id */ init=true; - Mmsg(tmp,"SELECT Job.JobId, JobTDate, FileIndex, Filename.Name, " + Mmsg(tmp,"SELECT Job.JobId, JobTDate, FileIndex, FilenameId, " "PathId, FileId " - "FROM File,Job,Filename WHERE Job.JobId=File.Jobid " - "AND File.FilenameId=Filename.FilenameId AND FileId IN (%s)", + "FROM File,Job WHERE Job.JobId=File.Jobid " + "AND FileId IN (%s)", fileid); pm_strcat(query, tmp.c_str()); } diff --git a/bacula/src/cats/bvfs.h b/bacula/src/cats/bvfs.h index 4ee66528e7..a9bcf5f2fa 100644 --- a/bacula/src/cats/bvfs.h +++ b/bacula/src/cats/bvfs.h @@ -44,21 +44,21 @@ typedef enum { typedef enum { BVFS_Type = 0, /* Could be D, F, V, L */ BVFS_PathId = 1, - BVFS_FilenameId = 5, + BVFS_FilenameId = 2, - BVFS_Name = 2, - BVFS_JobId = 3, + BVFS_Name = 3, /* Can be empty for File version */ + BVFS_JobId = 4, - BVFS_LStat = 4, /* Can be empty for missing directories */ - BVFS_FileId = 5, /* Can be empty for missing directories */ + BVFS_LStat = 5, /* Can be empty for missing directories */ + BVFS_FileId = 6, /* Can be empty for missing directories */ /* Only if Path record */ - BVFS_FileIndex = 6, + BVFS_FileIndex = 7, /* Only if File Version record */ - BVFS_Md5 = 6, - BVFS_VolName = 7, - BVFS_VolInchanger = 8, + BVFS_Md5 = 7, + BVFS_VolName = 8, + BVFS_VolInchanger = 9, /* Only if Delta record */ BVFS_DeltaSeq = 6, diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index c6bfc525d3..76b5bec85a 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -736,7 +736,7 @@ const char *sql_bvfs_select[] = }; static const char *sql_bvfs_list_files_default = -"SELECT 'F', T1.PathId, Filename.Name, " +"SELECT 'F', T1.PathId, T1.FilenameId, Filename.Name, " "File.JobId, File.LStat, File.FileId " "FROM Job, File, ( " "SELECT MAX(JobTDate) AS JobTDate, PathId, FilenameId " @@ -770,7 +770,7 @@ const char *sql_bvfs_list_files[] = { /* JobId PathId JobId PathId WHERE? Filename? Limit Offset*/ /* Postgresql */ - "SELECT Type, PathId, Name, JobId, LStat, FileId " + "SELECT Type, PathId, FilenameId, Name, JobId, LStat, FileId " "FROM (" "SELECT DISTINCT ON (FilenameId) 'F' as Type, PathId, T.FilenameId, " "Filename.Name, JobId, LStat, FileId, FileIndex "