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
You can do all this by changing your code to:
func (char (*name))
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?
> char name;
> 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
.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.
DB2 Universal Database Development
IBM Toronto Labs