본문 바로가기
IT/DB

Pro-C 커서 패치 예제

by Spring Up!! 2021. 11. 30.
반응형


#define SQL_CD sqlca.sqlcode;
#define SQLCA_STORAGE_CLASS extern
EXEC SQL INCLUDE sqlca;

void CMyProc::PrepareCursor()
{
EXEC SQL BEGIN DECLARE SECTION;
char strSelect[1024];
EXEC SQL BEGIN DECLARE SECTION;

memset(strSelect, 0x00, sizeof(strSelect));
sprintf(strSelect,
" SELECT ₩n"
" SEQID, CODE ₩n"
" FROM mytable SUBPARTITION(SP%d) ₩n"
" WHERE STATE='1' ₩n", 1);

try
{
EXEC SQL PREPARE PREF_TB_READ FROM :strSelect;
if (SQL_CD != 0)
throw SQL_CD;

EXEC SQL DECLARE mycursor CURSOR FOR PREF_TB_READ;
if (SQL_CD != 0)
throw SQL_CD;
}
catch (int &ex)
{
;
}
}


void CMyProc::OpenCursor()
{
    EXEC SQL OPEN mycursor;

     if (SQL_CD != 0)
         throw SQL_CD;
     }
}

int CMyProc::FetchCursor()
{
    EXEC SQL BEGIN DECLARE SECTION;
         struct  stData stDataDB;
    EXEC SQL BEGIN DECLARE SECTION;

    EXEC SQL FETCH mycursor INTO :stDataDB;

    if (1403 == SQL_CD) // No data found
    {
         return SQL_CD;
    }
    else if  (-1001 == SQL_CD) // invalid cursor
    {
         return SQL_CD;
    }
    else (0 == SQL_CD) // success
    {
         // todo : trim space & treat data

    }




     if (SQL_CD != 0)
         throw SQL_CD;
     }
}




반응형

댓글