Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use SQLGLM in Pro*C?

2,188 views
Skip to first unread message

Lim Choon Long

unread,
Dec 15, 1994, 10:50:07 PM12/15/94
to
Hi,

I read in the Programmer's Guide to the Oracle Precompilers (ver 1.5)
and came across a section "Getting the Full Text of Error Messages"
(pg 7-11). I failed to get sqlglm(0 to work and will like to seek
help from the net.

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.

Thanks in advance for any help,

Choon Long
(email: cl...@maxtor.com)

----------------------------
#include <stdio.h>

EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[20];
VARCHAR password[20];
EXEC SQL END DECLARE SECTION;
EXEC SQL INCLUDE sqlca;

void sqlerror(); /* handles unrecoverable errors */

main()
{
strcpy(username.arr, "wronguser"); /* copy the username */
username.len = strlen(username.arr);
strcpy(password.arr, "wrongpw"); /* copy the password */
password.len = strlen(password.arr);

EXEC SQL WHENEVER SQLERROR DO sqlerror();

EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("\nConnected to ORACLE as user: %s\n", username.arr);

EXEC SQL COMMIT WORK RELEASE; /* logoff database */
exit(0);
}

void sqlerror()
{
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);

EXEC SQL ROLLBACK RELEASE;
exit(1);
}

----------------------------

Tim Smith

unread,
Dec 18, 1994, 11:19:37 AM12/18/94
to
scip...@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 (tss...@oracle.com)

0 new messages