Home » Developer & Programmer » Precompilers, OCI & OCCI » problem with runtime context in Pro*C
problem with runtime context in Pro*C [message #93603] |
Mon, 29 July 2002 22:46 |
DEEPIKA
Messages: 2 Registered: July 2002
|
Junior Member |
|
|
when i compile the following program using:
proc parse=NONE sqlcheck=SEMANTIC threads=YES release_cursor=YES connectOracle.pc
following error is reported:
Pro*C/C++: Release 8.0.5.1.0 - Production on Tue Jul 30 12:2:58 2002
(c) Copyright 1998 Oracle Corporation. All rights reserved.
System default option values taken from: /orc/oracle8/precomp/admin/pcscfg.cfg
Semantic error at line 30, column 29, file connectOracle.pc:
EXEC SQL CONTEXT ALLOCATE :ctx[[number]];
............................1
PCC-S-02322, found undefined identifier
Semantic error at line 30, column 29, file connectOracle.pc:
EXEC SQL CONTEXT ALLOCATE :ctx[[number]];
............................1
PCC-S-02391, Runtime context variable not of correct type
---------------------
code is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlca.h>
EXEC SQL INCLUDE SQLCA;
sql_context ctx[[5]];
//SQL_CONTEXT ctx[[5]];
void sql_error(void);
int connectOracleDb(char *user, char *pass, char *con_str,char *dbName,int number)
{
int val=0;
EXEC SQL BEGIN DECLARE SECTION;
char *uname,*pwd,*constr,*dbname;
EXEC SQL END DECLARE SECTION;
EXEC SQL ENABLE THREADS;
EXEC SQL CONTEXT ALLOCATE :ctx[[number]];
EXEC SQL CONTEXT USE :ctx[[number]];
uname = (char *)malloc(strlen(user) * sizeof(char));
pwd = (char *)malloc(strlen(pass) * sizeof(char));
constr = (char *)malloc(strlen(con_str)* sizeof(char));
dbname = (char *)malloc(strlen(dbName) * sizeof(char));
strcpy(uname,user);
strcpy(pwd,pass);
strcpy(constr,con_str);
strcpy(dbname,dbName);
EXEC SQL CONNECT :uname IDENTIFIED BY :pwd AT :dbname USING :constr;
if (sqlca.sqlcode<0)
{
sql_error();
val=-1;
}
else
val=100;
return(val);
}
int disconnectOracleDb(char *dbName, int number)
{
int val=0;
EXEC SQL BEGIN DECLARE SECTION;
char *dbname;
EXEC SQL END DECLARE SECTION;
EXEC SQL ENABLE THREADS;
EXEC SQL CONTEXT USE :ctx[[number]];
dbname = (char *)malloc(strlen(dbName)*sizeof(char));
strcpy(dbname,dbName);
EXEC SQL AT :dbname COMMIT WORK RELEASE;
if (sqlca.sqlcode<0)
{
sql_error();
val=-1;
}
else
val=100;
return(val);
}
int insertData(int arcount,char *wDbname,char *pstr,char *agentName,int number)
{
char *str;
int i = 0;
int val = 0;
EXEC SQL BEGIN DECLARE SECTION;
char *data[[6]];
char *prodid;
char *dbname;
varchar sql[[200]];
EXEC SQL END DECLARE SECTION;
EXEC SQL ENABLE THREADS;
EXEC SQL CONTEXT USE :ctx[[number]];
dbname=(char *)malloc(strlen(wDbname)*sizeof(char));
strcpy(dbname,wDbname);
str=(char *)malloc(80*sizeof(char));
prodid=(char *)malloc((1+strlen(agentName))*sizeof(char));
strcpy(prodid,agentName);
for(i=0;i<arcount;i++)
{
fflush(stdout);
sscanf(pstr,"%[[^;@]]",str);
data[[i]]=(char *)malloc(strlen(str)*sizeof(char));
fflush(stdout);
if (strcasecmp(str,"null")!=0)
strcpy((char *)data[[i]],str);
else
data[[i]]=NULL;
pstr+=strlen(str)+1;
}
sprintf(sql.arr,"INSERT INTO PIXLOG(PRODID,DATETIME,ERRTYPE,IPADDR,TYPE,ERRCODE,MSG) VALUES(:1,to_date(:2,'dd-mm-yyyy hh:mi:ss'),:3,:4,to_number(:5),to_Number(:6),:7)");
sql.len=strlen((char *)sql.arr);
EXEC SQL AT :dbname PREPARE SQLSTMT from :sql;
EXEC SQL AT :dbname EXECUTE SQLSTMT using :prodid , :data[[0]] ,:data[[1]] ,:data[[2]], :data[[3]], :data[[4]], :data[[5]];
EXEC SQL AT :dbname COMMIT WORK;
if (sqlca.sqlcode<0)
{
sql_error();
val=-1;
}
else
val=100;
prodid= (char *)malloc(10*sizeof(char));
free(prodid);
prodid=NULL;
str = (char *)malloc(10*sizeof(char));
free(str);
str=NULL;
dbname = (char *)malloc(10*sizeof(char));
free(dbname);
dbname=NULL;
for(i=0;i<5;i++)
{
data[[i]] = (char *)malloc(10*sizeof(char));
free(data[[i]]);
data[[i]]=NULL;
}
printf("nn exiting pix-insert functionn");
fflush(stdout);
return(val);
}
int sql_error()
{
printf("n ERROR WHILE OPERATION = %s",sqlca.sqlerrm.sqlerrmc);
fflush(stdout);
}
If anybdy can tell me what is wrong with the code?
|
|
|
|
Goto Forum:
Current Time: Thu Nov 28 07:11:26 CST 2024
|