Re: Pro*C/C++ and the goto operator

From: Alex Vinokur <alexander.vinokur_at_telrad.co.il>
Date: Tue, 05 Oct 1999 05:42:09 GMT
Message-ID: <7tc33g$a3o$1_at_nnrp1.deja.com>


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?

  1. I would like to use only standards.
  2. I don't use goto-operator in C/C++.
  3. So, I am trying to find another operator in Pro*C/C++ that
    • does not go against standard
    • is eqivalent to GOTO operator.

> 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?

[Quoted]   (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.

  • GOTO operator ===============
    • EXEC SQL syntax -----------
    • (sample1.pc) -----------
        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(;;) */

  • executible statements -----
  • (sample1.c) ------------
        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 =================

  • EXEC SQL syntax -----------
  • (sample1.pc) -----------

/* 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() */

  • executible statements -----
  • (sample1.c) ------------

/* 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 - 07:42:09 CEST

Original text of this message