Rafal Boni ([EMAIL PROTECTED]) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
failed connect from ecpg destroys evidence of failure

Long Description
PostgreSQL version 7.1.2, built from source, on Linux (RH 6.2)

If a CONNECT form ecpg fails, the debugging output, as well as the error returned is 
garbage, as the parameters passed in are freed right after the call to:

PQsetdbLogin(host, port, options, NULL, realname, user, passwd);
[src/interfaces/ecpg/lib/connect.c, around line 413]

but before the error checking or post-setdbLogin debugging checks
which use them.

Restructuring the code a little bit give both a sane error message and more useful 
debug output.  I've done that in my tree, but attempting to paste it in here is bad 
mojo (it trashes the rest of my message probably due to tab's), but I'll send it via 
email to anyone that's interested.

--rafal


Sample Code
foo_open_db(char *hostname, char *username, char *password,
     char *db_name)
{
EXEC SQL BEGIN DECLARE SECTION;
  char cUserName[256];
  char cPassword[256];
  char cDbName[256];
EXEC SQL END DECLARE SECTION;

  ECPGdebug(1, stdout);

  strncpy(cUserName, username, sizeof(cUserName) - 1);
  cUserName[sizeof(cUserName) - 1] = '\0';

  strncpy(cPassword, password, sizeof(cPassword) - 1);
  cPassword[sizeof(cPassword) - 1] = '\0';

  snprintf(cDbName, sizeof(cDbName) - 1, "tcp:postgresql://%s/%s", hostname, db_name);
  cDbName[sizeof(cDbName) - 1] = '\0';

  printf("attempting to connect to %s, user %s, pass %s\n", cDbName,
                                                            cUserName,

  EXEC SQL CONNECT TO :cDbName
         USER :cUserName IDENTIFIED BY :cPassword;

  if (sqlca.sqlcode != 0){
    fprintf(stderr, "Unable to connect to database:%s\n",
                 sqlca.sqlerrm.sqlerrmc);
    return -1;
  }



No file was uploaded with this report


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to