Hi to all.
I think there is a very odd behaviour of pgpool when using PQprepare,
PQexecPrepare during a transaction.
When calling in transaction PQexecPrepare errors are not trapped.
Postgres executes the prepared statement terminating with an error but
pgpool does not send the error to the client.
The problem does not occur when the call to PQexecPrepare is done
outside of a transaction block.
I attached sample code test.c that reproduces the bug.
In order to test it, you must create a sample table in a database named
"test" like this:
create table test_table(
a integer not null
);
I'm using pgpool II 2.2.4 in connection pooling mode (no replication or
load balance) with postgres 8.2.12.
The connections are made to pgpool via socket (dir /var/run, port 11271).
Thank you in advance,
Doct. Eng. Denis Gasparin
---
Edistar SRL
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
int main(int argc, char **argv) {
PGconn *conn;
PGresult *res;
Oid *param_types;
char **param_values;
int doTransaction = 0;
conn = PQconnectdb("host=/var/run/ port=11271 user=postgres dbname=test");
if (PQstatus(conn) == CONNECTION_BAD) {
printf("Unable to connect to db\n");
PQfinish(conn);
return 1;
}
if(doTransaction == 1) {
PQexec(conn,"begin;");
}
printf("Preparing the statement...\n");
param_types = calloc(1,sizeof(Oid));
param_types[0] = 0;
param_values = calloc(1,sizeof(char *));
param_values[0] = "123.5";
res = PQprepare(conn,"","INSERT INTO test_table (a) VALUES ($1)",1,param_types);
switch(PQresultStatus(res)) {
case PGRES_COMMAND_OK:
case PGRES_TUPLES_OK:
break;
default:
printf("%s\nError Message:%s\n","Error preparing the statement...",PQresultErrorMessage(res));
PQclear(res);
free(param_types);
PQfinish(conn);
return 1;
break;
}
PQclear(res);
printf("Executing the statement...\n");
res = PQexecPrepared(conn,"",1,param_values,NULL,NULL,0);
switch(PQresultStatus(res)) {
case PGRES_COMMAND_OK:
case PGRES_TUPLES_OK:
break;
default:
printf("%s\nError Message:%s","Error executing the statement...\n",PQresultErrorMessage(res));
PQclear(res);
free(param_types);
PQfinish(conn);
return 1;
break;
}
if(doTransaction == 1) {
PQexec(conn,"commit;");
}
free(param_types);
PQfinish(conn);
return 0;
}
_______________________________________________
Pgpool-general mailing list
[email protected]
http://pgfoundry.org/mailman/listinfo/pgpool-general