Re: Solaris ecpg program doesn't work - pulling my hair

From: <wespvp(at)syntegra(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Solaris ecpg program doesn't work - pulling my hair
Date: 2004-03-24 01:22:32
Message-ID: BC863EF8.BBC3%wespvp@syntegra.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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. Due to a test environment error, it
previously looked like they weren't. However, the error code is *never*
set. I display the entire sqlca data stucture 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);
}

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joan Picanyol 2004-03-24 01:27:34 Re: rule as on insert to view with multiple fk referencing the same table
Previous Message Tom Lane 2004-03-24 00:05:37 Re: linked list rewrite