Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Pro*C/C++ and the goto operator
Thank you very much for your answer.
I am starting to use Oracle8 (including Pro*c/C++),
so sometimes I have got questions.
In article <37F8E53D.AA60F032_at_Unforgettable.com>,
BlueSax_at_Unforgettable.com wrote:
> Why do you want to write something that goes against the standards
that
> Oracle has instituted?
> If you follow Oracle's method of using Pro-C your
> code will be highly portable and maintainable.
>
> There is an alternative to the goto. You could write something to the
> effect of:
>
> EXEC SQL WHENEVER NOT FOUND DO myfunc();
>
> If you do it that way, if a fetch causes a 1403 then myfunc() will be
> called, but that may not give you the desired result.
Why may result be undesirable?
(We don't need goto-operator in C/C++. Do we have to use this operator in Pro*C/C++?)
>
> Hint: look at the precompiler output to see what happens to the EXEC
SQL
> syntax when it is rewritten into executible statements by the
precompiler.
EXEC SQL suntax and corresponding executible statements
are shown below (see Appendix).
But I don't find the answer on my question.
>
> Ken
>
[snip]
Thanks in advance, Alex
Appendix.
for (;;) { [--- omitted ---] /* Branch to the notfound label when the * 1403 ("No data found") condition occurs. */ EXEC SQL WHENEVER NOT FOUND GOTO notfound; [--- omitted ---] continue; notfound: printf("\nNot a valid employee number - try again.\n");
} /* end for(;;) */
for (;;) { [--- omitted ---] /* Branch to the notfound label when the * 1403 ("No data found") condition occurs. */ /* EXEC SQL WHENEVER NOT FOUND GOTO notfound; */ [--- omitted ---] { struct sqlexd sqlstm; [--- omitted ---] if (sqlca.sqlcode == 1403) goto notfound; if (sqlca.sqlcode < 0) sql_error("ORACLE error--\n"); } [--- omitted ---] continue; notfound: printf("\nNot a valid employee number - try again.\n"); } /* end for(;;) */ ============================================= =============== DO operator =================
/* Declare error handling function. */
void sql_error(msg)
char *msg;
{
char err_msg[128];
size_t buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\n%s\n", msg); buf_len = sizeof (err_msg); sqlglm(err_msg, &buf_len, &msg_len); printf("%.*s\n", msg_len, err_msg); EXEC SQL ROLLBACK RELEASE; exit(EXIT_FAILURE);
} /* void sql_error(msg) */
void main()
{
[--- omitted ---]
/* Register sql_error() as the error handler. */ EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n"); [--- omitted ---]
} /* void main() */
/* Declare error handling function. */
void sql_error(msg)
char *msg;
{
char err_msg[128];
size_t buf_len, msg_len;
/* EXEC SQL WHENEVER SQLERROR CONTINUE; */
printf("\n%s\n", msg); buf_len = sizeof (err_msg); sqlglm(err_msg, &buf_len, &msg_len); printf("%.*s\n", msg_len, err_msg); /* EXEC SQL ROLLBACK RELEASE; */ { struct sqlexd sqlstm; sqlstm.sqlvsn = 10; sqlstm.arrsiz = 0; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )5; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); } exit(EXIT_FAILURE);
} /* void sql_error(msg) */
void main()
{
[--- omitted ---]
/* Register sql_error() as the error handler. */ /* EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");*/
[--- omitted ---]
{ struct sqlexd sqlstm; [--- omitted ---] if (sqlca.sqlcode < 0) sql_error("ORACLE error--\n"); } [--- omitted ---]
} /* void main() */
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Tue Oct 05 1999 - 00:42:09 CDT
![]() |
![]() |