* Bacula Catalog Database Update record interface routines
*
* Kern Sibbald, March 2000
+ *
+ * Version $Id$
*/
/*
*/
-/* *****FIXME**** fix fixed length of select_cmd[] and insert_cmd[] */
-
/* The following is necessary so that we do not include
* the dummy external definition of DB.
*/
extern void print_result(B_DB *mdb);
extern int UpdateDB(char *file, int line, B_DB *db, char *update_cmd);
-static int do_update(B_DB *mdb, char *cmd)
-{
- int stat;
-
- stat = UPDATE_DB(mdb, cmd);
- return stat;
-}
-
/* -----------------------------------------------------------------------
*
* Generic Routines (or almost generic)
{
int stat;
- P(mdb->mutex);
+ db_lock(mdb);
Mmsg(&mdb->cmd, "UPDATE File SET MD5=\"%s\" WHERE FileId=%d", MD5, FileId);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
{
int stat;
- P(mdb->mutex);
+ db_lock(mdb);
Mmsg(&mdb->cmd, "UPDATE File SET FileIndex=%d WHERE FileId=%d", JobId, FileId);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
char dt[MAX_TIME_LENGTH];
time_t stime;
struct tm tm;
- int32_t StartDay;
+ btime_t JobTDate;
int stat;
+ char ed1[30];
stime = jr->StartTime;
localtime_r(&stime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
- StartDay = (int32_t)(date_encode(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday) -
- date_encode(2000, 1, 1));
+ JobTDate = (btime_t)stime;
- P(mdb->mutex);
+ db_lock(mdb);
Mmsg(&mdb->cmd, "UPDATE Job SET Level='%c', StartTime=\"%s\", \
-ClientId=%d, StartDay=%d WHERE JobId=%d",
- (char)(jr->Level), dt, jr->ClientId, StartDay, jr->JobId);
+ClientId=%d, JobTDate=%s WHERE JobId=%d",
+ (char)(jr->Level), dt, jr->ClientId, edit_uint64(JobTDate, ed1), jr->JobId);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
time_t ttime;
struct tm tm;
int stat;
+ char ed1[30], ed2[30];
+ btime_t JobTDate;
ttime = jr->EndTime;
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
+ JobTDate = ttime;
- P(mdb->mutex);
+ db_lock(mdb);
Mmsg(&mdb->cmd,
"UPDATE Job SET JobStatus='%c', EndTime='%s', \
-ClientId=%d, JobBytes=%" lld ", JobFiles=%d, JobErrors=%d, VolSessionId=%d, \
-VolSessionTime=%d, PoolId=%d, FileSetId=%d WHERE JobId=%d",
- (char)(jr->JobStatus), dt, jr->ClientId, jr->JobBytes, jr->JobFiles,
- jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
- jr->PoolId, jr->FileSetId, jr->JobId);
+ClientId=%d, JobBytes=%s, JobFiles=%d, JobErrors=%d, VolSessionId=%d, \
+VolSessionTime=%d, PoolId=%d, FileSetId=%d, JobTDate=%s WHERE JobId=%d",
+ (char)(jr->JobStatus), dt, jr->ClientId, edit_uint64(jr->JobBytes, ed1),
+ jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
+ jr->PoolId, jr->FileSetId, edit_uint64(JobTDate, ed2), jr->JobId);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
{
int stat;
- P(mdb->mutex);
+ db_lock(mdb);
Mmsg(&mdb->cmd,
"UPDATE Pool SET NumVols=%d, MaxVols=%d, UseOnce=%d, UseCatalog=%d, \
AcceptAnyVolume=%d, LabelFormat=\"%s\" WHERE PoolId=%d",
pr->AcceptAnyVolume, pr->LabelFormat, pr->PoolId);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}
time_t ttime;
struct tm tm;
int stat;
+ char ed1[30], ed2[30];
ttime = mr->LastWritten;
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
- P(mdb->mutex);
+ Dmsg1(100, "update_media: FirstWritten=%d\n", mr->FirstWritten);
+ db_lock(mdb);
if (mr->VolMounts == 1) {
- Mmsg(&mdb->cmd, "UPDATE Media SET FirstWritten=\"%s\" WHERE \
- VolumeName=\"%s\"", dt, mr->VolumeName);
- if (do_update(mdb, mdb->cmd) == 0) {
- V(mdb->mutex);
- return 0;
- }
+ Mmsg(&mdb->cmd, "UPDATE Media SET FirstWritten=\"%s\"\
+ WHERE VolumeName=\"%s\"", dt, mr->VolumeName);
+ UPDATE_DB(mdb, mdb->cmd);
}
Mmsg(&mdb->cmd, "UPDATE Media SET VolJobs=%d,\
- VolFiles=%d, VolBlocks=%d, VolBytes=%" lld ", VolMounts=%d, VolErrors=%d,\
- VolWrites=%d, VolMaxBytes=%" lld ", LastWritten=\"%s\", VolStatus=\"%s\" \
+ VolFiles=%d, VolBlocks=%d, VolBytes=%s, VolMounts=%d, VolErrors=%d,\
+ VolWrites=%d, VolMaxBytes=%s, LastWritten=\"%s\", VolStatus=\"%s\" \
WHERE VolumeName=\"%s\"",
- mr->VolJobs, mr->VolFiles, mr->VolBlocks, mr->VolBytes, mr->VolMounts,
- mr->VolErrors, mr->VolWrites, mr->VolMaxBytes, dt, mr->VolStatus,
- mr->VolumeName);
+ mr->VolJobs, mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1),
+ mr->VolMounts, mr->VolErrors, mr->VolWrites,
+ edit_uint64(mr->VolMaxBytes, ed2), dt,
+ mr->VolStatus, mr->VolumeName);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}