problem in compiling pro*c code [message #94154] |
Tue, 06 April 2004 02:04 |
xicongzhui
Messages: 1 Registered: April 2004
|
Junior Member |
|
|
when i compile the following program using:
proc iname=DBFunction.pc oname=DBFunction.c code=c includ
e="D:oracleora92precomppublic"
following error is reported:
Pro*C/C++: Release 9.2.0.1.0 - Production on ‰Î Apr 6 18:01:06 2004
Copyright (c) 1982, 2002, Oracle Corporation.[sp] All rights reserved.
System default option values taken from: D:oracleora92precompadminpcscfg.cfg
Semantic error at line 23, column 21, file DBFunction.pc:
[sp]VARCHAR uid[[ID_SIZE]];[sp][sp][sp][sp][sp][sp][sp] /* user name host variable */
............................1
PCC-S-02322, found undefined identifier
Semantic error at line 23, column 21, file DBFunction.pc:
[sp]VARCHAR uid[[ID_SIZE]];[sp][sp][sp][sp][sp][sp][sp] /* user name host variable */
............................1
PCC-S-02322, found undefined identifier
Semantic error at line 23, column 21, file DBFunction.pc:
[sp]VARCHAR uid[[ID_SIZE]];[sp][sp][sp][sp][sp][sp][sp] /* user name host variable */
............................1
PCC-S-02322, found undefined identifier
code is
#include <stdio.h>
#include <string.h>
#include <sqlca.h>
#include <oraca.h>
#include <stdlib.h>
#define SQLCA_STORAGE_CLASS extern
#define ORACA_STORAGE_CLASS extern
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE ORACA;
EXEC ORACLE OPTION (ORACA=YES);
EXEC ORACLE OPTION (RELEASE_CURSOR=YES);
#define ID_SIZE[sp][sp][sp][sp][sp][sp][sp][sp][sp][sp][sp][sp][sp][sp][sp][sp] 80
int connectToDB()
{
[sp][sp][sp] EXEC SQL BEGIN DECLARE SECTION;
[sp][sp][sp][sp][sp][sp][sp] VARCHAR uid[[ID_SIZE]];[sp][sp][sp][sp][sp][sp][sp] /* user name host variable */
[sp][sp][sp][sp][sp][sp][sp] VARCHAR pwd[[80]];[sp][sp][sp][sp][sp][sp][sp] /* user password host variable */
[sp][sp][sp][sp][sp][sp][sp] VARCHAR db_str[[20]];[sp][sp][sp][sp] /* database host machine&database name */
[sp][sp][sp] EXEC SQL END DECLARE SECTION;
[sp][sp][sp] EXEC SQL WHENEVER SQLERROR GOTO ErrorConnect;
[sp][sp][sp] oraca.orastxtf = ORASTFERR;
[sp][sp][sp] strcpy((char *)uid.arr, "vcs");
[sp][sp][sp] strcpy((char *)pwd.arr, "vcs");
[sp][sp][sp] strcpy((char *)db_str.arr, "vcs.sunjapan.com.cn");
[sp][sp][sp] uid.len = (unsigned short)strlen((char *)uid.arr);
[sp][sp][sp] pwd.len = (unsigned short)strlen((char *)pwd.arr);
[sp][sp][sp] db_str.len = (unsigned short)strlen((char *)db_str.arr);
[sp][sp][sp] /* connect to oracle system */
[sp][sp][sp] if(db_str.len == 0) {
[sp][sp][sp][sp][sp][sp][sp] EXEC SQL CONNECT :uid IDENTIFIED BY :pwd;
[sp][sp][sp] } else {
[sp][sp][sp][sp][sp][sp][sp] EXEC SQL CONNECT :uid IDENTIFIED BY :pwd USING :db_str;
[sp][sp][sp] }
[sp][sp][sp] if(sqlca.sqlcode==1403) {[sp] /* user/password not found */
[sp][sp][sp][sp][sp][sp][sp] return -1;
[sp][sp][sp] }
[sp][sp][sp] if(sqlca.sqlcode<0) {[sp] /* other system error */
[sp][sp][sp][sp][sp][sp][sp] printf("%sn",sqlca.sqlerrm.sqlerrmc);
[sp][sp][sp][sp][sp][sp][sp] printf("Cann't login into oracle system!nn");
[sp][sp][sp][sp][sp][sp][sp] return -1;
[sp][sp][sp] }
[sp][sp][sp]
[sp][sp][sp] return 0;
[sp][sp][sp] ErrorConnect:
[sp][sp][sp] return -1;
}
|
|
|
|
Re: problem in compiling pro*c code [message #94159 is a reply to message #94156] |
Thu, 08 April 2004 21:02 |
Kaustubh Deshpande
Messages: 32 Registered: March 2004
|
Member |
|
|
Hi,
There are restrictions on the use of the #define preprocessor directive in Pro*C/C++
You cannot use the #define directive to create symbolic constants for use in
executable SQL statements.
The following invalid example demonstrates this:
#define RESEARCH_DEPT 40
...
EXEC SQL SELECT empno, sal
INTO :emp_number, :salary /* host arrays */
FROM emp
WHERE deptno = RESEARCH_DEPT; /* INVALID! */
The only declarative SQL statements where you can legally use a #defined macro
are TYPE and VAR statements.
So, for example, the following uses of a macro are
legal in Pro*C/C++
#define STR_LEN 40
...
typedef char asciiz[[STR_LEN]];
...
EXEC SQL TYPE asciiz IS STRING(STR_LEN) REFERENCE;
...
EXEC SQL VAR password IS STRING(STR_LEN);
Regards,
Kaustubh Deshpande
|
|
|
Re: problem in compiling pro*c code [message #94198 is a reply to message #94154] |
Wed, 05 May 2004 04:47 |
Gerald
Messages: 54 Registered: January 2001
|
Member |
|
|
Had similar problem. For your example I used
EXEC SQL BEGIN DECLARE SECTION;
#define ID_SIZE 80
const int ID_OTHERWAY_SIZE = 80;
EXEC SQL END DECLARE SECTION;
Now its in ORACLE scope. You could also the sample const as well. My problem was getting a ton of these into a separate include file to be shared by all. I am using an 8.x version so not sure of support in 9.x
|
|
|