/* Check that the tables correspond to the version we want */
int check_tables_version(JCR *jcr, B_DB *mdb)
{
- char *query = "SELECT VersionId FROM Version";
+ const char *query = "SELECT VersionId FROM Version";
bacula_db_version = 0;
db_sql_query(mdb, query, int_handler, (void *)&bacula_db_version);
/* Utility routine for queries. The database MUST be locked before calling here. */
int
-QueryDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
+QueryDB(const char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
{
int status;
if ((status=sql_query(mdb, cmd)) != 0) {
* 1 on success
*/
int
-InsertDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
+InsertDB(const char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
{
if (sql_query(mdb, cmd)) {
m_msg(file, line, &mdb->errmsg, _("insert %s failed:\n%s\n"), cmd, sql_strerror(mdb));
* 1 on success
*/
int
-UpdateDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
+UpdateDB(const char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
{
if (sql_query(mdb, cmd)) {
return 0;
}
mdb->num_rows = sql_affected_rows(mdb);
- if (mdb->num_rows != 1) {
+ if (mdb->num_rows < 1) {
char ed1[30];
m_msg(file, line, &mdb->errmsg, _("Update problem: affected_rows=%s\n"),
edit_uint64(mdb->num_rows, ed1));
if (verbose) {
- j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
+// j_msg(file, line, jcr, M_INFO, 0, "%s\n", cmd);
}
return 0;
}
* n number of rows affected
*/
int
-DeleteDB(char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
+DeleteDB(const char *file, int line, JCR *jcr, B_DB *mdb, char *cmd)
{
if (sql_query(mdb, cmd)) {
* thread without blocking, but must be unlocked the number of
* times it was locked.
*/
-void _db_lock(char *file, int line, B_DB *mdb)
+void _db_lock(const char *file, int line, B_DB *mdb)
{
int errstat;
if ((errstat=rwl_writelock(&mdb->lock)) != 0) {
* same thread up to the number of times that thread called
* db_lock()/
*/
-void _db_unlock(char *file, int line, B_DB *mdb)
+void _db_unlock(const char *file, int line, B_DB *mdb)
{
int errstat;
if ((errstat=rwl_writeunlock(&mdb->lock)) != 0) {
db_unlock(mdb);
#endif
+/*
+ * This is turned off because transactions break
+ * if multiple simultaneous jobs are run.
+ */
+#ifdef xAVE_POSTGRESQL
+ db_lock(mdb);
+ /* Allow only 25,000 changes per transaction */
+ if (mdb->transaction && mdb->changes > 25000) {
+ db_end_transaction(jcr, mdb);
+ }
+ if (!mdb->transaction) {
+ db_sql_query(mdb, "BEGIN", NULL, NULL); /* begin transaction */
+ Dmsg0(400, "Start PosgreSQL transaction\n");
+ mdb->transaction = 1;
+ }
+ db_unlock(mdb);
+#endif
}
void db_end_transaction(JCR *jcr, B_DB *mdb)
mdb->changes = 0;
db_unlock(mdb);
#endif
+
+#ifdef xAVE_POSTGRESQL
+ db_lock(mdb);
+ if (mdb->transaction) {
+ db_sql_query(mdb, "COMMIT", NULL, NULL); /* end transaction */
+ mdb->transaction = 0;
+ Dmsg1(400, "End PostgreSQL transaction changes=%d\n", mdb->changes);
+ }
+ mdb->changes = 0;
+ db_unlock(mdb);
+#endif
}
/*
field = sql_fetch_field(mdb);
if (row[i] == NULL) {
bsnprintf(buf, sizeof(buf), " %-*s |", (int)field->max_length, "NULL");
- } else if (IS_NUM(field->type) && !jcr->gui) {
+ } else if (IS_NUM(field->type) && !jcr->gui && is_an_integer(row[i])) {
bsnprintf(buf, sizeof(buf), " %*s |", (int)field->max_length,
add_commas(row[i], ewc));
} else {
field = sql_fetch_field(mdb);
if (row[i] == NULL) {
bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name, "NULL");
- } else if (IS_NUM(field->type) && !jcr->gui) {
+ } else if (IS_NUM(field->type) && !jcr->gui && is_an_integer(row[i])) {
bsnprintf(buf, sizeof(buf), " %*s: %s\n", max_len, field->name,
add_commas(row[i], ewc));
} else {