diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c index 6733de392b..79b7116707 100644 --- a/src/backend/dbi/gnc-backend-dbi.c +++ b/src/backend/dbi/gnc-backend-dbi.c @@ -1685,7 +1685,7 @@ gnc_dbi_safe_sync_all( QofBackend *qbe, QofBook *book ) be->primary_book = book; gnc_sql_sync_all( &be->sql_be, book ); - if ( ERR_BACKEND_NO_ERR != qof_backend_get_error( qbe ) ) + if (qof_backend_check_error (qbe)) { conn_table_operation( (GncSqlConnection*)conn, table_list, rollback ); diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index dc819db87f..61406373c9 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -512,7 +512,8 @@ gnc_sql_sync_all( GncSqlBackend* be, /*@ dependent @*/ QofBook *book ) } else { - qof_backend_set_error( (QofBackend*)be, ERR_BACKEND_SERVER_ERR ); + if (!qof_backend_check_error ((QofBackend*)be)) + qof_backend_set_error( (QofBackend*)be, ERR_BACKEND_SERVER_ERR ); is_ok = gnc_sql_connection_rollback_transaction( be->conn ); } finish_progress( be ); diff --git a/src/backend/xml/io-gncxml-v2.c b/src/backend/xml/io-gncxml-v2.c index c7ab52eaef..051c94c8d1 100644 --- a/src/backend/xml/io-gncxml-v2.c +++ b/src/backend/xml/io-gncxml-v2.c @@ -1033,7 +1033,7 @@ write_book(FILE *out, QofBook *book, sixtp_gdv2 *gd) g_list_length(gnc_book_get_schedxactions(book)->sx_list), "budget", qof_collection_count( qof_book_get_collection(book, GNC_ID_BUDGET)), - "price", gnc_pricedb_get_num_prices(gnc_pricedb_get_db(book)), + "price", gnc_pricedb_get_num_prices(gnc_pricedb_get_db(book)), NULL)) return FALSE; @@ -1131,11 +1131,11 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd) /* Write out the parent pricedb tag then loop to write out each price. We do it this way instead of just calling xmlElemDump so that we can increment the progress bar as we go. */ - - if (fprintf( out, "<%s version=\"%s\">\n", parent->name, + + if (fprintf( out, "<%s version=\"%s\">\n", parent->name, xmlGetProp(parent, BAD_CAST "version")) < 0) return FALSE; - + /* We create our own output buffer so we can call xmlNodeDumpOutput to get the indendation correct. */ outbuf = xmlOutputBufferCreateFile(out, NULL); @@ -1144,7 +1144,7 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd) xmlFreeNode(parent); return FALSE; } - + for (node = parent->children; node; node = node->next) { /* Write two spaces since xmlNodeDumpOutput doesn't indent the first line */ @@ -1152,14 +1152,14 @@ write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd) xmlNodeDumpOutput(outbuf, NULL, node, 1, 1, NULL); /* It also doesn't terminate the last line */ xmlOutputBufferWrite(outbuf, 1, "\n"); - if (ferror(out)) + if (ferror(out)) break; gd->counter.prices_loaded += 1; run_callback(gd, "prices"); } - + xmlOutputBufferClose(outbuf); - + if (ferror(out) || fprintf(out, "\n", parent->name) < 0) { xmlFreeNode(parent); @@ -1670,8 +1670,7 @@ gnc_book_write_accounts_to_xml_file_v2( if (out && fclose(out)) success = FALSE; - if (!success - && qof_backend_get_error(be) == ERR_BACKEND_NO_ERR) + if (!success && !qof_backend_check_error(be)) { /* Use a generic write error code */ @@ -2186,4 +2185,3 @@ gnc_xml2_parse_with_subst (FileBackend *fbe, QofBook *book, GHashTable *subst) return success; } - diff --git a/src/libqof/qof/qofbackend.c b/src/libqof/qof/qofbackend.c index 6a8ab60616..07dfab0dca 100644 --- a/src/libqof/qof/qofbackend.c +++ b/src/libqof/qof/qofbackend.c @@ -64,6 +64,13 @@ qof_backend_get_error (QofBackend *be) return err; } +gboolean +qof_backend_check_error (QofBackend *be) +{ + g_return_val_if_fail (be != NULL, TRUE); + return be->last_err != ERR_BACKEND_NO_ERR; +} + void qof_backend_set_message (QofBackend *be, const char *format, ...) { diff --git a/src/libqof/qof/qofbackend.h b/src/libqof/qof/qofbackend.h index 13aed89c4d..5b4e41179d 100644 --- a/src/libqof/qof/qofbackend.h +++ b/src/libqof/qof/qofbackend.h @@ -166,6 +166,14 @@ void qof_backend_set_error (QofBackend *be, QofBackendError err); */ QofBackendError qof_backend_get_error (QofBackend *be); +/** Report if the backend is in an error state. + * Since get_error resets the error state, its use for branching as the backend + * bubbles back up to the session would make the session think that there was + * no error. + * \param be The backend being tested. + * \return TRUE if the backend has an error set. + */ +gboolean qof_backend_check_error (QofBackend *be); /** \brief Load a QOF-compatible backend shared library.