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

From: Kenneth C Stahl <BlueSax_at_Unforgettable.com>
Date: Mon, 04 Oct 1999 13:34:53 -0400
Message-ID: <37F8E53D.AA60F032_at_Unforgettable.com>


[Quoted] Why do you want to write something that goes against the standards that [Quoted] [Quoted] Oracle has instituted? If you follow Oracle's method of using Pro-C your [Quoted] 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.

[Quoted] Hint: look at the precompiler output to see what happens to the EXEC SQL [Quoted] syntax when it is rewritten into executible statements by the precompiler.

Ken

Alex Vinokur wrote:
>
> Hi,
>
> Here is a piece of code from
> file sample1.pc (Pro*C/C++ Demo).
>
> ===================================================
> for (;;)
> {
> emp_number = 0;
> printf("\nEnter employee number (0 to quit): ");
> gets(temp_char);
> emp_number = atoi(temp_char);
> if (emp_number == 0)
> break;
>
> /* Branch to the notfound label when the
> * 1403 ("No data found") condition occurs.
> */
> EXEC SQL WHENEVER NOT FOUND GOTO notfound; // ATTENTION#1
>
> EXEC SQL SELECT ename, sal, comm
> INTO :emprec INDICATOR :emprec_ind
> FROM EMP
> WHERE EMPNO = :emp_number;
>
> /* Print data. */
> printf("\n\nEmployee Salary Commission\n");
> printf("-------- ------- ----------\n");
>
> /* Null-terminate the output string data. */
> emprec.emp_name.arr[emprec.emp_name.len] = '\0';
> printf("%s %7.2f ",
> emprec.emp_name.arr, emprec.salary);
>
> if (emprec_ind.comm_ind == -1)
> printf("NULL\n");
> else
> printf("%7.2f\n", emprec.commission);
>
> total_queried++;
> continue;
>
> notfound: // ATTENTION#2
> printf("\nNot a valid employee number - try again.\n");
>
> } /* end for(;;) */
> ===================================================
>
> This code uses the goto operator
> EXEC SQL WHENEVER NOT FOUND GOTO notfound
> and label (notfound).
>
> The question is:
> Can we write (in Pro*C/C++)
> an equivalent program
> that does not use the goto operator?

........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
Received on Mon Oct 04 1999 - 19:34:53 CEST

Original text of this message