내블로그
링크추가

jjeong블로그를
링크에 추가하시겠습니까?

취소

[Cubrid] cci example code

jjeong | 2012/05/22 00:33 | 개발일반 앱으로 보기

[Source Code]

// http://www.cubrid.org/manual/841/ko/CCI%20API
// http://www.cubrid.org/manual/841/ko/C%20Type%20Definition
#include <stdio.h>
#include <cas_cci.h>

int main (int argc, char *argv[]) {

    int con = 0, req = 0, rowCount = 0, res;

    T_CCI_ERROR error;
    T_CCI_QUERY_RESULT *queryResult;

    printf("Program started!\n");

    if ((con=cci_connect("SERVER_IP", SERVER_PORT, "DB_NAME", "USER", "PASSWORD"))<0) {
        printf( "%s(%d): cci_connect fail\n", __FILE__, __LINE__);
        return -1;
    }

    if ((req=cci_prepare(con, "select name from demodb where id=1", 0,&error))<0) {
        printf( "%s(%d): cci_prepare fail(%d)\n", __FILE__, __LINE__,error.err_code);
        goto handle_error;
    }

    printf("Prepare ok!(%d)\n",req);
    printf("========================================\n");

    if ((res=cci_execute(req, 0, 0, &error))<0) {
        printf( "%s(%d): cci_execute fail(%d)\n", __FILE__, __LINE__,error.err_code);
        goto handle_error;
    }

    if ((res=cci_execute_result(req, &queryResult, &error))<0) {
        printf( "%s(%d): cci_execute_result fail(%d)\n", __FILE__, __LINE__,error.err_code);
        goto handle_error;
    }

    rowCount = CCI_QUERY_RESULT_RESULT(queryResult, 1);

    if ( rowCount > 0 ) {
        printf("This is virus(%d).\n", rowCount);
    } else {
        printf("This is clean(%d).\n", rowCount);
    }

    if ((res=cci_close_req_handle(req))<0) {
           printf( "%s(%d): cci_close_req_handle fail", __FILE__, __LINE__);
           goto handle_error;
    }

    if ((res=cci_disconnect(con, &error))<0) {
          printf( "%s(%d): cci_disconnect fail(%d)", __FILE__, __LINE__,error.err_code);
          goto handle_error;
    }

    printf("Program ended!\n");

    return 0;

handle_error:

    if (req > 0) cci_close_req_handle(req);
    if (con > 0) cci_disconnect(con, &error);

    printf("Program failed!\n");

    return -1;
}


[Build]

- 위치

mkdir -p /home/jjeong/workspace/cubrid

cd  /home/jjeong/workspace/cubrid

- prerequisite

http://www.cubrid.org/manual/841/en/CCI%20API

CUBRID-CCI-Linux-8.4.0.2027.tar.gz

tar -xvzf CUBRID-CCI-Linux-8.4.0.2027.tar.gz

ln -s cubrid-cci-8.4.0.2027 libcubrid

- gcc

gcc cubrildMini.c ./libcubrid/lib/libcascci.a -I./libcubrid/include -lpthread -lnsl -o cubridMini


ⓒ Daum Kakao Corp.

검색어 입력폼