Skip to content

Commit

Permalink
cats: refactored INSERTDB to return number of affected rows
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Jan 28, 2022
1 parent a26c16f commit cdcf02a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions core/src/cats/cats.h
Expand Up @@ -588,10 +588,10 @@ class BareosDb : public BareosDbQueryEnum {
int line,
JobControlRecord* jcr,
const char* select_cmd);
bool InsertDB(const char* file,
int line,
JobControlRecord* jcr,
const char* select_cmd);
int InsertDB(const char* file,
int line,
JobControlRecord* jcr,
const char* select_cmd);
int DeleteDB(const char* file,
int line,
JobControlRecord* jcr,
Expand Down
14 changes: 7 additions & 7 deletions core/src/cats/sql.cc
Expand Up @@ -236,10 +236,10 @@ bool BareosDb::QueryDB(const char* file,
* Returns: false on failure
* true on success
*/
bool BareosDb::InsertDB(const char* file,
int line,
JobControlRecord* jcr,
const char* select_cmd)
int BareosDb::InsertDB(const char* file,
int line,
JobControlRecord* jcr,
const char* select_cmd)
{
int num_rows;

Expand All @@ -248,18 +248,18 @@ bool BareosDb::InsertDB(const char* file,
sql_strerror());
j_msg(file, line, jcr, M_FATAL, 0, "%s", errmsg);
if (verbose) { j_msg(file, line, jcr, M_INFO, 0, "%s\n", select_cmd); }
return false;
return -1;
}
num_rows = SqlAffectedRows();
if (num_rows != 1) {
char ed1[30];
msg_(file, line, errmsg, _("Insertion problem: affected_rows=%s\n"),
edit_uint64(num_rows, ed1));
if (verbose) { j_msg(file, line, jcr, M_INFO, 0, "%s\n", select_cmd); }
return false;
return num_rows;
}
changes++;
return true;
return num_rows;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions core/src/cats/sql_create.cc
Expand Up @@ -132,7 +132,7 @@ bool BareosDb::CreateJobmediaRecord(JobControlRecord* jcr, JobMediaDbRecord* jm)
/* clang-format on */

Dmsg0(300, cmd);
if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create JobMedia record %s failed: ERR=%s\n"), cmd,
sql_strerror());
} else {
Expand Down Expand Up @@ -668,7 +668,7 @@ bool BareosDb::CreateCounterRecord(JobControlRecord* jcr, CounterDbRecord* cr)
FillQuery(SQL_QUERY::insert_counter_values, esc, cr->MinValue, cr->MaxValue,
cr->CurrentValue, cr->WrapCounter);

if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create DB Counters record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Jmsg(jcr, M_ERROR, 0, "%s", errmsg);
Expand Down Expand Up @@ -1045,7 +1045,7 @@ bool BareosDb::CreateBaseFileAttributesRecord(JobControlRecord* jcr,
Mmsg(cmd, "INSERT INTO basefile%lld (Path, Name) VALUES ('%s','%s')",
(uint64_t)jcr->JobId, esc_path, esc_name);

retval = INSERT_DB(jcr, cmd);
retval = INSERT_DB(jcr, cmd) == 1;
DbUnlock(this);

return retval;
Expand Down Expand Up @@ -1210,7 +1210,7 @@ bool BareosDb::CreateQuotaRecord(JobControlRecord* jcr, ClientDbRecord* cr)
" VALUES ('%s', '%s', %s)",
edit_uint64(cr->ClientId, ed1), "0", "0");

if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create DB Quota record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Jmsg(jcr, M_ERROR, 0, "%s", errmsg);
Expand Down Expand Up @@ -1262,7 +1262,7 @@ bool BareosDb::CreateNdmpLevelMapping(JobControlRecord* jcr,
" VALUES ('%s', '%s', '%s', %s)",
edit_uint64(jr->ClientId, ed1), edit_uint64(jr->FileSetId, ed2),
esc_name, "0");
if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create DB NDMP Level Map record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Jmsg(jcr, M_ERROR, 0, "%s", errmsg);
Expand Down Expand Up @@ -1301,7 +1301,7 @@ bool BareosDb::CreateNdmpEnvironmentString(JobControlRecord* jcr,
" VALUES ('%s', '%s', '%s', '%s')",
edit_int64(jr->JobId, ed1), edit_uint64(jr->FileIndex, ed2), esc_envname,
esc_envvalue);
if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg,
_("Create DB NDMP Job Environment record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Expand Down Expand Up @@ -1341,7 +1341,7 @@ bool BareosDb::CreateJobStatistics(JobControlRecord* jcr,
edit_uint64(jsr->JobBytes, ed3), edit_int64(jsr->DeviceId, ed4));
Dmsg1(200, "Create job stats: %s\n", cmd);

if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create DB JobStats record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Jmsg(jcr, M_ERROR, 0, "%s", errmsg);
Expand Down Expand Up @@ -1399,7 +1399,7 @@ bool BareosDb::CreateDeviceStatistics(JobControlRecord* jcr,

Dmsg1(200, "Create device stats: %s\n", cmd);

if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create DB DeviceStats record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Jmsg(jcr, M_ERROR, 0, "%s", errmsg);
Expand Down Expand Up @@ -1444,7 +1444,7 @@ bool BareosDb::CreateTapealertStatistics(JobControlRecord* jcr,

Dmsg1(200, "Create tapealert: %s\n", cmd);

if (!INSERT_DB(jcr, cmd)) {
if (INSERT_DB(jcr, cmd) != 1) {
Mmsg2(errmsg, _("Create DB TapeAlerts record %s failed. ERR=%s\n"), cmd,
sql_strerror());
Jmsg(jcr, M_ERROR, 0, "%s", errmsg);
Expand Down

0 comments on commit cdcf02a

Please sign in to comment.