일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- C/C++
- scala
- 명사 분석기
- Node.js
- 나의 취미
- Lift
- 베트남어
- ajax
- 디즈니씨
- php
- 나의 프로젝트
- 스킨 스쿠버
- iBatis
- nodejs express
- 주식이야기
- ejb
- 도커
- rss
- Cross
- 메일왕창보내는법
- 명사 추출기
- Eclipse
- 책이야기
- ror실행
- node.js web framework
- php thumbnail
- flex3
- 명사 뽑아내기
- docker
- express for node.js
- Today
- Total
nkdk의 세상
[PRO-C] 프로씨를 이용해서 심심해서 한번 만들어 봤습니다. ^^ 본문
// 아마 이 소스 하나면 전체적인 것이 이해가 전부 되리라 생각 되네요. 물론 빠진 부분이 있긴 한데
// 그 부분의 경우에는 스스로 공부하셔야 겠죠? 자~ 그럼 스타트~
#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#include"sqlca.h"
#include<string.h>
EXEC SQL BEGIN DECLARE SECTION;
char *conStr = "scott/tiger@java";
VARCHAR vEname[11];
VARCHAR vJob[10];
VARCHAR vHiredate[11];
int iEmpno, iSal, iMgr, iComm;
int iDeptno;
int iResult;
int iCnt = 0;
char ename[11];
char job[10];
char hiredate[11];
char sTempBuf[32];
short vEname_ind;
short vJob_ind;
short vHiredate_ind;
short iDeptno_ind;
short iEmpno_ind;
short iSal_ind;
short iMgr_ind;
short iComm_ind;
short iResult_ind;
EXEC SQL END DECLARE SECTION;
int bEname, bJob, bHiredate,bEmpno, bMgr, bSal, bComm, bDeptno;
int hostInit(void)
{
memset(&vEname, 0x00, sizeof(vEname));
memset(&vJob, 0x00, sizeof(vJob));
memset(&vHiredate, 0x00, sizeof(vHiredate));
memset(&sTempBuf, 0x00, sizeof(sTempBuf));
iMgr = 0; iEmpno = 0; iSal = 0; iComm = 0;
iResult = 0; iDeptno = 0; ename[11] = ""; job[10] = ""; hiredate[11] = "";
vEname_ind = 0; vJob_ind = 0; vHiredate_ind = 0; iMgr_ind = 0;
iEmpno_ind = 0; iSal_ind = 0; iComm_ind = 0; iResult_ind = 0; iDeptno_ind = 0;
bEname = 0; bJob = 0; bHiredate = 0; bEmpno = 0; bMgr = 0; bSal = 0; bComm = 0; bDeptno = 0;
return 0;
}
int updateQuery() {
hostInit();
iComm_ind = 0;
printf("Want Change NO : ");
scanf("%d", &iEmpno);
printf("Update data No %d\nname(s) job(s) mgr(i) hiredate(1900/05/10) sal(i) comm(i) deptno(i)\n", iEmpno);
scanf("%s %s %d %s %d %d %d", ename, job, &iMgr, hiredate, &iSal, &iComm, &iDeptno);
strcpy((char*)vEname.arr, ename);
strcpy((char*)vJob.arr, job);
strcpy((char*)vHiredate.arr, hiredate);
vJob.len = strlen(vJob.arr);
vEname.len = strlen(vEname.arr);
vHiredate.len = strlen(vHiredate.arr);
EXEC SQL
UPDATE EMP
SET
ENAME=:vEname:vEname_ind,
JOB=:vJob:vJob_ind,
MGR=:iMgr:iMgr_ind,
HIREDATE=:vHiredate:vHiredate_ind,
SAL = :iSal:iSal_ind,
COMM=:iComm:iComm_ind,
DEPTNO=:iDeptno:iDeptno_ind
WHERE EMPNO = :iEmpno;
EXEC SQL COMMIT WORK;
printf("No[%d] %s %s %d %s %d %d %d change Complete\n", iEmpno, ename, job, iMgr, hiredate, iSal, iComm, iDeptno);
hostInit();
}
int deleteQuery() {
hostInit();
iComm_ind = 0; /* indicator check point */
printf("Delete NO. Input : ");
scanf("%d", &iEmpno);
EXEC SQL DELETE FROM EMP WHERE EMPNO = :iEmpno;
EXEC SQL COMMIT WORK;
printf("No.[%d] delete success!!\n", iEmpno);
printf("Press Enter.....");
getch();
hostInit();
return 0;
SQL_ERROR_RTN:
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0x00;
printf("SQL_CODE=[%d] SQL_MESSAGE=[%s]\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
printf("Error : SQL ERROR !!\n");
return -1;
}
int insertQuery() {
hostInit();
iComm_ind = 0; /* indicator check point */
printf("input data\nempno(i) ename(s) job(s) mgr(i) hiredate(1900/05/10) sal(i) comm(i) deptno(i)\n");
scanf("%d %s %s %d %s %d %d %d", &iEmpno, ename, job, &iMgr, hiredate, &iSal, &iComm, &iDeptno);
strcpy((char*)vEname.arr, ename);
strcpy((char*)vJob.arr, job);
strcpy((char*)vHiredate.arr, hiredate);
vJob.len = strlen(vJob.arr);
vEname.len = strlen(vEname.arr);
vHiredate.len = strlen(vHiredate.arr);
EXEC SQL
INSERT INTO EMP(
EMPNO,
ENAME,
JOB,MGR, HIREDATE, SAL, COMM, DEPTNO)
VALUES(
:iEmpno:iEmpno_ind,
:vEname:vEname_ind,
:vJob:vJob_ind,
:iMgr:iMgr_ind,
TO_DATE(:vHiredate:vHiredate_ind, 'YYYY/MM/DD'),
:iSal:iSal_ind,
:iComm:iComm_ind,
:iDeptno:iDeptno_ind
);
EXEC SQL COMMIT WORK;
printf("%d %s %s %d %s %d %d %d insert success\n", iEmpno, ename, job, iMgr, hiredate, iSal, iComm, iDeptno);
hostInit();
}
int fileinQuery() {
FILE *fp;
fp=fopen("c:\\emp.data", "a+");
hostInit();
printf("パイルに入れたい名前は? ");
scanf("%s", sTempBuf);
EXEC SQL WHENEVER SQLERROR GOTO SQL_ERROR_RTN;
EXEC SQL DECLARE curEmp3 CURSOR FOR SELECT EMPNO, ENAME, JOB, MGR,
(TO_CHAR(HIREDATE, 'YYYY/MM/DD')) AS HIREDATE, SAL, COMM,
DEPTNO FROM EMP WHERE ENAME = :sTempBuf;
EXEC SQL OPEN curEmp3;
EXEC SQL WHENEVER NOT FOUND DO break;
for(;;)
{
EXEC SQL FETCH curEmp3 INTO
:iEmpno:iEmpno_ind,
:vEname:vEname_ind,
:vJob:vJob_ind,
:iMgr:iMgr_ind,
:vHiredate:vHiredate_ind,
:iSal:iSal_ind,
:iComm:iComm_ind,
:iDeptno:iDeptno_ind;
iCnt++;
if (iResult == 0)
{
printf("ENAME = [%s], JOB = [%s], SAL = [%d], COMM = [%d]\n",
vEname.arr,
vJob.arr,
iSal,
iComm);
fprintf(fp, "\n%d,%s,%s,%d,%d,%s,%d, %d, %d", iEmpno, vEname.arr, vJob.arr,
iMgr, iSal, vHiredate.arr, iSal, iComm, iDeptno);
}
}
if (iCnt==0) {
printf("データ無\n");
} else
printf("%d's dataをパイルに入れました。", iCnt);
iCnt = 0;
printf("\n ------ Enter Press -----\n");
getch();
fclose(fp);
return 0;
SQL_ERROR_RTN:
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0x00;
printf("SQL_CODE=[%d] SQL_MESSAGE=[%s]\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
printf("Error : SQL ERROR !!\n");
return -1;
}
int fileoutQuery() {
FILE *fp;
char file_data[500];
char tmp;
char tmpBuf[50];
int i,k;
memset(&file_data, 0x00, sizeof(file_data));
EXEC SQL WHENEVER SQLERROR GOTO SQL_ERROR_RTN;
fp = NULL;
printf("File名を入れて(EX -> c:\\\\nknk.data)");
scanf("%s", sTempBuf);
fp=fopen(sTempBuf, "r+");
memset(&tmpBuf, 0x00, sizeof(tmpBuf));
while(fgets(file_data, sizeof(file_data), fp))
{
k=0;
i=0;
hostInit();
while(file_data[i] != 10)
{
if(file_data[i] == ',')
{
if(bEmpno == 0)
{
if(strlen(tmpBuf) != 0)
iEmpno = atoi(tmpBuf);
else
iEmpno_ind = -1;
bEmpno = 1;
}
else if(bEname == 0)
{
if(strlen(tmpBuf) != 0)
{
strncpy(vEname.arr,tmpBuf,strlen(tmpBuf));
vEname.len = strlen(vEname.arr);
}
else
vEname_ind = -1;
bEname = 1;
}
else if(bJob == 0)
{
if(strlen(tmpBuf) != 0)
{
strncpy(vJob.arr,tmpBuf,strlen(tmpBuf));
vJob.len = strlen(vJob.arr);
}
else
vJob_ind = -1;
bJob = 1;
}
else if(bMgr == 0)
{
if(strlen(tmpBuf) != 0)
iMgr = atoi(tmpBuf);
else
iMgr_ind = -1;
bMgr = 1;
}
else if(bHiredate == 0)
{
if(strlen(tmpBuf) != 0)
{
strncpy(vHiredate.arr,tmpBuf,strlen(tmpBuf));
vHiredate.len = strlen(vHiredate.arr);
}
else
vHiredate_ind = -1;
bHiredate = 1;
}
else if(bSal == 0)
{
if(strlen(tmpBuf) != 0)
iSal = atoi(tmpBuf);
else
iSal_ind = -1;
bSal = 1;
}
else if(bComm == 0)
{
if(strlen(tmpBuf) != 0)
iComm = atoi(tmpBuf);
else
iComm_ind = -1;
bComm = 1;
}
memset(&tmpBuf, 0x00, strlen(tmpBuf));
k = 0;
}
else
{
tmp=file_data[i];
tmpBuf[k]=tmp;
k++;
}
i++;
if(file_data[i] == 10)
{
if(strlen(tmpBuf) != 0)
iDeptno = atoi(tmpBuf);
else
iDeptno_ind = -1;
break;
}
}
printf("%d %s %s %d %d %d %d %s 入力した。\n",iEmpno,vEname.arr ,vJob.arr ,iMgr ,iSal
,iComm ,iDeptno , vHiredate.arr);
EXEC SQL
INSERT INTO EMP(
EMPNO,
ENAME,
JOB,
MGR,
HIREDATE,
SAL,
COMM,
DEPTNO
)
VALUES(
:iEmpno:iEmpno_ind,
:vEname:vEname_ind,
:vJob:vJob_ind,
:iMgr:iMgr_ind,
TO_DATE( :vHiredate:vHiredate_ind, 'YYYY/MM/DD'),
:iSal:iSal_ind,
:iComm:iComm_ind,
:iDeptno:iDeptno_ind
);
}
EXEC SQL COMMIT WORK;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("insert success !!\n");
fclose(fp);
return 0;
SQL_ERROR_RTN:
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0x00;
printf("SQL_CODE=[%d] SQL_MESSAGE=[%s]\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
printf("Error : SQL ERROR !!\n");
return -1;
}
int selectQuery() {
EXEC SQL WHENEVER SQLERROR GOTO SQL_ERROR_RTN;
hostInit();
printf("探したいNAME : ");
scanf("%s", sTempBuf);
EXEC SQL DECLARE curEmp CURSOR FOR
SELECT
EMPNO,
ENAME,
JOB,
MGR,
(TO_CHAR(HIREDATE, 'YYYY/MM/DD')) AS HIREDATE, SAL, COMM, DEPTNO FROM EMP where ENAME = :sTempBuf;
EXEC SQL OPEN curEmp;
EXEC SQL WHENEVER NOT FOUND DO break;
iCnt=0;
printf("_NO_ ___NAME___ ___JOB___ _MGR_ ___DATE___ _SAL_ _COMM Dept_\n");
for(;;)
{
EXEC SQL FETCH curEmp INTO
:iEmpno:iEmpno_ind,
:vEname:vEname_ind,
:vJob:vJob_ind,
:iMgr:iMgr_ind,
:vHiredate:vHiredate_ind,
:iSal:iSal_ind,
:iComm:iComm_ind,
:iDeptno:iDeptno_ind;
iCnt++;
if (iResult == 0)
{
printf("%-4d %+10s %+9s %5d %+10s %5d %5d %5d\n",
iEmpno, vEname.arr,
vJob.arr,
iMgr,
vHiredate.arr,
iSal,
iComm,iDeptno);
}
}
if (iCnt==0) {
printf("no Data\n");
} else
printf("%d's data\n", iCnt);
iCnt = 0;
printf("\n ------ Enter Press -----\n");
getch();
EXEC SQL CLOSE curEmp;
return 0;
SQL_ERROR_RTN:
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0x00;
printf("SQL_CODE=[%d] SQL_MESSAGE=[%s]\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
printf("Error : SQL ERROR !!\n");
return -1;
}
int allselectQuery() {
EXEC SQL BEGIN DECLARE SECTION;
int swPoint = 0;
EXEC SQL END DECLARE SECTION;
hostInit();
EXEC SQL WHENEVER SQLERROR GOTO SQL_ERROR_RTN;
EXEC SQL DECLARE curEmp2 CURSOR FOR SELECT
EMPNO,
ENAME,
JOB,
MGR,
(TO_CHAR(HIREDATE, 'YYYY/MM/DD')) AS HIREDATE, SAL, COMM, DEPTNO FROM
EMP ORDER BY EMPNO;
EXEC SQL OPEN curEmp2;
EXEC SQL WHENEVER NOT FOUND DO break;
iCnt=0;
printf("_NO_ ___NAME___ ___JOB___ _MGR_ ___DATE___ _SAL_ _COMM Dept_\n");
for(;;) {
EXEC SQL FETCH curEmp2 INTO
:iEmpno:iEmpno_ind,
:vEname:vEname_ind,
:vJob:vJob_ind,
:iMgr:iMgr_ind,
:vHiredate:vHiredate_ind,
:iSal:iSal_ind,
:iComm:iComm_ind,
:iDeptno:iDeptno_ind;
iCnt++;
if (iResult == 0)
{
printf("%-4d %+10s %+9s %5d %+10s %5d %5d %5d\n",
iEmpno, vEname.arr,
vJob.arr,
iMgr,
vHiredate.arr,
iSal,
iComm,iDeptno);
}
hostInit();
swPoint++;
if(swPoint==23) {
printf("Press Enter --------");
getch();
swPoint = 0;
printf("\n_NO_ ___NAME___ ___JOB___ _MGR_ ___DATE___ _SAL_ _COMM Dept_\n");
}
}
printf("--------------------------------");
printf("\nTotal %d's data....\n", iCnt);
printf("---------- End data ------------\n");
iCnt=0;
getch();
system("cls");
EXEC SQL CLOSE curEmp2;
return 0;
SQL_ERROR_RTN:
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0x00;
printf("SQL_CODE=[%d] SQL_MESSAGE=[%s]\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
printf("Error : SQL ERROR !!\n");
return -1;
}
int main()
{
int cntcnt=0;
int cncncns=0;
EXEC SQL WHENEVER SQLERROR GOTO SQL_ERROR_RTN;
EXEC SQL CONNECT :conStr;
printf("Connection Success!!\n");
while(cntcnt != -1) {
printf("Pro-Sql machine :\n 1:select\n11:all select\n 2:insert\n 3:update\n 4:delete\n 5:Db data File in\n 6:file data db in\n(0:quit):");
scanf("%d", &cncncns);
switch(cncncns) {
case 0:
cntcnt=-1;
EXEC SQL COMMIT WORK RELEASE;
printf("\nDisconnected...\n");
break;
case 1:
selectQuery();
break;
case 11:
allselectQuery();
break;
case 2:
insertQuery();
break;
case 3:
updateQuery();
break;
case 4:
deleteQuery();
break;
case 5:
fileinQuery();
break;
case 6:
fileoutQuery();
break;
default:
printf("Not data");
break;
}
}
return 0;
SQL_ERROR_RTN:
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml]=0x00;
printf("SQL_CODE=[%d] SQL_MESSAGE=[%s]\n",
sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
printf("Error : SQL ERROR !!\n");
return -1;
}
// 정도가 되겠습니다. ^^ 이제 나도 pro - c 유저~ ^^