# Find JobId, FileIndex for a given path/file and date
# for use when inserting individual files into the tree.

SELECT Job.JobId,
       File.FileIndex
FROM Job,
     File,
     Path,
     Client
WHERE Job.JobId=File.JobId
  AND Job.StartTime<='%s'
  AND Path.Path='%s'
  AND File.Name='%s'
  AND Client.Name='%s'
  AND Job.ClientId=Client.ClientId
  AND Path.PathId=File.PathId
  AND JobStatus IN ('T',
                    'W')
  AND TYPE='%c'
ORDER BY Job.StartTime DESC
LIMIT 1
