EXEC SQL BEGIN DECLARE SECTION;
sql_context ctx1[CONTEXT_MAX_COUNT];
EXEC SQL END DECLARE SECTION;
EXEC SQL TYPE my_long IS LONG VARCHAR(
1000000
) REFERENCE;
int
oracleConnect(
char
* szAlias,
char
* szUser,
char
* szPass,
int
nContextCount)
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[
128
];
VARCHAR password[
32
];
VARCHAR alias[
128
];
int
nCount =
0
;
EXEC SQL END DECLARE SECTION;
memset(username.arr,
0x00
, sizeof(username.arr));
username.len =
0
;
memset(password.arr,
0x00
, sizeof(password.arr));
password.len =
0
;
memset(alias.arr,
0x00
, sizeof(alias.arr));
alias.len =
0
;
strcpy((
char
*)username.arr, szUser);
username.len = (unsigned
short
)strlen(szUser);
strcpy((
char
*)password.arr, szPass);
password.len = (unsigned
short
)strlen(szPass);
EXEC SQL WHENEVER SQLERROR GOTO connect_error;
if
(strlen(szAlias) >
0
)
{
strcpy((
char
*)alias.arr, szAlias);
alias.len = (unsigned
short
)strlen(szAlias);
EXEC SQL CONTEXT USE :ctx1[nContextCount];
EXEC SQL CONNECT :username IDENTIFIED BY :password USING :alias;
}
else
{
EXEC SQL CONTEXT USE :ctx1[nContextCount];
EXEC SQL CONNECT :username IDENTIFIED BY :password ;
}
return
STAT_OK;
connect_error:
return
(sqlca.sqlcode);
}
int
oracleClose()
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
int
nCount =
0
;
for
(nCount=
0
; nCount<g_nContextCount; nCount++)
{
EXEC SQL CONTEXT USE :ctx1[nCount];
EXEC SQL COMMIT WORK RELEASE;
}
return
STAT_OK;
}
int
oracleSelectPolicyList(
char
* sqlText, PolicyList **head,
int
nContextNumber)
{
EXEC SQL BEGIN DECLARE SECTION;
int
result;
int
general =
0
;
VARCHAR PolicyID[
50
];
VARCHAR PolicyCode[
10
];
VARCHAR Type[
10
];
VARCHAR UsageType[
10
];
EXEC SQL END DECLARE SECTION;
PolicyList *first, *second;
memset(PolicyID.arr,
0x00
, sizeof(PolicyID.arr));
PolicyID.len =
0
;
memset(PolicyCode.arr,
0x00
, sizeof(PolicyCode.arr));
PolicyCode.len =
0
;
memset(Type.arr,
0x00
, sizeof(Type.arr));
Type.len =
0
;
memset(UsageType.arr,
0x00
, sizeof(UsageType.arr));
UsageType.len =
0
;
EXEC SQL WHENEVER SQLERROR CONTINUE;
#ifdef _USER_THREAD
EXEC SQL CONTEXT USE :ctx1[nContextNumber];
#endif
EXEC SQL PREPARE ORA_STMT FROM :sqlText;
EXEC SQL DECLARE ORA_CUR_SELECT CURSOR FOR ORA_STMT;
EXEC SQL OPEN ORA_CUR_SELECT ;
while
(
1
)
{
EXEC SQL FETCH ORA_CUR_SELECT INTO :PolicyID, :PolicyCode, :Type, :UsageType;
result = sqlca.sqlcode;
if
(result ==
1403
)
{
break
;
}
else
if
((result <
0
) && (result != ORACLE_STAT_NULL_RETURN))
{
EXEC SQL CLOSE ORA_CUR_SELECT;
return
result;
}
if
(general ==
0
)
{
*head = (PolicyList *)calloc(
1
, sizeof(PolicyList));
strncpy((*head)->PolicyID, (
char
*)PolicyID.arr, PolicyID.len);
strncpy((*head)->PolicyCode, (
char
*)PolicyCode.arr, PolicyCode.len);
strncpy((*head)->Type, (
char
*)Type.arr, Type.len);
strncpy((*head)->UsageType, (
char
*)UsageType.arr, UsageType.len);
(*head)->next = NULL;
second = *head;
general++;
continue
;
}
first = (PolicyList *)calloc(
1
, sizeof(recordPolicyificateList));
strncpy(first->PolicyID, (
char
*)PolicyID.arr, PolicyID.len);
strncpy(first->PolicyCode, (
char
*)PolicyCode.arr, PolicyCode.len);
strncpy(first->Type, (
char
*)Type.arr, Type.len);
strncpy(first->UsageType, (
char
*)UsageType.arr, UsageType.len);
first->next = NULL;
second->next = first;
second = second->next;
first = NULL;
general++;
}
EXEC SQL CLOSE ORA_CUR_SELECT;
if
(general >
0
)
return
(
0
);
return
(result);
}