The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
This program is Free Software; you can redistribute it and/or
- modify it under the terms of version two of the GNU General Public
+ modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*
* Kern Sibbald, March 2000
*
- * Version $Id$
+ * Version $Id: sql_update.c 8478 2009-02-18 20:11:55Z kerns $
*/
-/* The following is necessary so that we do not include
- * the dummy external definition of DB.
- */
-#define __SQL_C /* indicate that this is sql.c */
-
#include "bacula.h"
-#include "cats.h"
-#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI
+#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI
+
+#include "cats.h"
+#include "bdb_priv.h"
+#include "sql_glue.h"
/* -----------------------------------------------------------------------
*
db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest,
int type)
{
- int stat;
+ int ret;
char ed1[50];
+ int len = strlen(digest);
db_lock(mdb);
- Mmsg(mdb->cmd, "UPDATE File SET MD5='%s' WHERE FileId=%s", digest,
- edit_int64(FileId, ed1));
- stat = UPDATE_DB(jcr, mdb, mdb->cmd);
+ mdb->esc_name = check_pool_memory_size(mdb->esc_name, len*2+1);
+ mdb->db_escape_string(jcr, mdb->esc_name, digest, len);
+ Mmsg(mdb->cmd, "UPDATE File SET MD5='%s' WHERE FileId=%s", mdb->esc_name,
+ edit_int64(FileId, ed1));
+ ret = UPDATE_DB(jcr, mdb, mdb->cmd);
db_unlock(mdb);
- return stat;
+ return ret;
}
/* Mark the file record as being visited during database
"UPDATE Job SET JobStatus='%c',EndTime='%s',"
"ClientId=%u,JobBytes=%s,ReadBytes=%s,JobFiles=%u,JobErrors=%u,VolSessionId=%u,"
"VolSessionTime=%u,PoolId=%u,FileSetId=%u,JobTDate=%s,"
-"RealEndTime='%s',PriorJobId=%s WHERE JobId=%s",
+"RealEndTime='%s',PriorJobId=%s,HasBase=%u,PurgedFiles=%u WHERE JobId=%s",
(char)(jr->JobStatus), dt, jr->ClientId, edit_uint64(jr->JobBytes, ed1),
edit_uint64(jr->ReadBytes, ed4),
jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
jr->PoolId, jr->FileSetId, edit_uint64(JobTDate, ed2),
- rdt,
- PriorJobId,
+ rdt, PriorJobId, jr->HasBase, jr->PurgedFiles,
edit_int64(jr->JobId, ed3));
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
{
int stat;
char ed1[50], ed2[50];
+ char esc_name[MAX_ESCAPE_NAME_LENGTH];
+ char esc_uname[MAX_ESCAPE_NAME_LENGTH];
CLIENT_DBR tcr;
db_lock(mdb);
return 0;
}
+ mdb->db_escape_string(jcr, esc_name, cr->Name, strlen(cr->Name));
+ mdb->db_escape_string(jcr, esc_uname, cr->Uname, strlen(cr->Uname));
Mmsg(mdb->cmd,
"UPDATE Client SET AutoPrune=%d,FileRetention=%s,JobRetention=%s,"
"Uname='%s' WHERE Name='%s'",
cr->AutoPrune,
edit_uint64(cr->FileRetention, ed1),
edit_uint64(cr->JobRetention, ed2),
- cr->Uname, cr->Name);
+ esc_uname, esc_name);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
db_unlock(mdb);
*/
int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
{
+ char esc[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
-
+ mdb->db_escape_string(jcr, esc, cr->Counter, strlen(cr->Counter));
Mmsg(mdb->cmd,
-"UPDATE Counters SET MinValue=%d,MaxValue=%d,CurrentValue=%d,"
+"UPDATE Counters SET \"MinValue\"=%d,\"MaxValue\"=%d,CurrentValue=%d,"
"WrapCounter='%s' WHERE Counter='%s'",
cr->MinValue, cr->MaxValue, cr->CurrentValue,
- cr->WrapCounter, cr->Counter);
+ cr->WrapCounter, esc);
int stat = UPDATE_DB(jcr, mdb, mdb->cmd);
db_unlock(mdb);
{
int stat;
char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50];
+ char esc[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
+ mdb->db_escape_string(jcr, esc, pr->LabelFormat, strlen(pr->LabelFormat));
+
Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s",
edit_int64(pr->PoolId, ed4));
pr->NumVols = get_sql_record_max(jcr, mdb);
pr->MaxVolJobs, pr->MaxVolFiles,
edit_uint64(pr->MaxVolBytes, ed3),
pr->Recycle, pr->AutoPrune, pr->LabelType,
- pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
+ esc, edit_int64(pr->RecyclePoolId,ed5),
edit_int64(pr->ScratchPoolId,ed6),
pr->ActionOnPurge,
ed4);
char ed1[50], ed2[50], ed3[50], ed4[50];
char ed5[50], ed6[50], ed7[50], ed8[50];
char ed9[50], ed10[50], ed11[50];
-
+ char esc_name[MAX_ESCAPE_NAME_LENGTH];
+ char esc_status[MAX_ESCAPE_NAME_LENGTH];
Dmsg1(100, "update_media: FirstWritten=%d\n", mr->FirstWritten);
db_lock(mdb);
+ mdb->db_escape_string(jcr, esc_name, mr->VolumeName, strlen(mr->VolumeName));
+ mdb->db_escape_string(jcr, esc_status, mr->VolStatus, strlen(mr->VolStatus));
+
if (mr->set_first_written) {
Dmsg1(400, "Set FirstWritten Vol=%s\n", mr->VolumeName);
ttime = mr->FirstWritten;
(void)localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm);
Mmsg(mdb->cmd, "UPDATE Media SET FirstWritten='%s'"
- " WHERE VolumeName='%s'", dt, mr->VolumeName);
+ " WHERE VolumeName='%s'", dt, esc_name);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
Dmsg1(400, "Firstwritten=%d\n", mr->FirstWritten);
}
(void)localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm);
Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' "
- "WHERE VolumeName='%s'", dt, mr->VolumeName);
+ "WHERE VolumeName='%s'", dt, esc_name);
UPDATE_DB(jcr, mdb, mdb->cmd);
}
(void)localtime_r(&ttime, &tm);
strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm);
Mmsg(mdb->cmd, "UPDATE Media Set LastWritten='%s' "
- "WHERE VolumeName='%s'", dt, mr->VolumeName);
+ "WHERE VolumeName='%s'", dt, esc_name);
UPDATE_DB(jcr, mdb, mdb->cmd);
}
mr->VolJobs, mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1),
mr->VolMounts, mr->VolErrors, mr->VolWrites,
edit_uint64(mr->MaxVolBytes, ed2),
- mr->VolStatus, mr->Slot, mr->InChanger,
+ esc_status, mr->Slot, mr->InChanger,
edit_int64(mr->VolReadTime, ed3),
edit_int64(mr->VolWriteTime, ed4),
mr->VolParts,
edit_uint64(mr->ScratchPoolId, ed10),
edit_uint64(mr->RecyclePoolId, ed11),
mr->RecycleCount,mr->Recycle, mr->ActionOnPurge,
- mr->VolumeName);
+ esc_name);
Dmsg1(400, "%s\n", mdb->cmd);
{
int stat;
char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
-
+ char esc[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
if (mr->VolumeName[0]) {
+ mdb->db_escape_string(jcr, esc, mr->VolumeName, strlen(mr->VolumeName));
Mmsg(mdb->cmd, "UPDATE Media SET "
"ActionOnPurge=%d, Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
"MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,RecyclePoolId=%s"
mr->MaxVolJobs, mr->MaxVolFiles,
edit_uint64(mr->MaxVolBytes, ed3),
edit_uint64(mr->RecyclePoolId, ed4),
- mr->VolumeName);
+ esc);
} else {
Mmsg(mdb->cmd, "UPDATE Media SET "
"ActionOnPurge=%d, Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
{
char ed1[50], ed2[50];
+ char esc[MAX_ESCAPE_NAME_LENGTH];
if (mr->InChanger != 0 && mr->Slot != 0 && mr->StorageId != 0) {
if (mr->MediaId != 0) {
edit_int64(mr->StorageId, ed1), edit_int64(mr->MediaId, ed2));
} else if (*mr->VolumeName) {
+ mdb->db_escape_string(jcr, esc,mr->VolumeName,strlen(mr->VolumeName));
Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0, Slot=0 WHERE "
"Slot=%d AND StorageId=%s AND VolumeName!='%s'",
mr->Slot,
- edit_int64(mr->StorageId, ed1), mr->VolumeName);
+ edit_int64(mr->StorageId, ed1), esc);
} else { /* used by ua_label to reset all volume with this slot */
Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0, Slot=0 WHERE "
}
}
-#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/
+#endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL || HAVE_INGRES || HAVE_DBI */