Some DB2 Doubts

Some DB2 Doubts

Post by Manoj SASIDHARA » Sun, 17 Sep 2000 09:34:21



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.deja.com/
Before you buy.

 
 
 

Some DB2 Doubts

Post by Doug Dool » Tue, 19 Sep 2000 04:00:00


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

 
 
 

Some DB2 Doubts

Post by Manoj SASIDHARA » Tue, 19 Sep 2000 04:00:00


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.
 
 
 

1. db2 xml extender..serious doubt

I'm working with XML extnder..and am storing data throught XColumn.
It seems it is impossible to store a documnet which has  a DTD like

<!ELEMENT ARTICLE (CHAPTER+)>
<!ATTLIST ARTICLE ARTICLE-ID KEY #REQUIRED>

<!ELEMENT CHAPTER (SECTION+)>
<!ATTLIST CHAPTER CHAPTER-ID KEY #REQUIRED>

<!ELEMET SECTION (TEXT+)>
<!ATTLIST SECTION SECTION-ID KEY #REQUIRED>

<!ELEMENT TEXT (#PCDATA)>

I need to store all the elements and attributes in side-tables(I can very
well do it with XCollection, but I need to do with XColumn :) becuase of
some reasons.

Now multi_occurence attribute in DAD file will have value "YES" for
CHAPTER-ID as well as for SEcTION-ID. so I cannot store both of these
together in the same tables. Thus it is a lossy decomposition, as I cannot
know after decomposition which section belong to which chapters. becuase I
need to have a table in which there are columns for both chapter-id and
section-id telling which sections occur in which chapter. I don't think it
is possible because multi-occurence attribute for both of these is "YES".

Is there a way out, so that it is a lossless decomposition.
Thanks in advance...

p.s: I think I'm somewhat misinterpreting multi-occurence attribute. Can
anyone clarify how it is used.

Sincerely
-Nitin Khandelwal
Computer Science and Engineering
University of Waterloo

Studying in: Indian Institute of Technology, India

2. Change sorting behaviour?

3. Distributed DB2 - Oracle/Oracle - Oracle/DB2 - DB2/DB2

4. How to use cursor properly?

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

6. cursor bug introduced in SP3?

7. Galley my wild animal doubt is the following:

8. AMD XML Report Engine Released! -- XML/XSLT-based client-side sorting, grouping, filtering and more.

9. sql server 6.0 stored procedure doubts

10. Query Doubt

11. importing doubt

12. Doubt on queries !

13. Doubt in SQL Server TEXT datatypes