Background Image
응용개발
2008.11.21 17:31

embedded sql 에서 char 사용시 주의 사항

조회 수 19009 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
embedded sql 에서 host variable 을 사용할 경우 char type 에 대하여 where 절에 사용시 주의하여야 합니다.
비교하고자 하는 대상의 정확한 length(스키마상의 length)를 알아내고 host variable 상의 실제 데이터의 length(strlen) 이 비교대상의 스키마상의 length 보다 작은 경우 나머지는 공백으로 채워주어야만 정확한 비교 결과를 만들어 냅니다.
즉, name char(10) 일 경우 where name = :name 에서 strcpy(name, ‘1234’) 는 결과가 없지만 strcpy(name, ‘1234      ‘) 는 결과가 나올 수 있게 됩니다.

아래는 테스트를 위한 SQL 입니다.
create class t ( name char(10), addr varchar(10))
insert into t values(''''1234'''', ''''1234'''')
name                  addr
============================================
''''1234      ''''          ''''1234''''

아래는 예제 C source 입니다.
#include <stdio.h>

main()
{
        exec sql begin declare section;
                char    c[10];
                VARCHAR vc[10];
                char    rtn[10];
        exec sql end declare section;

        uci_startup("test");
        exec sql connect ''''demodb'''';

        strcpy(c, "1234");
        exec sql declare c0 cursor for
                select name from t where name = :c;
        exec sql open c0;
        exec sql fetch c0 into :rtn;
        printf("0. where char=(%s) : result count=%dn", c, SQLERRD[2]);
        exec sql close c0;

        strcpy(c, "1234      ");
        exec sql declare c1 cursor for
                select name from t where name = :c;
        exec sql open c1;
        exec sql fetch c1 into :rtn;
        printf("1. where char=(%s) : result count=%dn", c, SQLERRD[2]);
        exec sqlx close c1;

        strcpy(c, "12");
        exec sqlx declare c2 cursor for
                select name from t where substr(name,1,2) = :c;
        exec sqlx open c2;
        exec sqlx fetch c2 into :rtn;
        printf("2. where substr(char,1,2)=(%s) : result count=%dn", c, SQLERRD[2]);
        exec sql close c2;

        strcpy(c, "12        ");
        exec sql declare c3 cursor for
                select name from t where substr(name,1,2) = :c;
        exec sql open c3;
        exec sql fetch c3 into :rtn;
        printf("3. where substr(char,1,2)=(%s) : result count=%dn", c, SQLERRD[2]);
        exec sql close c3;

        strcpy(vc.array, "1234");
        exec sql declare c4 cursor for
                select name from t where addr = :vc;
        exec sql open c4;
        exec sql fetch c4 into :rtn;
        printf("4. (NO vc.length) where varchar=(%s) : result count=%dn", vc.array, SQLERRD[2]);
        exec sql close c4;

        strcpy(vc.array, "1234");
        vc.length = strlen(vc.array);
        exec sql declare c5 cursor for
                select name from t where addr = :vc;
        exec sql open c5;
        exec sql fetch c5 into :rtn;
        printf("5. where varchar=(%s) : result count=%dn", vc.array, SQLERRD[2]);
        exec sql close c5;

        strcpy(vc.array, "1234      ");
        vc.length = strlen(vc.array);
        exec sql declare c6 cursor for
                select name from t where addr = :vc;
        exec sql open c6;
        exec sql fetch c6 into :rtn;
        printf("6. where varchar=(%s) : result count=%dn", vc.array, SQLERRD[2]);
        exec sql close c6;

        strcpy(vc.array, "12");
        exec sql declare c7 cursor for
                select name from t where substr(addr,1,2) = :vc;
        exec sql open c7;
        exec sql fetch c7 into :rtn;
        printf("7. where substr(varchar,1,2)=(%s) : result count=%dn", vc.array, SQLERRD[2]);
        exec sql close c7;

        exec sql disconnect;
}


아래는 실행결과입니다.
0. where char=(1234) : result count=0
1. where char=(1234      ) : result count=1
2. where substr(char,1,2)=(12) : result count=0
3. where substr(char,1,2)=(12        ) : result count=1
4. (NO vc.length) where varchar=(1234) : result count=1
5. where varchar=(1234) : result count=1
6. where varchar=(1234      ) : result count=1
7. where substr(varchar,1,2)=(12) : result count=1

  1. function based index 대체 방법

    Date2010.07.01 Category질의작성 By남재우 Views13420
    Read More
  2. embedded sql 에서 char 사용시 주의 사항

    Date2008.11.21 Category응용개발 Byadmin Views19009
    Read More
  3. cubrid_service.exe 가 CPU 를 지속적으로 일정부분 점유하는 경우

    Date2010.01.01 Category운영관리 By남재우 Views13030
    Read More
  4. cubrid_fetch_all() php 함수로 만들어 사용하기

    Date2009.06.30 Category응용개발 By시난 Views18619
    Read More
  5. cubrid: error while loading shared libraries 에러가 발생했을 경우 대처

    Date2009.05.19 Category기타 By웁쓰 Views22441
    Read More
  6. cubrid.conf파일 적용의 우선 순위와 HOST적용 우선 순위

    Date2009.11.14 Category운영관리 Bycubebridge Views13370
    Read More
  7. cubrid-php module r2.2 이상 버젼에서 configure시에 주의사항

    Date2010.07.20 Category응용개발 Byseongjoon Views14007
    Read More
  8. cubrid plandump ( plan cache정보확인)

    Date2015.12.29 Category운영관리 By주현 Views4300
    Read More
  9. cubrid manager server 구동 시 no "events" section in configuration 오류 발생

    Date2014.07.03 CategoryCUBRID 매니저 By손승일 Views10262
    Read More
  10. csql에서 Java SP를 이용 조회 시 한글 깨짐현상 조치방법

    Date2009.05.21 Category기타 Bycubebridge Views21044
    Read More
  11. csql 인터프리터를 통해 쿼리 수행시간을 확인하는 방법.

    Date2009.06.30 Category운영관리 Byseongjoon Views13196
    Read More
  12. csql 데이터 입력방법

    Date2009.06.09 Category운영관리 By정만영 Views213427
    Read More
  13. XE(구 제로보드XE) 에서 로그인이 되지 않을 경우 해결법

    Date2009.04.16 Category기타 ByPrototype Views26997
    Read More
  14. Window서버 cmd창에서 CUBRID 구동 후 cmd창을 닫을 시 DB서비스 중단 조치방법

    Date2009.10.29 Category운영관리 Bycubebridge Views16465
    Read More
  15. Windows에서 32bit 버전의 PHP 설치 후 CUBRID와 연동 실패 시 해결 방법

    Date2016.03.28 Category응용개발 By진우진 Views4526
    Read More
  16. Windows 환경에서 JAVA SP 사용 utf-8 한글 깨짐 해결

    Date2016.07.01 Category응용개발 By손승일 Views4594
    Read More
  17. Windows 서버에서 [장치에 쓰기 캐싱 사용] 설정/해제에 따른 성능 차이

    Date2012.06.30 Category운영관리 By이용미 Views20231
    Read More
  18. Weblogic 10.0 사용시 JDK 1.5를 사용한 JDBC 드라이버 사용시 주의사항.

    Date2012.02.22 Category응용개발 Bycubebridge Views51957
    Read More
  19. WHERE 조건에서 다중 컬럼 IN절 처리 최적화 방법 (cubrid + ibatis)

    Date2015.08.21 Category응용개발 By이상신 Views55153
    Read More
  20. VALUES 절 활용하기

    Date2020.05.13 Category질의작성 By황영진 Views821
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 14 Next
/ 14

Contact Cubrid

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