* 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;
- btime_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 = (btime_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=%s WHERE JobId=%d",
- (char)(jr->Level), dt, jr->ClientId, edit_uint64(StartDay, ed1), 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;
}
struct tm tm;
int stat;
char ed1[30], ed2[30];
- btime_t StartDay;
+ btime_t JobTDate;
ttime = jr->EndTime;
localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
- StartDay = (btime_t)(date_encode(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday) -
- date_encode(2000, 1, 1));
+ JobTDate = ttime;
- P(mdb->mutex);
+ db_lock(mdb);
Mmsg(&mdb->cmd,
"UPDATE Job SET JobStatus='%c', EndTime='%s', \
ClientId=%d, JobBytes=%s, JobFiles=%d, JobErrors=%d, VolSessionId=%d, \
-VolSessionTime=%d, PoolId=%d, FileSetId=%d, StartDay=%s WHERE JobId=%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(StartDay, ed2), jr->JobId);
+ 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;
}
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,\
mr->VolStatus, mr->VolumeName);
stat = UPDATE_DB(mdb, mdb->cmd);
- V(mdb->mutex);
+ db_unlock(mdb);
return stat;
}