Re: Pro*C - extra space after variables

From: Kenneth C Stahl <BlueSax_at_Unforgettable.com>
Date: Thu, 09 Dec 1999 11:00:33 -0500
Message-ID: <384FD221.BEDE60A8_at_Unforgettable.com>


Thomas Kyte wrote:
>
> why? how is that largish amount of code better then:
>
> int get_date(void)
> {
> static varchar today[8];
>
> exec sql whenever sqlerror goto sqlerr;
> exec sql whenever not_found goto sqlerr;
> exec sql select to_char(sysdate,'yyyymmdd') into :today from dual;
>
> fprintf(stdout,"Today: %.*s",today.len,today.arr);
>
> return 0;
> sqlerr:
> return 1;
> }

In the code above, there is automatically two trips to the database even though only one row is expected. You absolutely cannot control this when you use implicit cursors because it has no way of knowing that only one row will ever be returned and therefore it must make the second trip to the database in order to determine if it needs to indicate a "too many rows" error.

[Quoted] Also, are you absolutely sure that you want to use the static storage class when an automatic would be sufficient? I am always suspicious of 'static' within a function since it normally indicates some type of kluge.

[Quoted] I've said it before and I'll keep saying it - simple code is not necessarily better code. Precise control over what a program does (providing it is written properly) will never get you into trouble whereas shortcuts and arcane practices are invitations to problems. Received on Thu Dec 09 1999 - 17:00:33 CET

Original text of this message