Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Scope of EXEC SQL DECLARE <cursor>

Re: Scope of EXEC SQL DECLARE <cursor>

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Tue, 26 Oct 1999 09:19:50 -0400
Message-ID: <EqoVOOyFptSnD=MWbz+OYVyOtYYz@4ax.com>


A copy of this was sent to Alex Vinokur <alexander.vinokur_at_telrad.co.il> (if that email address didn't require changing) On Tue, 26 Oct 1999 11:24:38 GMT, you wrote:

>Hi,
>
>Here is a program containing the same line
> EXEC SQL DECLARE the_cursor CURSOR FOR the_exec;
>in two different functions (foo1 and foo2).
>I have got warning message (see below).
>
>Does it mean that EXEC SQL DECLARE <cursor>
> always has global scope?
>If it is right, what is a reason for that?
>(Does it depend on SQL scope?)
>Ordinary internal variables have a local scope.
>

the scope of ALL proc EXEC SQL stuff (cursors, statements, etc) are from the point in the file they are found ON down. They do not obey C scope at all -- they are global and from the point they are seen in the file as you go from line 1 to line N.

>Do we have to use different names in
> EXEC SQL DECLARE <cursor>
> even if these declarations
> are in different functions?

Yes.

>If EXEC SQL DECLARE <cursor> has a global scope,
> why is the message warning one,
> but not error one?
>
> Thanks,
> Alex
>
>
>//#########################################################
>//------------------- Pro*C++ code : BEGIN ----------------
>
>//==========================
>#include <stdio.h>
>
>#include <sqlca.h>
>#include <sqlda.h>
>#include <sqlcpr.h>
>#include <oraca.h>
>//==========================
>
>
>//###############################
>//###############################
>class FOO
>{
> private :
> public :
> void foo1 ();
> void foo2 ();
>};
>
>
>//###############################
>//===============================
>void FOO::foo1()
>{
>EXEC SQL BEGIN DECLARE SECTION;
>const char *host_command_line = "DUMMY";
>EXEC SQL END DECLARE SECTION;
>
> EXEC SQL PREPARE the_exec FROM :host_command_line;
> EXEC SQL DECLARE the_cursor CURSOR FOR the_exec;
>
>} // void FOO::foo1()
>
>//===============================
>void FOO::foo2()
>{
>EXEC SQL BEGIN DECLARE SECTION;
>const char *host_command_line = "DUMMY";
>EXEC SQL END DECLARE SECTION;
>
> EXEC SQL PREPARE the_exec FROM :host_command_line;
> EXEC SQL DECLARE the_cursor CURSOR FOR the_exec; // Line#43
>
>} // void FOO::foo2()
>
>
>//###############################
>//===============================
>int main ()
>{
> return 0;
>}
>
>
>//------------------- Pro*C++ code : END ------------------
>
>
>
>//#########################################################
>//------------------- Compilation Results : BEGIN --------- code=cpp
>sys_include=(/opt/SUNWspro/SC4.2/include,/opt/SUNWspro/SC4.2/include/CC,/usr/
>include,/opt/SUNWspro/RW/workspaces/SOLARIS26/SUNPRO42/7s) code=cpp
>sys_include=(/opt/SUNWspro/SC4.2/include,/opt/SUNWspro/SC4.2/include/CC,/usr/
>include,/opt/SUNWspro/RW/workspaces/SOLARIS26/SUNPRO42/7s) proc code=cpp
>sys_include='(/opt/SUNWspro/SC4.2/include,/opt/SUNWspro/SC4.2/include/CC,/usr
>/include,/opt/SUNWspro/RW/workspaces/SOLARIS26/SUNPRO42/7s)' iname=ntt
>MODE=ORACLE LINES=YES CPP_SUFFIX=cpp CHAR_MAP=STRING
>
>Pro*C/C++: Release 8.0.5.0.0 - Production on Tue Oct 26 12:48:2 1999
>
>(c) Copyright 1998 Oracle Corporation. All rights reserved.
>
>System default option values taken from:
>/home/u01/app/oracle/product/8.0.5/precomp/admin/pcscfg.cfg
>
>Warning at line 43, column 19, file ntt.pc:
> EXEC SQL DECLARE the_cursor CURSOR FOR the_exec;
>..................1
>PCC-W-02332, attempted to redefine SQL identifier
>
>[snip]
>
>
>//------------------- Compilation Results : END -----------
>
>
>//#########################################################
>//------------------- Environment -------------------------
>
>=== Oracle 8.0.5
>=== Pro*C/C++ : Release 8.0.5.0.0
>=== CC: WorkShop Compilers 4.2 30 Oct 1996 C++ 4.2
>=== SunOS 5.6
>
>//---------------------------------------------------------
>
>//#########################################################
>
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.

--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Tue Oct 26 1999 - 08:19:50 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US