makefile文件也要相应的增加
/* -------------------------------------------------------
* myproc.pc
* Author: Youbin Wang
* Rem : 2009.04.28 create the file
* ------------------------------------------------------- */
#include
#include
#include
#include
#include
#include
#include
#include
#include "mystructs.h"
EXEC SQL BEGIN DECLARE SECTION;
#define UNAME_LEN 20
#define PWD_LEN 40
VARCHAR username[UNAME_LEN];
VARCHAR password[PWD_LEN];
/* host structure for output value */
struct
{
VARCHAR emp_name[UNAME_LEN];
float salary;
float commission;
}emprec;
/* indicator structure to correspond to host output struct */
struct
{
short emp_name_ind;
short sal_ind;
short comm_ind;
}emprec_ind;
int emp_number;
int total_queried;
int i_num;
EXEC SQL END DECLARE SECTION;
/* Sql communications area.
you car user #include or EXEC SQL INCLUDE.*/
#include
int sql_error(msg)
char *msg;
{
char err_msg[128];
size_t buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\n%s\n", msg);
buf_len = sizeof(err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s\n", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(EXIT_FAILURE);
}
int srv_to_proc(int input,int s_socket)
{
char temp_char[32];
/* connect to ORACLE */
strncpy((char*)username.arr,"SCOTT",UNAME_LEN);
username.len =
(unsigned short)strlen((char*)username.arr);
strncpy((char*)password.arr,"TIGER",PWD_LEN);
password.len =
(unsigned short)strlen((char*)password.arr);
EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("\nConnected to ORACLE as user:%s \n",username.arr);
total_queried = 0;
EXEC SQL WHENEVER NOT FOUND GOTO notfound;
printf("\n\nemployee Salary Commission\n");
printf("-------- ------- ----------\n");
i_num=input;
EXEC SQL SELECT ename, sal, comm
INTO :emprec INDICATOR :emprec_ind
FROM EMP WHERE rownum = :i_num ;
emprec.emp_name.arr[emprec.emp_name.len] = '\0';
printf("%s %7.2f ",
emprec.emp_name.arr, emprec.salary);
if (-1 == emprec_ind.comm_ind)
printf("NULL\n");
else
printf("%7.2f\n", emprec.commission);
send(s_socket,(char *)&emprec, sizeof(emprec), 0);
notfound:
printf("\nNot data left - try again.\n");
printf("\n\nTotal rows returned was %d.\n", total_queried);
printf("\n bye bye. \n\n\n");
//Disconnect from ORACLE
EXEC SQL ROLLBACK WORK RELEASE;
exit(EXIT_SUCCESS);
}
No comments:
Post a Comment