Discussion:
Embedded SQL C++ Program - Error C2275
(too old to reply)
9***@gmail.com
2007-10-24 21:49:30 UTC
Permalink
Hello there,

I'm trying to write my first Embedded SQL C++ program but am hung up with 6 instances of the following error:
"cpp.sqx(29) : error C2275: 'sqlca' : illegal use of this type as an expression c:\program files\ibm\sqllib\include\sqlca.h(40) : see declaration of 'sqlca'"

What I'm getting from that error message is that the Visual C++ 2005 Express compiler that I'm using doesn't like the way that DB2 prepped my .sqx into a .cxx.

Here's my .sqx:
----------------------------------------------
#include <sqlenv.h>
#include <sqlutil.h>
#include "utilemb.h"
#if ((__cplusplus >= 199711L) && !defined DB2HP && !defined DB2AIX) || \
(DB2LINUX && (__LP64__ || (__GNUC__ >= 3)) )
#include <iomanip>
#include <iostream>
using namespace std;
#else
#include <iomanip.h>
#include <iostream.h>
using namespace std;
#endif

EXEC SQL BEGIN DECLARE SECTION;
char dbName[10];
char dbUser[20];
char dbPswd[40];
char currentDate[50];
EXEC SQL END DECLARE SECTION;

extern "c" __declspec(dllexport)
void jonoGetChar(char* db, char* user, char* pswd, char* out_date)
{
sprintf(dbName, "%s", db);
sprintf(dbUser, "%s", user);
sprintf(dbPswd, "%s", pswd);

EXEC SQL CONNECT TO :dbName USER :dbUser USING :dbPswd;
EXEC SQL SELECT CURRENT DATE INTO :currentDate FROM MYTABLE WHERE FLAG = '1';
EXEC SQL CONNECT RESET;

sprintf(out_date, "%s", currentDate);
}

int main(int argc, char *argv[])
{
int rc = 0;

return rc;
}
-------------------------------------------------------------------


First I connect to my database and then run
"db2 prep cpp.sqx"
I then disconnect from my database and run
"cl -Zi -Od -c -W2 -LD -DWIN32 /EHsc cpp.cxx utilemb.cxx"
When that runs I get all those errors complaining about 'sqlca'.

Any ideas why that's not working?

Thanks!
Knut Stolze
2007-10-25 06:14:14 UTC
Permalink
Post by 9***@gmail.com
Hello there,
I'm trying to write my first Embedded SQL C++ program but am hung up with
illegal use of this type as an expression c:\program
files\ibm\sqllib\include\sqlca.h(40) : see declaration of 'sqlca'"
What I'm getting from that error message is that the Visual C++ 2005
Express compiler that I'm using doesn't like the way that DB2 prepped my
.sqx into a .cxx.
----------------------------------------------
#include <sqlenv.h>
#include <sqlutil.h>
#include "utilemb.h"
#if ((__cplusplus >= 199711L) && !defined DB2HP && !defined DB2AIX) || \
(DB2LINUX && (__LP64__ || (__GNUC__ >= 3)) )
#include <iomanip>
#include <iostream>
using namespace std;
#else
#include <iomanip.h>
#include <iostream.h>
using namespace std;
#endif
EXEC SQL BEGIN DECLARE SECTION;
char dbName[10];
char dbUser[20];
char dbPswd[40];
char currentDate[50];
EXEC SQL END DECLARE SECTION;
I recommend that you add here:

EXEC SQL INCLUDE SQLCA;
Post by 9***@gmail.com
extern "c" __declspec(dllexport)
void jonoGetChar(char* db, char* user, char* pswd, char* out_date)
{
sprintf(dbName, "%s", db);
sprintf(dbUser, "%s", user);
sprintf(dbPswd, "%s", pswd);
EXEC SQL CONNECT TO :dbName USER :dbUser USING :dbPswd;
EXEC SQL SELECT CURRENT DATE INTO :currentDate FROM MYTABLE WHERE FLAG =
'1'; EXEC SQL CONNECT RESET;
sprintf(out_date, "%s", currentDate);
}
int main(int argc, char *argv[])
{
int rc = 0;
return rc;
}
-------------------------------------------------------------------
Also, it is good coding practice to avoid global variables if you don't need
them. Therefore, you should move the DECLARE SECTION inside those functions
where you need the respective host variables. Likewise, you should move the
EXEC SQL INCLUDE SQLCA inside each function that accesses DB2.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Continue reading on narkive:
Loading...