'공부/ProC'에 해당되는 글 1건
- 2012.02.22 :: [Pro C] 샘플 프로그램 (솔라리스 9 오라클 9r2 환경)
공부/ProC
2012. 2. 22. 09:40
Makefile
############################################################################################################
TARGET = zipcode
CC = gcc
PROC = proc
LIB = -L$(ORACLE_HOME)/lib -lclntsh
MYINC = include/
PROCINC = include=$(ORACLE_HOME)/precomp/public/ include=$(ORACLE_HOME)/rdbms/demo/ \
include=$(ORACLE_HOME)/rdbms/public/ \
include=$(ORACLE_HOME)/network/public/
CINC = -I$(ORACLE_HOME)/precomp/public/ -I$(ORACLE_HOME)/rdbms/demo/ \
-I$(ORACLE_HOME)/rdbms/public/ -I$(ORACLE_HOME)/network/public/
ORA_OPT = PARSE=NONE RELEASE_CURSOR=YES MODE=ANSI
CC_OPT =
OBJECT = zipcode.o
ORA_GARBAGE = *.dcl *.cod *.cud *.lis
######## implicit rules
.SUFFIXES: .pc .c
.pc.c:
$(PROC) $* INCLUDE=$(MYINC) $(PROCINC) $(ORA_OPT)
.c.o:
$(CC) -m64 -c -o $*.o $*.c -I $(MYINC) $(CINC)
####### build rules
all: $(TARGET)
$(TARGET): $(OBJECT)
$(CC) -m64 -o $(TARGET) $(OBJECT) $(LIB)
zipcode.c: zipcode.pc
zipcode.o: zipcode.c
clean:
rm -f $(TARGET) $(OBJECT) $(ORA_GARBAGE)
#################################################################################
zipcode.pc
#################################################################################
컴파일 방법
다 설정 해놔서 make 치면 되지만..
컴파일 구조는 아래와 같다.
#################################################################################
zipcode.pc
#################################################################################
#include <stdio.h>
#include <unistd.h>
/* SQLCA ?\201 ?+??CN?U */
EXEC SQL INCLUDE SQLCA;
int main(int argc, char **argv)
{
/* ?+???I */
EXEC SQL BEGIN DECLARE SECTION;
int count = 0;
char userid[40]= "scott/tiger";
EXEC SQL END DECLARE SECTION;
/* DB ?\203\234a */
EXEC SQL CONNECT :userid;
/* ??\236? A??R */
if (sqlca.sqlcode < 0)
{
printf("%s\n", sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK RELEASE;
exit(0);
}
/* Ao?R */
EXEC SQL SELECT count(*)
INTO: count
FROM zipcode;
/* Ao?R \234a\234u?? ?eCN ??\236?A??R */
if (sqlca.sqlcode != 0)
{
EXEC SQL COMMIT WORK RELEASE;
return 0;
}
printf("?i?iAO?O \336?AIA? : %d \234?\n", count);
/* DB ?\203\234a A?\236a */
EXEC SQL COMMIT WORK RELEASE;
}
################################################################################# 컴파일 방법
다 설정 해놔서 make 치면 되지만..
컴파일 구조는 아래와 같다.
+--------------+
| Proc Program | SQL 문을 포함
| .pc |
+--------------+
↓
+--------------+
| 오라클 |
| 선행컴파일러 |
| proc |
+--------------+
↓
+--------------+
| 해석된 | 기존의 SQL 문은 library 를
| .c 쏘쓰코드 | 직접 호출하는 문으로 변경됨
+--------------+
↓
+--------------+
| C 컴파일러 |
+--------------+
↓
+--------------+
| Object 파일 |
+--------------+
↓
+--------------+
| Linker | 오라클 라이브러리가 링크됨
+--------------+
↓
+--------------+
| 실행파일 |
+--------------+