Re: Pro*C - extra space after variables
Date: Thu, 09 Dec 1999 17:43:24 +0800
Message-ID: <384F79BC.7037_at_yahoo.com>
Kenneth C Stahl wrote:
>
> 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.
>
> 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.
>
> 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.
I'd be interested in seeing a trace of this...I was on the understanding that as of some version (7.3+ maybe) this problem had been 'solved'...that is, a trace revealed only a single fetch even for the implicit case...
If I had a server at home I'd try it myself...
Cheers
-- =========================================== Connor McDonald "These views mine, no-one elses etc etc" connor_mcdonald_at_yahoo.com "Some days you're the pigeon, and some days you're the statue."Received on Thu Dec 09 1999 - 10:43:24 CET