Some DB2 Doubts 
Author Message
 Some DB2 Doubts

Hi Friends,

I have the following questions regarding Embedded SQL programming using
DB2UDB.

(a) Do all Host Variables in DB2 have Global scope, i.e do they become
Global Variables?

(b) Can pointers be used as Host Variables as shown below?
func(char *name)
{
EXEC SQL
select name into :name from names where id = 1;

Quote:
}

(c) What is the maximum size of a string (character array) which can be
used as Host Variable?
func()
{
char name[1000];
EXEC SQL
insert into names(name) values (:name);

Quote:
}

(d) Should the extension of the Embedded SQL file be only .sqc?

I require these points to prepare a document for future Porting to
DB2UDB from other databases like Oracle/Informix.

Thanks in advance for answering these questions.

Best Regards
MS

Sent via Deja.com http://www.***.com/
Before you buy.



Wed, 05 Mar 2003 08:34:21 GMT
 Some DB2 Doubts

Quote:
> (a) Do all Host Variables in DB2 have Global scope, i.e do they become
> Global Variables?

This is a common misconception.  The precompiler doesn't understand C
scoping rules, so it will only allow one occurrence of each host
variable name in a file.  Once you get past the precompiler, however,
all the normal C scoping rules are in effect.

Quote:
> (b) Can pointers be used as Host Variables as shown below?
> func(char *name)
> {
> EXEC SQL
> select name into :name from names where id = 1;
> }

You can do this, and the Application Programming Guide disucsses it.
The trick is, DB2 needs to know the maximum length of the host
variable.  You also need to dereference you pointer before using it as a
host variable.

You can do all this by changing your code to:

func (char (*name)[50])
{
   EXEC SQL SELECT name INTO :*name FROM names WHERE id = 1;

Quote:
}
> (c) What is the maximum size of a string (character array) which can be
> used as Host Variable?
> func()
> {
> char name[1000];
> EXEC SQL
> insert into names(name) values (:name);
> }

For the workstation version of BD2:
As of DB2 v6.1, string host variables can be up to 32,672 bytes long.
In earlier releases, the max was 4000 characters.

I'm not sure what the limits are on DB2 for OS/390, VM/VSE, or OS/400.

Quote:
> (d) Should the extension of the Embedded SQL file be only .sqc?

It depends on the programming language you want to use.  Standard
extensions are:
   .sqc - C
   .sqC - C++ (where the OS has a case sensitive filesystem)
   .sqx - C++
   .sqb - COBOL
   .sqf - FORTRAN

You can also use the TARGET option on the PREP command to tell DB2 to
process for a specific language.

Hope this helps.
--
___________________________________________________________________________
    Doug Doole
    DB2 Universal Database Development
    IBM Toronto Labs



Fri, 07 Mar 2003 03:00:00 GMT
 Some DB2 Doubts
Hi Doug,

Thanks a lot for the answers.

bRgds/MS



Quote:
> > (a) Do all Host Variables in DB2 have Global scope, i.e do they
become
> > Global Variables?

> This is a common misconception.  The precompiler doesn't understand C
> scoping rules, so it will only allow one occurrence of each host
> variable name in a file.  Once you get past the precompiler, however,
> all the normal C scoping rules are in effect.

> > (b) Can pointers be used as Host Variables as shown below?
> > func(char *name)
> > {
> > EXEC SQL
> > select name into :name from names where id = 1;
> > }

> You can do this, and the Application Programming Guide disucsses it.
> The trick is, DB2 needs to know the maximum length of the host
> variable.  You also need to dereference you pointer before using it
as a
> host variable.

> You can do all this by changing your code to:

> func (char (*name)[50])
> {
>    EXEC SQL SELECT name INTO :*name FROM names WHERE id = 1;
> }

> > (c) What is the maximum size of a string (character array) which
can be
> > used as Host Variable?
> > func()
> > {
> > char name[1000];
> > EXEC SQL
> > insert into names(name) values (:name);
> > }

> For the workstation version of BD2:
> As of DB2 v6.1, string host variables can be up to 32,672 bytes long.
> In earlier releases, the max was 4000 characters.

> I'm not sure what the limits are on DB2 for OS/390, VM/VSE, or OS/400.

> > (d) Should the extension of the Embedded SQL file be only .sqc?

> It depends on the programming language you want to use.  Standard
> extensions are:
>    .sqc - C
>    .sqC - C++ (where the OS has a case sensitive filesystem)
>    .sqx - C++
>    .sqb - COBOL
>    .sqf - FORTRAN

> You can also use the TARGET option on the PREP command to tell DB2 to
> process for a specific language.

> Hope this helps.
> --

________________________________________________________________________
___

Quote:
>     Doug Doole
>     DB2 Universal Database Development
>     IBM Toronto Labs

Sent via Deja.com http://www.deja.com/
Before you buy.


Fri, 07 Mar 2003 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. db2 xml extender..serious doubt

2. Distributed DB2 - Oracle/Oracle - Oracle/DB2 - DB2/DB2

3. Differences between SQL on DB2-MVS and DB2-OS/2 or DB2-NT

4. Galley my wild animal doubt is the following:

5. sql server 6.0 stored procedure doubts

6. Query Doubt

7. importing doubt

8. Doubt on queries !

9. Doubt in SQL Server TEXT datatypes

10. MDX Query Doubt

11. doubt in using partitions

12. Data Analyzer doubts


 
Powered by phpBB® Forum Software