Oracle CGI for NCSA http server
since 27 January, 1999, last modified 9 June, 1999
ÀÌ ÇÁ·Î±×·¥Àº NCSA HTTP Server »ó¿¡¼ GET method CGI¸¦ ÀÌ¿ëÇÏ¿© ORACLE¿¡ Long raw typeÀ¸·Î ³ª´©¾î ÀúÀåµÈ Binary Á¤º¸¸¦ Àоî File·Î ¸¸µé¾î ÁÖ´Â ±â´ÉÀ» ÇÑ´Ù. ÀúÀåµÈ Çü½ÄÀº CDMÀÇ Long Field ÀúÀå¹æ½ÄÀ» ÂüÁ¶ ¹Ù¶÷.
/*======================== t02.pc A cgi program with Oracle interface It allows user input through GET method 1998/1/26 =========================*/ #include <string.h> #include <stdio.h> #include <sqlca.h> #ifndef NO_STDLIB_H #include <stdlib.h> #else char *getenv(); #endif #include <sqlcpr.h> typedef struct{ int len; char buf[50000]; } long_varraw; EXEC SQL type long_varraw is long varraw(50000); void browse_part(); void do_connect(); void sql_error(); main() { char input_str[12]; putenv("ORACLE_HOME=/home/oracle73/app/oracle/product/7.3.4"); putenv("ORACLE_SID=VPMDB"); printf("Content-type: text/html%c%c",10,10); printf("<HTML><BODY bgcolor=#FFFFFF>"); printf("<BR> %s",getenv("QUERY_STRING")); /* decode input string %20 -> space */ get_decode(getenv("QUERY_STRING"),input_str); if(input_str == NULL) { printf("<BR><FONT color=#FF0000>No part information to decode.</FONT>"); exit(1); } do_connect(); browse_part(input_str); EXEC SQL commit work release; } /*-------------------------------*/ /* BROWSE A PART */ void browse_part(input_part) char *input_part; { char s_part_no[12]; char s_dwg_no[12]; int recno; int seqno; char temp[4]; long_varraw lvr; short ind; FILE *fp; FILE *fp2; int num_write; int num_write2; int total = 0; /* Type equivalence key to the string external * datatype, so we don't have to null-terminate it. */ EXEC SQL VAR s_part_no is string(12); EXEC SQL VAR s_dwg_no is string(12); EXEC SQL whenever sqlerror do sql_error("browse_part"); EXEC SQL declare key_cursor cursor for SELECT a.s_part_no, b.s_dwg_no, d."$RECNO", d."$SEQNO", d."$DATA" INTO :s_part_no, :s_dwg_no, :recno, :seqno,:lvr :ind FROM parts.part_list a, parts.document b, parts."$EXT_LF" c, parts.LF00001 d WHERE a.s_part_no = :input_part AND a."$COID"=b."$COID" AND b."$COID"=c."$COID" AND b."$COMPID" = c."$COMPID_FATHER" AND d."$COID" = SUBSTR(c."$CUR_ACC_MET_DATA",55,16) AND d."$COMPID" = SUBSTR(c."$CUR_ACC_MET_DATA",71,16); EXEC SQL open key_cursor; printf("<BR>npart no dwg name rec seq"); printf("<BR>----------- --------- ------"); system("rm ../docs/output.hgl"); fp = fopen("../docs/output.hgl","a"); while (1) { EXEC SQL whenever not found do break; EXEC SQL fetch key_cursor into :s_part_no, :s_dwg_no, :recno, :seqno, :lvr :ind; if (seqno == 1) { num_write = fwrite(lvr.buf+4, sizeof(char), lvr.len-4, fp); printf("<BR> %s %s %d %d %d ", s_part_no,s_dwg_no, recno, seqno, lvr.len-4); } else { num_write = fwrite(lvr.buf, sizeof(char), lvr.len, fp); printf("<BR> %s %s %d %d %d ", s_part_no,s_dwg_no, recno, seqno, lvr.len); } total = total + num_write; fclose(fp); printf("<P><A HREF =/output.hgl >document file</A></P>"); } EXEC SQL whenever not found continue; EXEC SQL close key_cursor; } /*-------------------------------*/ /* DB CONNECTION */ void do_connect() { char *uid = "login/passwd"; EXEC SQL whenever sqlerror do sql_error("Connect"); EXEC SQL connect :uid; printf("<BR>Connected.\n"); } /* ------------------------------*/ /* GENERIC ERROR HANDLER */ void sql_error(routine) char *routine; { char message_buffer[512]; size_t buffer_size; size_t message_length; EXEC SQL WHENEVER SQLERROR CONTINUE; printf("<BR><FONT COLOR=#FF0000>Error while executing %s!</FONT>", routine); EXEC SQL ROLLBACK WORK RELEASE; exit(1); } /*--------------------------------- decode CIG QUERY_STRING (GET Method) -----------------------------------*/ void get_decode(input, output) char *input; char *output; { int i, j; j=0; FOR (i=0 ; i < strlen(input) ; i++) { if (input[i]=='%') { output[j]=' '; j=j++; i=i+2; /* %20 (HEXA code for space) */ } else { output[j]=input[i]; j=j++; } } output[j+1]='\0'; }
Knowledge and Engineering Databases © copyright Namchul Do, 1999