0

The Postgresql role is the owner of the db 'university' and it's been configured like,

alter user canoe password 'mypassword';

The piece of embedded SQL code in C just makes a connection to DB.

printf("SQLSTATE=[%s]\n", SQLSTATE);
EXEC SQL CONNECT TO 'university' USER 'canoe/mypassword'
printf("SQLSTATE=[%s]\n", SQLSTATE);

The code is compiled and linked. It's run on the localhost on which the postgresql server is running and listening on its default port.

$ ecpg connection.pgc
$ gcc -I/usr/include/postgresql connection.c -o conn -lecpg

The output of the compiled code is:

SQLSTATE=[00000]
SQLSTATE=[08001]

The error code 08001 means "sqlclient_unable_to_establish_sqlconnection". I've changed the configuration of postgresql to log all connection attempts in order to debug the code.

LOG: parameter "log_connections" changed to "on"
LOG: 00000: parameter "log_error_verbosity" changed to "verbose"

However, when the compiled code is run, there is no any error. When I connect it with pgsql, it has log info.

$ pqsql university -W
LOG: connection authorized: user=canoe database=university

The wired thing that I notice is even I enter wrong password after prompt, I can still get authorized. But my piece of C code doesn't work.

I can't resolve the issue or have any idea to debug it further. Any idea to where is the issue?

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
canoe
  • 1,273
  • 13
  • 29
  • I really don't recommend writing new code in ecpg without a really good reason. It's very little used and not very well supported. It works, and is widely deployed for a lot of legacy apps, though. – Craig Ringer Sep 16 '14 at 09:03
  • I agree that ESQL is terrible; especially the interaction with the C preprocessor is a PITA. But everybody should at least be allowed to be exposed to it just once... – joop Sep 16 '14 at 09:35

0 Answers0