mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/backend/postgres/PostgresBackend.c (pgendEnable):
Added ENTER/LEAVE statements * src/backend/postgres/escape.c: Adde gnc-engine-util.h, and "module = MOD_BACKEND" - (sqlEscape_destroy): Added ENTER/LEAVE statemtents. * src/backend/postgres/gncquery.c (sql_Query_destroy): Added ENTER/LEAVE statements. * src/backend/postgres/putil.h: Cleaned up the formatting on the SEND/FINISH/EXEC/GET_RESULT macros. Changed them to use PQresultErrorMessage where possible. Made them all set the Backend error message string. Removed the PQfinish() calls, and setting be->connection to NULL. Reasoning: if a malformed query fails, there is no reason to close the connection. If an update/insert fails, again, there is no need to close the connection. The user should be presented an error message and respond appropriately. If a update/insert/delete fails, then generally the transaction is rolled back to the last BEGIN, thereby preventing data corruption. * src/engine/QueryNew.c (gncQueryPrint): Check that q is not NULL prior to processing it. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7905 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
dda9a689f7
commit
5acf50fa9b
26
ChangeLog
26
ChangeLog
@ -1,3 +1,29 @@
|
||||
2003-02-01 Matthew Vanecek <mevanecek@yahoo.com>
|
||||
|
||||
* src/backend/postgres/PostgresBackend.c (pgendEnable):
|
||||
Added ENTER/LEAVE statements
|
||||
|
||||
* src/backend/postgres/escape.c: Adde gnc-engine-util.h,
|
||||
and "module = MOD_BACKEND"
|
||||
- (sqlEscape_destroy): Added ENTER/LEAVE statemtents.
|
||||
|
||||
* src/backend/postgres/gncquery.c (sql_Query_destroy): Added
|
||||
ENTER/LEAVE statements.
|
||||
|
||||
* src/backend/postgres/putil.h: Cleaned up the formatting on the
|
||||
SEND/FINISH/EXEC/GET_RESULT macros. Changed them to use
|
||||
PQresultErrorMessage where possible. Made them all set the Backend
|
||||
error message string. Removed the PQfinish() calls, and setting
|
||||
be->connection to NULL. Reasoning: if a malformed query fails, there is
|
||||
no reason to close the connection. If an update/insert fails,
|
||||
again, there is no need to close the connection. The user should
|
||||
be presented an error message and respond appropriately. If
|
||||
a update/insert/delete fails, then generally the transaction is
|
||||
rolled back to the last BEGIN, thereby preventing data corruption.
|
||||
|
||||
* src/engine/QueryNew.c (gncQueryPrint): Check that q is not NULL
|
||||
prior to processing it.
|
||||
|
||||
2003-02-01 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
* src/gnome/window-register.c: fix the query code to use the correct
|
||||
|
@ -2405,6 +2405,7 @@ pgendDisable (PGBackend *be)
|
||||
void
|
||||
pgendEnable (PGBackend *be)
|
||||
{
|
||||
ENTER(" ");
|
||||
if (0 >= be->nest_count)
|
||||
{
|
||||
PERR ("too many nested disables");
|
||||
@ -2428,6 +2429,8 @@ pgendEnable (PGBackend *be)
|
||||
be->be.percentage = be->snr.percentage;
|
||||
be->be.events_pending = be->snr.events_pending;
|
||||
be->be.process_events = be->snr.process_events;
|
||||
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
|
@ -32,8 +32,11 @@
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-engine-util.h"
|
||||
#include "escape.h"
|
||||
|
||||
static short module = MOD_BACKEND;
|
||||
|
||||
/* ================================================ */
|
||||
|
||||
struct _escape {
|
||||
@ -129,9 +132,11 @@ sqlEscape_new (void)
|
||||
void
|
||||
sqlEscape_destroy (sqlEscape *b)
|
||||
{
|
||||
if (!b) return;
|
||||
ENTER(" ");
|
||||
if (!b) { LEAVE("b is (null)"); return; }
|
||||
g_free (b->escape); b->escape = NULL;
|
||||
g_free (b);
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/* ================ END OF FILE ==================== */
|
||||
|
@ -83,11 +83,15 @@ sqlQuery_new(void)
|
||||
void
|
||||
sql_Query_destroy(sqlQuery * sq)
|
||||
{
|
||||
if (!sq)
|
||||
ENTER(" ");
|
||||
if (!sq) {
|
||||
LEAVE("sq = (null)");
|
||||
return;
|
||||
}
|
||||
g_free(sq->q_base);
|
||||
sqlEscape_destroy(sq->escape);
|
||||
g_free(sq);
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -84,22 +84,22 @@ int finishQuery(PGBackend *be);
|
||||
* It performs a minimal check to see that the send succeeded.
|
||||
*/
|
||||
|
||||
#define SEND_QUERY(be,buff,retval) \
|
||||
{ \
|
||||
int rc; \
|
||||
if (NULL == be->connection) return retval; \
|
||||
PINFO ("sending query %s", buff); \
|
||||
rc = PQsendQuery (be->connection, buff); \
|
||||
if (!rc) \
|
||||
{ \
|
||||
#define SEND_QUERY(be,buff,retval) \
|
||||
{ \
|
||||
int rc; \
|
||||
if (NULL == be->connection) return retval; \
|
||||
PINFO ("sending query %s", buff); \
|
||||
rc = PQsendQuery (be->connection, buff); \
|
||||
if (!rc) \
|
||||
{ \
|
||||
gchar * msg = (gchar *)PQerrorMessage(be->connection); \
|
||||
/* hack alert -- we need kinder, gentler error handling */\
|
||||
PERR("send query failed:\n\t%s", msg); \
|
||||
xaccBackendSetMessage (&be->be, msg); \
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
|
||||
return retval; \
|
||||
} \
|
||||
}
|
||||
PERR("send query failed:\n\t%s", msg); \
|
||||
xaccBackendSetMessage (&be->be, msg); \
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
|
||||
return retval; \
|
||||
} \
|
||||
} \
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
/* The FINISH_QUERY macro makes sure that the previously sent
|
||||
@ -138,50 +138,54 @@ int finishQuery(PGBackend *be);
|
||||
* wire, and makes sure that no errors occured. Results are left
|
||||
* in the result buffer.
|
||||
*/
|
||||
#define GET_RESULTS(conn,result) \
|
||||
{ \
|
||||
ExecStatusType status; \
|
||||
result = PQgetResult (conn); \
|
||||
if (!result) break; \
|
||||
status = PQresultStatus(result); \
|
||||
if ((PGRES_COMMAND_OK != status) && \
|
||||
(PGRES_TUPLES_OK != status)) \
|
||||
{ \
|
||||
PERR("failed to get result to query:\n" \
|
||||
"\t%s", PQerrorMessage((conn))); \
|
||||
PQclear (result); \
|
||||
PQfinish (conn); \
|
||||
be->connection = NULL; \
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
#define GET_RESULTS(conn,result) \
|
||||
{ \
|
||||
gchar *msg = NULL; \
|
||||
ExecStatusType status; \
|
||||
result = PQgetResult (conn); \
|
||||
if (!result) break; \
|
||||
status = PQresultStatus(result); \
|
||||
msg = PQresultErrorMessage(result); \
|
||||
if ((PGRES_COMMAND_OK != status) && \
|
||||
(PGRES_TUPLES_OK != status)) \
|
||||
{ \
|
||||
PERR("failed to get result to query:\n\t%s", msg); \
|
||||
PQclear (result); \
|
||||
xaccBackendSetMessage (&be->be, msg); \
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);\
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
/* The EXEC_QUERY macro executes a query and returns the results
|
||||
* and makes sure that no errors occured. Results are left
|
||||
* in the result buffer.
|
||||
*/
|
||||
#define EXEC_QUERY(conn,buff,result) \
|
||||
{ \
|
||||
ExecStatusType status = 0; \
|
||||
result = PQexec (conn, buff); \
|
||||
if (result) \
|
||||
status = PQresultStatus(result); \
|
||||
if (!result || \
|
||||
((PGRES_COMMAND_OK != status) && \
|
||||
(PGRES_TUPLES_OK != status))) \
|
||||
{ \
|
||||
PERR("failed to get result to query:\n" \
|
||||
"\t%s", PQerrorMessage((conn))); \
|
||||
if (result) \
|
||||
PQclear (result); \
|
||||
result = NULL; \
|
||||
PQfinish (conn); \
|
||||
be->connection = NULL; \
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
|
||||
} \
|
||||
}
|
||||
#define EXEC_QUERY(conn,buff,result) \
|
||||
{ \
|
||||
gchar *msg = NULL; \
|
||||
ExecStatusType status = 0; \
|
||||
result = PQexec (conn, buff); \
|
||||
if (result) { \
|
||||
status = PQresultStatus(result); \
|
||||
msg = PQresultErrorMessage(result); \
|
||||
} else { \
|
||||
msg = PQerrorMessage(conn); \
|
||||
} \
|
||||
if (!result || \
|
||||
((PGRES_COMMAND_OK != status) && \
|
||||
(PGRES_TUPLES_OK != status))) \
|
||||
{ \
|
||||
PERR("failed to get result to query:\n" \
|
||||
"\t%s", msg); \
|
||||
if (result) \
|
||||
PQclear (result); \
|
||||
result = NULL; \
|
||||
xaccBackendSetMessage (&be->be, msg); \
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);\
|
||||
} \
|
||||
} \
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
/* The IF_ONE_ROW macro counts the number of rows returned by
|
||||
|
@ -1322,11 +1322,17 @@ gncQueryPrint (QueryNew * query)
|
||||
QueryNewSort_t s[3];
|
||||
gint maxResults = 0, numSorts = 3;
|
||||
|
||||
ENTER (" ");
|
||||
|
||||
if (!query) {
|
||||
LEAVE("query is (null)");
|
||||
return;
|
||||
}
|
||||
|
||||
output = NULL;
|
||||
str = NULL;
|
||||
maxResults = gncQueryGetMaxResults (query);
|
||||
|
||||
ENTER (" ");
|
||||
output = gncQueryPrintSearchFor (query, output);
|
||||
output = gncQueryPrintTerms (query, output);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user