Be a little bit more careful about using sqlstate, in case libpq returned
NULL for it.
This commit is contained in:
parent
0bf70870db
commit
e39bc695d6
@ -1,4 +1,4 @@
|
|||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.15 2003/08/04 00:43:32 momjian Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.16 2003/08/08 13:16:20 petere Exp $ */
|
||||||
|
|
||||||
#define POSTGRES_ECPG_INTERNAL
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
@ -164,6 +164,9 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
|
|||||||
|
|
||||||
int sqlcode;
|
int sqlcode;
|
||||||
|
|
||||||
|
if (sqlstate == NULL)
|
||||||
|
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
|
||||||
|
|
||||||
/* these are not warnings */
|
/* these are not warnings */
|
||||||
if (strncmp(sqlstate, "00", 2) == 0)
|
if (strncmp(sqlstate, "00", 2) == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.6 2003/08/04 00:43:32 momjian Exp $ */
|
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.7 2003/08/08 13:16:20 petere Exp $ */
|
||||||
|
|
||||||
#define POSTGRES_ECPG_INTERNAL
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
@ -159,18 +159,29 @@ void
|
|||||||
ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
|
ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
|
||||||
{
|
{
|
||||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
|
char *sqlstate;
|
||||||
|
char *message;
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
sqlstate = PQresultErrorField(result, 'C');
|
||||||
|
if (sqlstate == NULL)
|
||||||
|
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
|
||||||
|
message = PQresultErrorField(result, 'M');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
|
||||||
|
message = PQerrorMessage(conn);
|
||||||
|
}
|
||||||
|
|
||||||
/* copy error message */
|
/* copy error message */
|
||||||
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
|
||||||
"'%s' in line %d.",
|
"'%s' in line %d.", message, line);
|
||||||
result ? PQresultErrorField(result, 'M') : PQerrorMessage(conn),
|
|
||||||
line);
|
|
||||||
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
|
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
|
||||||
|
|
||||||
/* copy SQLSTATE */
|
/* copy SQLSTATE */
|
||||||
strncpy(sqlca->sqlstate,
|
strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
|
||||||
result ? PQresultErrorField(result, 'C') : ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
|
|
||||||
sizeof(sqlca->sqlstate));
|
|
||||||
|
|
||||||
/* assign SQLCODE for backward compatibility */
|
/* assign SQLCODE for backward compatibility */
|
||||||
if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate)) == 0)
|
if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate)) == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user