From: Dan Langille Date: Fri, 12 Dec 2003 16:12:25 +0000 (+0000) Subject: Add numornull which retuns NULL if the value is zero, or the value. X-Git-Tag: Release-7.0.0~9853 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3e9c0df4f09e746f575a675923ff9f0f60cfd861;p=bacula%2Fbacula Add numornull which retuns NULL if the value is zero, or the value. This function was needed because Job.{PoolId|FileSetId|ClientId} are foreign keys. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@877 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index 1030bcb49f..843de7f413 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -113,6 +113,14 @@ db_update_job_start_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) return stat; } +/* + * Given an incoming integer, set the string buffer to either NULL or the value + * + * + */ +void numornull(char *s, size_t n, int id) { + bsnprintf(s, n, id ? "%d" : "NULL", id); +} /* @@ -130,6 +138,15 @@ db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) int stat; char ed1[30], ed2[30]; btime_t JobTDate; + char PoolId [50]; + char FileSetId [50]; + char ClientId [50]; + + + /* some values are set to zero, which translates to NULL in SQL */ + numornull(PoolId, sizeof(PoolId), jr->PoolId); + numornull(FileSetId, sizeof(FileSetId), jr->FileSetId); + numornull(ClientId, sizeof(ClientId), jr->ClientId); ttime = jr->EndTime; localtime_r(&ttime, &tm); @@ -139,11 +156,11 @@ db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) db_lock(mdb); Mmsg(&mdb->cmd, "UPDATE Job SET JobStatus='%c', EndTime='%s', \ -ClientId=%u, JobBytes=%s, JobFiles=%u, JobErrors=%u, VolSessionId=%u, \ -VolSessionTime=%u, PoolId=%u, FileSetId=%u, JobTDate=%s WHERE JobId=%u", - (char)(jr->JobStatus), dt, jr->ClientId, edit_uint64(jr->JobBytes, ed1), +ClientId=%s, JobBytes=%s, JobFiles=%u, JobErrors=%u, VolSessionId=%u, \ +VolSessionTime=%u, PoolId=%s, FileSetId=%s, JobTDate=%s WHERE JobId=%u", + (char)(jr->JobStatus), dt, ClientId, edit_uint64(jr->JobBytes, ed1), jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime, - jr->PoolId, jr->FileSetId, edit_uint64(JobTDate, ed2), jr->JobId); + PoolId, FileSetId, edit_uint64(JobTDate, ed2), jr->JobId); stat = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb);