ÀÀ¿ëÇÁ·Î±×·¥ °³¹ß ¾È³»¼­

¿¹: ÆÄÀÏ·Î ¹®¼­ ¹ßÃé

ÀÌ ÇÁ·Î±×·¥ ¿¹´Â CLOB ¿ä¼Ò°¡ Å×À̺í·ÎºÎÅÍ ¿ÜºÎ ÆÄÀÏ·Î ¼ö½ÅµÉ ¼ö ÀÖ´Â ¹æ¹ýÀ» º¸¿© ÁÝ´Ï´Ù.

»ùÇà LOBFILE ÇÁ·Î±×·¥ ÀÛ¾÷ ¹æ¹ý

  1. È£½ºÆ® º¯¼ö Á¤ÀÇ. BEGIN DECLARE SECTION ¹× END DECLARE SECTION¹®Àº È£½ºÆ® º¯¼ö ¼±¾ðÀ» ºÐ¸®ÇÕ´Ï´Ù. È£½ºÆ® º¯¼ö´Â SQL¹®¿¡¼­ ÂüÁ¶µÉ ¶§ ÄÝ·Ð(:)À¸·Î ½ÃÀ۵˴ϴÙ. CLOB FILE REFERENCE È£½ºÆ® º¯¼ö°¡ ¼±¾ðµË´Ï´Ù.
  2. CLOB FILE REFERENCE È£½ºÆ® º¯¼ö°¡ ¼³Á¤µË´Ï´Ù. FILE REFERENCEÀÇ ¼Ó¼ºÀÌ ¼³Á¤µË´Ï´Ù. ¼±¾ðµÈ Àüü °æ·Î°¡ ¾ø´Â ÆÄÀÏ À̸§ÀÌ ±âº»°ªÀ¸·Î ÇöÀç ÀÛ¾÷ µð·ºÅ丮¿¡ ³õ¿© Áý´Ï´Ù.
  3. CLOB FILE REFERENCE È£½ºÆ® º¯¼ö·Î ¼±ÅÃ. Àç°³ ÇʵåÀÇ µ¥ÀÌÅʹ ȣ½ºÆ® º¯¼ö¿¡ ÀÇÇØ ÂüÁ¶µÇ´Â ÆÄÀÏ À̸§À¸·Î ¼±Åõ˴ϴÙ.

CHECKERR ¸ÅÅ©·Î/ÇÔ¼ö´Â ¿À·ù üũ À¯Æ¿¸®Æ¼ÀÔ´Ï´Ù. ÀÌ ¿À·ù üũ À¯Æ¿¸®Æ¼ÀÇ À§Ä¡´Â »ç¿ëµÈ ÇÁ·Î±×·¡¹Ö ¾ð¾î¿¡ µû¶ó ´Þ¶óÁú ¼ö ÀÖ½À´Ï´Ù.

C
DB2 API¸¦ È£ÃâÇÏ´Â C ÇÁ·Î±×·¥¿¡ ´ëÇØ¼­´Â utilapi.c¿¡¼­ sqlInfoPrint ÇÔ¼ö´Â utilapi.h¿¡¼­ API_SQL_CHECK·Î¼­ÂüÁ¶µË´Ï´Ù. C embedded SQL ÇÁ·Î±×·¥¿¡ ´ëÇØ¼­´Â utilemb.sqc¿¡¼­ sqlInfoPrint ÇÔ¼ö´Â utilemb.h¿¡¼­ EMB_SQL_CHECK·Î¼­ ÂüÁ¶µË´Ï´Ù.

COBOL
CHECKERRÀº checkerr.cbl¶ó°í ÇÏ´Â ¿ÜºÎ ÇÁ·Î±×·¥ÀÔ´Ï´Ù.

ÀÌ ¿À·ù üũ À¯Æ¿¸®Æ¼¿¡ ´ëÇÑ ¼Ò½º Äڵ忡 ´ëÇØ¼­´Â ¿¹Á¦ ÇÁ·Î±×·¥¿¡¼­ GET ERROR MESSAGE »ç¿ëÀÇ ³»¿ëÀ» ÂüÁ¶ÇϽʽÿÀ.

C ¿¹: LOBFILE.SQC

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sql.h>
#include "utilemb.h"
 
EXEC SQL INCLUDE SQLCA;
 
int main(int argc, char *argv[]) {
 
   EXEC SQL BEGIN DECLARE SECTION; (1)
      SQL TYPE IS CLOB_FILE resume;
      short lobind;
      char userid[9];
      char passwd[19];
   EXEC SQL END DECLARE SECTION;
 
   printf( "Sample C program: LOBFILE\n" );
 
   if (argc == 1) {
      EXEC SQL CONNECT TO sample;
	  EMB_SQL_CHECK("CONNECT TO SAMPLE");
   }
   else if (argc == 3) {
      strcpy (userid, argv[1]);
      strcpy (passwd, argv[2]);
      EXEC SQL CONNECT TO sample USER :userid USING :passwd;
      EMB_SQL_CHECK("CONNECT TO SAMPLE");
   }
   else {
      printf ("\nUSAGE: lobfile [userid passwd]\n\n");
      return 1;
   } /* endif */
   
   strcpy (resume.name, "RESUME.TXT");  (2)
   resume.name_length = strlen("RESUME.TXT");
   resume.file_options = SQL_FILE_OVERWRITE;
 
   EXEC SQL SELECT resume INTO :resume :lobind FROM emp_resume  (3)
      WHERE resume_format='ascii' AND empno='000130';
 
   if (lobind < 0) {
      printf ("NULL LOB indicated \n");
   } else {
      printf ("Resume for EMPNO 000130 is in file : RESUME.TXT\n");
   } /* endif */
 
   EXEC SQL CONNECT RESET;
   EMB_SQL_CHECK("CONNECT RESET");
   return 0;
}
/* end of program : LOBFILE.SQC */

COBOL ¿¹: LOBFILE.SQB

       Identification Division.
       Program-ID. "lobfile".
 
       Data Division.
       Working-Storage Section.
 
           copy "sqlenv.cbl".
           copy "sql.cbl".
           copy "sqlca.cbl".
 
           EXEC SQL BEGIN DECLARE SECTION END-EXEC. (1)
       01 userid            pic x(8).
       01 passwd.
         49 passwd-length   pic s9(4) comp-5 value 0.
         49 passwd-name     pic x(18).
       01 resume            USAGE IS SQL TYPE IS CLOB-FILE.
       01 lobind            pic s9(4) comp-5.
           EXEC SQL END DECLARE SECTION END-EXEC.
 
       77 errloc          pic x(80).
 
       Procedure Division.
       Main Section.
           display "Sample COBOL program: LOBFILE".
 
      * Get database connection information.
           display "Enter your user id (default none): "
                with no advancing.
           accept userid.
 
           if userid = spaces
             EXEC SQL CONNECT TO sample END-EXEC
           else
             display "Enter your password : " with no advancing
             accept passwd-name.
 
      * Passwords in a CONNECT statement must be entered in a VARCHAR
      * format with the length of the input string.
           inspect passwd-name tallying passwd-length for characters
              before initial " ".
 
           EXEC SQL CONNECT TO sample USER :userid USING :passwd
               END-EXEC.
           move "CONNECT TO" to errloc.
           call "checkerr" using SQLCA errloc.
 
           move "RESUME.TXT" to resume-NAME. (2)
           move 10 to resume-NAME-LENGTH.
           move SQL-FILE-OVERWRITE to resume-FILE-OPTIONS.
 
           EXEC SQL SELECT resume INTO :resume :lobind  (3)
                    FROM emp_resume
                    WHERE resume_format = 'ascii'
                    AND empno = '000130' END-EXEC.
           if lobind less than 0 go to NULL-LOB-indicated.
 
           display "Resume for EMPNO 000130 is in file : RESUME.TXT".
           go to End-Main.
 
       NULL-LOB-indicated.
           display "NULL LOB indicated".
 
       End-Main.
           EXEC SQL CONNECT RESET END-EXEC.
           move "CONNECT RESET" to errloc.
           call "checkerr" using SQLCA errloc.
       End-Prog.
                  stop run.


[ ÆäÀÌÁöÀÇ ¸Ç À§ | ÀÌÀü ÆäÀÌÁö | ´ÙÀ½ ÆäÀÌÁö | ¸ñÂ÷ | »öÀÎ ]