Re: How to use SQLGLM in Pro*C?

From: Tim Smith <tssmith_at_netcom.com>
Date: Sun, 18 Dec 1994 16:19:37 GMT
Message-ID: <tssmithD10LCp.D7C_at_netcom.com>


scip3109_at_leonis.nus.sg (Lim Choon Long) writes:
>Below is a small program that will fail upon connection. It displayed
>sqlca.sqlerrm.sqlerrmc but core dump at sqlglm() instead of displaying
>the message from sqlglm(). I am using Pro*C release 1.5.6.2.1 on
>SunOS 4.1.3.
 [...]
> char errmsg[100];
> int errlength;
>
> EXEC SQL WHENEVER SQLERROR CONTINUE;
>
> printf("\nORACLE error detected:\n");
> printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc);
>
> sqlglm(errmsg, 100, &errlength);
> printf("Oracle ERROR : %s\n", errmsg);
[...]

Your problem (as you've probably discovered by now), is that all args to sqlglm() must be pointers. So you should do:

char errmsg[100];
int msglen, errlen;

msglen = sizeof (errmsg);
sqlglm(errmsg, &msglen, &errlen);
printf("%.*s\n", errlen, errmsg);

Perhaps this was not documented correctly in the 1.5 Pro*C Supplement to the Oracle Precompilers Guide. It is correct in the V1.6 and later manuals.

A seg fault when calling a function is caused, most of the time, by an argument that should be a pointer and isn't.

--Tim (tssmith_at_oracle.com) Received on Sun Dec 18 1994 - 17:19:37 CET

Original text of this message