Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / February 2007

Tip: Looking for answers? Try searching our database.

Error compiling DB2 C++ application.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dotyet - 27 Feb 2007 02:18 GMT
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
Ian - 27 Feb 2007 03:46 GMT
> Hi Everyone,
>
[quoted text clipped - 4 lines]
> 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,
dotyet - 27 Feb 2007 11:20 GMT
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.

> > Hi Everyone,
>
[quoted text clipped - 21 lines]
>
> Good luck,
Ian - 27 Feb 2007 20:53 GMT
> oops!!... sorry forgot to mention that i did use the prep command....
>
[quoted text clipped - 4 lines]
> 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.
dotyet - 28 Feb 2007 12:47 GMT
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

> > oops!!... sorry forgot to mention that i did use the prep command....
>
[quoted text clipped - 14 lines]
>
> Then you should be OK.
Gert van der Kooij - 27 Feb 2007 12:36 GMT
> 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 .
dotyet - 27 Feb 2007 13:59 GMT
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

> In article <1172542691.232236.70...@8g2000cwh.googlegroups.com>,
> dot...@yahoo.com says...
[quoted text clipped - 6 lines]
> Did you use the sample bld script to compile yout program. You can find
> it athttp://tinyurl.com/2evjlh.
peteh - 28 Feb 2007 15:01 GMT
> 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
dotyet - 28 Feb 2007 16:49 GMT
OK. Sounds good. I will have a look at that too.

regards,
dotyet

> > Hi Everyone,
>
[quoted text clipped - 10 lines]
>
> Pete H
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.