Background Image

FORUM

조회 수 131 추천 수 0 댓글 4
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄


* 질문 등록 시 다음의 내용을 꼭 기입하여 주세요.

OS
Linux 64bit
CUBRID Ver.
11.2
CUBRID TOOL Ver.
[도움말]-[버전정보] 확인
응용 환경(API)
cci c


* CUBRID 응용 오류, SQL 오류 또는 SQL 튜닝 관련된 문의는 반드시 다음의 내용을 추가해 주세요. 비밀글이나 비밀 댓글도 가능합니다.
* 저희가 상황을 이해하고, 재현이 가능해야 알 수 있는 문제들이 많습니다. 가능한 정보/정황들을 부탁합니다.

 

에러 내용 및 재현 방법 재현 가능한 Source와 SQL
관련 테이블(인덱스, 키정보 포함) 정보 CUBRID 홈 디렉토리 아래 log 디렉토리 압축


-------------- 아래에 질문 사항을 기입해 주세요. ------------------------------------------------------------------------
db link로 원격테이블 조회시 조건문에 바인딩변수가 필요할듯 한데 어떻게 구현해야할지 샘플 좀 부탁드립니다.

cubrid manual에서 제공하는 샘플에 쿼리문만 수정하여 테스트 해보는데 바인딩시 오류가 발생하더라구요.

수고하세요.

 

// Example to execute a query with a bind variable
// In Linux: gcc -o cci_bind cci_bind.c -m64 -I${CUBRID}/cci/include -lnsl ${CUBRID}/cci/lib/libcascci.so -lpthread

#include <stdio.h>
#include <string.h>
#include "cas_cci.h"
#define BUFSIZE  (1024)

int
main (void)
{
    int con = 0, req = 0, col_count = 0, i, ind;
    int error;
    char *data;
    T_CCI_ERROR cci_error;
    T_CCI_COL_INFO *col_info;
    T_CCI_CUBRID_STMT stmt_type;
//    char *query = "select * from nation where name = ?";
    char *query = "SELECT * FROM dblink (remote_srv, 'select code,name,continent,capital from public.nation where name = ?') AS t(code CHAR(3), name VARCHAR(40), continent VARCHAR(10), capital VARCHAR(30))";
    char namebuf[128];

    //getting a connection handle for a connection with a server
    con = cci_connect ("localhost", 33000, "demodb", "dba", "");
    if (con < 0)
    {
        printf ("cannot connect to database\n");
        return 1;
    }

    //preparing the SQL statement
    req = cci_prepare (con, query, 0, &cci_error);
    if (req < 0)
    {
        printf ("prepare error: %d, %s\n", cci_error.err_code,
              cci_error.err_msg);
        goto handle_error;
    }

    //Binding date into a value
    // 여기서 오류발생함
    strcpy (namebuf, "Korea");
    error =
    cci_bind_param (req, 1, CCI_A_TYPE_STR, namebuf, CCI_U_TYPE_STRING,
                    CCI_BIND_PTR);
    if (error < 0)
    {
        printf ("bind_param error: %d ", error);
        goto handle_error;
    }

    //getting column information when the prepared statement is the SELECT query
    col_info = cci_get_result_info (req, &stmt_type, &col_count);
    if (col_info == NULL)
    {
        printf ("get_result_info error: %d, %s\n", cci_error.err_code,
              cci_error.err_msg);
        goto handle_error;
    }

    //Executing the prepared SQL statement
    error = cci_execute (req, 0, 0, &cci_error);
    if (error < 0)
    {
        printf ("execute error: %d, %s\n", cci_error.err_code,
              cci_error.err_msg);
        goto handle_error;
    }

    //Executing the prepared SQL statement
    error = cci_execute (req, 0, 0, &cci_error);
    if (error < 0)
    {
        printf ("execute error: %d, %s\n", cci_error.err_code,
              cci_error.err_msg);
        goto handle_error;
    }

    while (1)
    {

        //Moving the cursor to access a specific tuple of results
        error = cci_cursor (req, 1, CCI_CURSOR_CURRENT, &cci_error);
        if (error == CCI_ER_NO_MORE_DATA)
        {
            break;
        }
        if (error < 0)
        {
            printf ("cursor error: %d, %s\n", cci_error.err_code,
                  cci_error.err_msg);
            goto handle_error;
        }

        //Fetching the query result into a client buffer
        error = cci_fetch (req, &cci_error);
        if (error < 0)
        {
            printf ("fetch error: %d, %s\n", cci_error.err_code,
                  cci_error.err_msg);
            goto handle_error;
        }
        for (i = 1; i <= col_count; i++)
        {

            //Getting data from the fetched result
            error = cci_get_data (req, i, CCI_A_TYPE_STR, &data, &ind);
            if (error < 0)
            {
                printf ("get_data error: %d, %d\n", error, i);
                goto handle_error;
            }
            if (ind == -1)
            {
                printf ("NULL\t");
            }
            else
            {
                printf ("%s\t|", data);
            }
        }
            printf ("\n");
    }

    //Closing the request handle
    error = cci_close_req_handle (req);
    if (error < 0)
    {
        printf ("close_req_handle error: %d, %s\n", cci_error.err_code,
                cci_error.err_msg);
        goto handle_error;
    }

    //Disconnecting with the server
    error = cci_disconnect (con, &cci_error);
    if (error < 0)
    {
        printf ("error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
        goto handle_error;
    }

    return 0;

handle_error:
    if (req > 0)
        cci_close_req_handle (req);
    if (con > 0)
        cci_disconnect (con, &cci_error);
    return 1;
}

 

  • ?
    오명환 2023.05.18 15:21
    dblink안에서 사용하는 remote 질의 내부에는 binding 변수(?)를 사용할 수 업습니다.
    대신, 다음과 같이 dblink를 사용한 질의에 조건절로 변경해서 사용하시면 됩니다.

    - 오류나는 질의
    SELECT * FROM dblink (remote_srv, 'select code,name,continent,capital from public.nation where name = ?') AS t(code CHAR(3), name VARCHAR(40), continent VARCHAR(10), capital VARCHAR(30))

    - 수정 질의
    SELECT * FROM dblink (remote_srv, 'select code,name,continent,capital from public.nation') AS t(code CHAR(3), name VARCHAR(40), continent VARCHAR(10), capital VARCHAR(30)) where name = ?
  • ?
    jjune1206 2023.05.18 16:18
    바인딩이 이런 방식뿐이 안된다면...
    원격테이블에서 레코드를 FULL로 획득해서 조건이 적용되는것처럼 보이는데
    인덱스는 무시될테고, 퍼포먼스에 영향이 있겠네요?
  • ?
    주영진 2023.05.18 17:08

    dblink (...) 외부에 있는 조건이라도 dblink (...) 에 해당하는 조건에 대해서는 조건을 Push 한 쿼리가 원격지에서 실행됩니다.

    select *
    from dblink (remote_srv, 'select code,name,continent,capital from public.nation') as t(code char(3), name varchar(40), continent varchar(10), capital varchar(30))
    where name = ?

    이 쿼리는 원격지에서 실행 될 때 'select code,name,continent,capital from public.nation where name = ?' 으로 쿼리가 만들어져서 실행됩니다.
    ? 에는 바인드한 값이 채워진 상태로 실행됩니다.

  • ?
    jjune1206 2023.05.18 17:52
    확인 감사합니다.

  1. CUBRID 사용자를 위한 DBeaver 도구 출시 안내

    Date2024.04.23 Byadmin Views49
    read more
  2. SQLGate for CUBRID 영구 무료 라이선스 제공

    Date2020.04.09 Byadmin Views4458
    read more
  3. 운영db 접근이 되지 않아 문의 드립니다

    Date2023.07.20 By찬이 Views99
    Read More
  4. 홈경로 databases.txt 질문드립니다

    Date2023.07.17 By큐브리드드 Views92
    Read More
  5. Cubrid admin 접속 제한 문의드립니다.

    Date2023.07.13 By데굴v Views118
    Read More
  6. 특정단어 삭제

    Date2023.07.13 Byddmmdd Views165
    Read More
  7. error while loading shared libraries: libncurses.so.5 에러 문의 드립니다.

    Date2023.07.10 Bykikiki767 Views1471
    Read More
  8. 다운로드페이지에 CUBRIDManager 11.x windows-x64.exe 는 없는데 .. 다운로드 할 수 있을까요?

    Date2023.07.05 By최라이거 Views303
    Read More
  9. db_class에서 테이블 목록 조회시

    Date2023.07.03 Bycncn Views294
    Read More
  10. 조회쿼리 시간단축

    Date2023.06.30 Byleeee Views98
    Read More
  11. CUBRID 8.4.4 -> 11.0.3 로 업그레이드 시 발생할 문제가 있을까요?

    Date2023.06.29 BySDDC사업개발자 Views89
    Read More
  12. CUBRID to Tibero DBLink지원 가능한지 알고싶습니다.

    Date2023.06.28 By공공기관에서사용중1 Views138
    Read More
  13. ELO타입이 무엇인가요?

    Date2023.06.27 Bysobubble Views116
    Read More
  14. 백업파일 받았는데 복구하는 방법을 모르겠습니다.

    Date2023.06.20 ByGgyak Views186
    Read More
  15. UTF8 한글이 깨짐

    Date2023.06.19 Byyonggi Views271
    Read More
  16. 저장 프로스저에 있는 함수 상세보기 문의입니다.

    Date2023.06.12 By대출인생30년 Views82
    Read More
  17. MERGE INTO 속도 개선 문의

    Date2023.06.12 Byleeee Views129
    Read More
  18. NX_transcation

    Date2023.06.12 Byyoo Views79
    Read More
  19. cubrid cursor.close() 에러 관련질문

    Date2023.06.08 By힘내자화이팅 Views186
    Read More
  20. merge 쿼리 속도개선

    Date2023.06.08 Byleeee Views109
    Read More
  21. 브로커(CAS)수 질문드립니다!

    Date2023.06.05 By요시니 Views152
    Read More
  22. 데이터 이관 문의입니다.

    Date2023.05.30 Bykipo0821 Views129
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 200 Next
/ 200

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales