mirror of https://github.com/Gnucash/gnucash
The attached patch contains some immediate bug fixes for the SQL back end, and it adds and error message string + accessor/mutator to Backend. Also, in xaccAccountCommitEdit(), added the use of PWARN_GUI to display the error message. The bug fixes in the SQL backend involved converting the *_QUERY macros to functions. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7485 57a11ea4-9604-0410-9ed3-97b8803252fdzzzoldfeatures/g2-gog-integ
parent
d4f97ce2d9
commit
c2bfd78517
@ -0,0 +1,106 @@
|
||||
/********************************************************************\
|
||||
* putil.c -- utility macros for the postgres backend *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* 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*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* FILE:
|
||||
* putil.c
|
||||
*
|
||||
* FUNCTION:
|
||||
* Postgres backend utility macros
|
||||
*
|
||||
* HISTORY:
|
||||
* Copyright (c) 2002 Matthew Vanecek <mevanecek@yahoo.com>
|
||||
*
|
||||
*/
|
||||
|
||||
static short module = MOD_BACKEND;
|
||||
|
||||
#include "putil.h"
|
||||
|
||||
/* ============================================================= */
|
||||
/* The sendQuery function sends the sql statement off to the server.
|
||||
* It performs a minimal check to see that the send succeeded. The
|
||||
* return value indicates success or failure of the send.
|
||||
*/
|
||||
int sendQuery(PGBackend *be,char * buff) {
|
||||
int rc = 0;
|
||||
|
||||
ENTER(" ");
|
||||
if (NULL == be->connection) return ERR_BACKEND_CONN_LOST;
|
||||
PINFO("Connectionn is %p", be->connection);
|
||||
PINFO ("sending query %s", buff);
|
||||
rc = PQsendQuery (be->connection, buff);
|
||||
if (!rc) {
|
||||
gchar * msg = (gchar *)PQerrorMessage(be->connection);
|
||||
PERR("send query failed:\n"
|
||||
"\t%s", msg);
|
||||
xaccBackendSetMessage(&be->be, msg);
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);
|
||||
return ERR_BACKEND_SERVER_ERR;
|
||||
}
|
||||
LEAVE("PQsendQuery rc = %d", rc);
|
||||
return ERR_BACKEND_NO_ERR;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
/* The finishQuery function makes sure that the previously sent
|
||||
* query completed with no errors. It assumes that the query
|
||||
* does not produce any results; if it did those results are
|
||||
* discarded (only error conditions are checked for). The number of
|
||||
* rows affected by the query is returned.
|
||||
*/
|
||||
|
||||
int finishQuery(PGBackend *be) {
|
||||
int i=0;
|
||||
PGresult *result;
|
||||
|
||||
ENTER(" ");
|
||||
/* complete/commit the transaction, check the status */
|
||||
PINFO("Connection is %p", be->connection);
|
||||
do {
|
||||
int x;
|
||||
ExecStatusType status;
|
||||
result = PQgetResult(be->connection);
|
||||
if (!result) {
|
||||
PINFO("Result is (null)");
|
||||
break;
|
||||
}
|
||||
|
||||
status = PQresultStatus(result);
|
||||
x = atoi(PQcmdTuples(result));
|
||||
PINFO("Result status: %s, rows affected: %d, by %s",
|
||||
PQresStatus(status), x, PQcmdStatus(result));
|
||||
i += x;
|
||||
|
||||
if (PGRES_COMMAND_OK != status) {
|
||||
gchar * msg = (gchar *)PQerrorMessage(be->connection);
|
||||
PERR("finish query failed:\n\t%s", msg);
|
||||
PQclear(result);
|
||||
xaccBackendSetMessage(&be->be, msg);
|
||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);
|
||||
break;
|
||||
}
|
||||
PQclear(result);
|
||||
} while (result);
|
||||
|
||||
LEAVE("%d rows affected by SQL statement", i);
|
||||
return i;
|
||||
}
|
||||
Loading…
Reference in new issue