Solaris - no error handling in ecpg programs

From: Wes Palmer <Wesley(dot)R(dot)Palmer(at)syntegra(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: Solaris - no error handling in ecpg programs
Date: 2004-03-24 15:58:27
Message-ID: BC870C43.BC01%Wesley.R.Palmer@syntegra.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I have an ecpg program that runs perfectly on Linux (PostgreSQL 7.4.1). I
recompile it on Solaris and when I try to run there is absolutely no error
handling available. When I connect:

EXEC SQL WHENEVER SQLERROR GOTO sql_error;
EXEC SQL CONNECT TO :dbTarget USER :user USING :pw;

Where dbTarget = mydb(at)host(dot)my(dot)domain
user = xxxuser
pw = xxxpassword

The GOTO is not taken and sqlca.sqlcode is set to 0 (no error).

Similarly, when I try to fetch records, either using SELECT or with a
DECLARE CURSOR/FETCH, I get no records and sqlcl.sqlcode is zero (no error).
Since I get no record, but no error is detected, the variables are garbage
and the program SEGV's trying to manipulate the variables.

Psql works, and handles errors properly.

I've been able to determine that I am actually connecting to the database
under Solaris if I specify the correct credentials. And, database
operations such as searches do work. However, the error code is *never*
set. I display the entire sqlca data structure after a successful and
unsuccessful operation and can see no differences:

sqlca = {
sqlcaid = "SQLCA "
sqlabc = 140
sqlcode = 0
sqlerrm = {
sqlerrml = 0
sqlerrmc = ""
}
sqlerrp = "NOT SET "
sqlerrd = (0, 0, 0, 0, 0, 0)
sqlwarn = ""
sqlstate = "00000"
}

The following simple inelegant test case works properly on Linux but not
Solaris. If valid credentials are specified, both will connect to the
database and return the record, but Solaris will not set the error code if
there is a problem. sqlca.sqlcode is always 0. I've compared the C code
generated on Linux to that on Solaris, and they are the same. I know there
is a problem with NOT FOUND at 7.4.1, but that is not the issue here (I have
a patch for that).

main()
{
char *system = "host.dom.ain";
char *target = "mydb(at)host(dot)dom(dot)ain";
char *username = "testuser";
char *password = "test";

EXEC SQL BEGIN DECLARE SECTION;
VARCHAR user[60];
VARCHAR pw[60];
VARCHAR dbTarget[255];
VARCHAR systemName[255];
int systemNum;
EXEC SQL END DECLARE SECTION;

EXEC SQL WHENEVER SQLERROR GOTO connect_error;
EXEC SQL WHENEVER NOT FOUND CONTINUE;

strcpy (user.arr, username);
user.len = strlen(user.arr);

strcpy (pw.arr, password);
user.len = strlen(pw.arr);

strcpy (dbTarget.arr, target);
user.len = strlen(dbTarget.arr);

EXEC SQL CONNECT TO :dbTarget USER :user USING :pw;

printf ("Connect error code: %d\n", sqlca.sqlcode);

EXEC SQL WHENEVER SQLERROR GOTO select_error;
EXEC SQL WHENEVER NOT FOUND GOTO select_error;

strcpy (systemName.arr, system);
systemName.len = strlen(systemName.arr);
EXEC SQL SELECT system_key
INTO :systemNum
FROM systems
WHERE system_name=:systemName;

printf ("SELECT error code: %d\n", sqlca.sqlcode);
printf ("systemNum = %d\n", systemNum);
exit(0);

connect_error:
printf ("Connect failure: %d\n", sqlca.sqlcode);
exit (1);

select_error:
printf ("Select failure: %d\n", sqlca.sqlcode);
exit (1);
}

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-03-24 16:14:20 Re: BUG #1114: REVOKE done by non-privileged user claims success
Previous Message Tom Lane 2004-03-24 15:55:44 Re: BUG #1113: Default template databases grant CREATE to PUBLIC