By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,333 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,333 IT Pros & Developers. It's quick & easy.

Error compiling DB2 C++ application.

P: n/a
Hi Everyone,

I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.

For the time being, I am also looking at how to create packages and
bindfiles for DB2. I have the below mentioned code which is giving me
the following error:

########################################

#include <string.h>
#include <sqlenv.h>
#include <sqlutil.h>
#include "utilemb.h"
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{

EXEC SQL BEGIN DECLARE SECTION;

char PID[11];
sqlint32 quantity;
char location[128];

EXEC SQL END DECLARE SECTION;

cout << "Hopefully this will also work!!" << endl ;

EXEC SQL CONNECT TO SAMPLE ;

EXEC SQL CONNECT RESET ;

return 0 ;

}
########################################
ERROR:

[db2inst1@meridius embed]$ g++ sample2.C -I$DB2PATH/include
sample2.sqC: In function `int main()':
sample2.sqC:23: error: expected primary-expression before ')' token
sample2.sqC:25: error: expected primary-expression before ')' token
[db2inst1@meridius embed]$

I have copied utilemb.h to $DB2PATH/include directory.

Environment:

DB2 9.1 Fixpak 2
Linux 2.6
CentOS 4.4
GCC/G++ -->
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
disable-checking --with-system-zlib --enable-__cxa_atexit --disable-
libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
I have noticed that if I remove the following lines from the code, it
compiles successfully:

EXEC SQL CONNECT TO SAMPLE ;

EXEC SQL CONNECT RESET ;

I am only creating the database connection and disconnecting from it.
Can you shed some light as to what am I missing here?

Thanks!!.

dotyet

Feb 27 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Ian
dotyet wrote:
Hi Everyone,

I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.

For the time being, I am also looking at how to create packages and
bindfiles for DB2. I have the below mentioned code which is giving me
the following error:
When you write programs with embedded SQL, you have to run them through
the DB2 Precompiler, first. By convention, your source file would be
named 'test.sqC'. You'd then use the 'PREP' command:

db2 prep test.sqC bindfile

This produces the files 'test.C' and 'test.bnd'. You'd then use the
compiler to compile/link the test.C file, and the BIND command to add
the package to the database.

A word to the wise: Do *not* change the generated .C file after
executing the PREP command: The generated .C file is tied closely
to the corresponding .bnd file, and you'll create issues for yourself.
(Typically timestamp mismatch issues).

Good luck,
Feb 27 '07 #2

P: n/a
oops!!... sorry forgot to mention that i did use the prep command....

db2 "prep sample2.sqC bindfile"

which generated the .C file.

Anyways, advise taken and still waiting for more of them. For the time
being, the problem persists.

rgds,
dotyet.

On Feb 26, 10:46 pm, Ian <ianb...@mobileaudio.comwrote:
dotyet wrote:
Hi Everyone,
I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.
For the time being, I am also looking at how to create packages and
bindfiles for DB2. I have the below mentioned code which is giving me
the following error:

When you write programs with embedded SQL, you have to run them through
the DB2 Precompiler, first. By convention, your source file would be
named 'test.sqC'. You'd then use the 'PREP' command:

db2 prep test.sqC bindfile

This produces the files 'test.C' and 'test.bnd'. You'd then use the
compiler to compile/link the test.C file, and the BIND command to add
the package to the database.

A word to the wise: Do *not* change the generated .C file after
executing the PREP command: The generated .C file is tied closely
to the corresponding .bnd file, and you'll create issues for yourself.
(Typically timestamp mismatch issues).

Good luck,

Feb 27 '07 #3

P: n/a
In article <11*********************@8g2000cwh.googlegroups.co m>,
do****@yahoo.com says...
Hi Everyone,

I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.
Did you use the sample bld script to compile yout program. You can find
it at http://tinyurl.com/2evjlh .
Feb 27 '07 #4

P: n/a
Hi Gert,

Yes, I tried the build script as well. But that also led to the same
error.

Is it required that the code HAS to be in a class and not just a
function?

rgds,
dotyet

On Feb 27, 7:36 am, Gert van der Kooij <nom...@invalid.nlwrote:
In article <1172542691.232236.70...@8g2000cwh.googlegroups.co m>,
dot...@yahoo.com says...
Hi Everyone,
I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.

Did you use the sample bld script to compile yout program. You can find
it athttp://tinyurl.com/2evjlh.

Feb 27 '07 #5

P: n/a
Ian
dotyet wrote:
oops!!... sorry forgot to mention that i did use the prep command....

db2 "prep sample2.sqC bindfile"

which generated the .C file.

Anyways, advise taken and still waiting for more of them. For the time
being, the problem persists.
Oh, and you have to include a definition for variable called 'sqlca'
in your code, because the precompiler will generate code that depends
on this variable's existence.

Add:

struct sqlca sqlca = { 0 };

Then you should be OK.

Feb 27 '07 #6

P: n/a
Hi Ian,

Thanks for the tip, that did the magic. the file compiled with the
following warning only.. :) .... (which i will try to
"understand" )...

/home/db2inst1/sqllib/lib64/libimf.so: warning: warning: feupdateenv
is not implemented and will always fail
/usr/bin/ld: warning: libstdc++.so.5, needed by /home/db2inst1/sqllib/
lib/libdb2.so, may conflict with libstdc++.so.6

I am yet to read the document on how to use the struct though.

Interesting stuff...

Thanks a lot.

rgds,
dotyet
On Feb 27, 3:53 pm, Ian <ianb...@mobileaudio.comwrote:
dotyet wrote:
oops!!... sorry forgot to mention that i did use the prep command....
db2 "prep sample2.sqC bindfile"
which generated the .C file.
Anyways, advise taken and still waiting for more of them. For the time
being, the problem persists.

Oh, and you have to include a definition for variable called 'sqlca'
in your code, because the precompiler will generate code that depends
on this variable's existence.

Add:

struct sqlca sqlca = { 0 };

Then you should be OK.

Feb 28 '07 #7

P: n/a
On Feb 26, 9:18 pm, "dotyet" <dot...@yahoo.comwrote:
Hi Everyone,

I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.
Hi dotyet;
You may already be aware of this, but the ADMIN_CMD stored procedure
(shipped with DB2 with lots of table functions), surfaces alot of the
things you could only get to via the admin APIs. More is being added
with each release. I only mention it because I went to some trouble
coding C programs for external routines and am in the process of
converting them to use the new ADMIN_CMD interface...

Pete H

Feb 28 '07 #8

P: n/a
OK. Sounds good. I will have a look at that too.

regards,
dotyet

On Feb 28, 10:01 am, "peteh" <phazz...@intellicare.comwrote:
On Feb 26, 9:18 pm, "dotyet" <dot...@yahoo.comwrote:
Hi Everyone,
I am learning how to write C++ programs for DB2. My primary area of
concern would be the administrative level DB2 APIs.

Hi dotyet;
You may already be aware of this, but the ADMIN_CMD stored procedure
(shipped with DB2 with lots of table functions), surfaces alot of the
things you could only get to via the admin APIs. More is being added
with each release. I only mention it because I went to some trouble
coding C programs for external routines and am in the process of
converting them to use the new ADMIN_CMD interface...

Pete H

Feb 28 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.