Jump to content
과거의 기술자료(읽기 전용): https://tech.devgear.co.kr ×
과거의 기술자료(읽기 전용): https://tech.devgear.co.kr

[DocWiki 번역] 데이터 타입 맵핑 (FireDAC)


Recommended Posts

Docwiki에 있는 "Data Type Mapping (FireDAC)"를 번역한 글 (번역일: 2022년 3월 7일)

위로 가기: Setting Options (FireDAC)

FireDAC offers a flexible adjustable data type mapping system, which allows you to simplify the migration to FireDAC or optimize data representation.

FireDAC에는 유연하게 조절할 수 있는 데이터 타입 맵핑 시스템이 있다. 데이터 타입 맵핑을 활용하면, FireDAC으로 마이그레이션하는 작업을 단순화할 수 있고,  데이터 표현을 최적화할 수 있다.  

일반 (General)

The data type mapping allows you to map:
result set column data types returned by a FireDAC driver to the data types preferred by the application.
command parameters data types defined by an application to the driver supported data types.

FireDAC 데이터 타입 맵핑을 통해 할 수 있는 맵핑 작업은,

  • FireDAC 드라이버에서 반환한 결과 세트 컬럼을 애플리케이션에서 선호하는 데이터 타입에 맵팅
  • 애플리케이션 안에 정의되는 Command 파라미터 데이터 타입을 FireDAC 드라이버에서 지원하는 데이터 타입에 맵핑


The data type mapping is useful for:

  • the creation of the data type schema compatible with other data access components when migrating the application from these components to FireDAC.
  • the creation of the data type schema compatible across several supported DBMS when developing a cross-DBMS application.
  • the mapping of the data types not supported by an application into the supported ones.
  • the mapping of the generalized data types supported by a driver into the more specialized/convenient ones.
  • the optimization of the memory consumption, by specifying the more optimal data types.

FireDAC 데이터 타입 맵핑이 유용할 상황은,

  • 데이터 타입 스키마를 다른 데이터 액세스 컴포넌트와 호환되도록 생성할 수 있기 때문에, 다른 데이터 액세스 컴포넌트에서 FireDAC으로 애플리케이션을 마이그레이션 할 때 유용하다.
  • 데이터 타입 스키마를 서로 다른 여러 DBMS와 호환되도록 생성할 수 있기 때문에, 여러 종류의 데이터베이스를 다루는 애플리케이션을 개발할 때 유용하다.
  • 애플리케이션에서 지원하지 않는 데이터 타입을 지원되는 데이터 타입으로 맵핑할 수 있다.
  • 특정 드라이버에 의해 생성된 고유한 데이터 타입을 보다 특화되고/편리한 타입으로 맵핑할 수 있다.
  • 메모리 소비를 최적화하기 위해, 보다 최적화된 데이터 타입으로 지정할 수 있다.


Let us consider SELECT of the numeric column from an Oracle table and how it may be mapped:

오라클 테이블에서 숫자 컬럼을 SELECT한다고 가정하고 어떻게 맵핑할 수 있는지 보자.

DDL 드라이버 데이터 타입 선호하는 데이터 타입
NUMBER(2,0) dtBcd, Precision=2, Scale=0 dtSByte
NUMBER(4,0) dtBcd, Precision=4, Scale=0 dtInt16
NUMBER(8,0) dtBcd, Precision=8, Scale=0 dtInt32
NUMBER(18,0) dtBcd, Precision=18, Scale=4 dtCurrency

As you can see, the Oracle driver returns a unified data type (dtBcd/dtFmtBCD) for all possible NUMBER(X,Y) database types. But an application may prefer to use a more specialized/convenient data type, such as dtInt32. Also, FireDAC uses 34 bytes long TBcd data structure for dtBcd/dtFmtBCD data type, and 4 bytes long Integer for dtInt32.

위 표와 같이, 오라클 드라이버는 오라클의 모든 NUMBER(X,Y) 데이터 타입을 일원화된 데이터 타입 (dtBcd/dtFmtBCD)으로 반환한다. 하지만, 애플리케이션에서는 보다 특화되고/편리한 데이터 타입인 dtInt32를 더 좋아한다. 또한 FireDAC은 dtBcd/dtFmtBCD 데이터 타입용으로 길이가 34 바이트인 TBcd 데이터 구조를 사용하고, dtInt32 데이터 타입용으로는 길이가 4 바이트인 Integer를 사용한다.

 

정의하기 (Defining)

FireDAC applies the mapping rules at a command preparation. After the command has been prepared, the rule changes have no effect. If the data type conforms to several rules, then only the first one is used. MaxStringSize, MaxBcdPrecision, MaxBcdScale properties are applied to the source data type before the mapping rules.

FireDAC의 맵핑 규칙은 명령(Command)을 준비할 때 반영된다. 명령(Command)이 준비된 이후에 맵핑 규칙을 변경하면 반영되지 않는다. 데이터 타입에 여러가지 규칙이 맵핑되는 경우에는 첫번째 맵핑만 적용된다. MaxStringSize, MaxBcdPrecision, MaxBcdScale 프로퍼티는 맵핑 규칙이 적용되기 전에 소스 데이터 타입에 반영된다.  

To define the data type mapping, an application must set FormatOptions.OwnMapRules to True and fill the MapRules collection. Each item in the collection is of the TFDMapRule class and represents a single mapping rule. In case of a result set column, each rule defines a transformation of a source data type, returned by a driver, into a target one, preferred by an application. In case of a command parameter, the rule defines a transformation of a target data type, specified by an application, into a source data type, supported by a driver. All rules, excluding the name-based ones, work bidirectionally for both cases.

FireDAC 데이터 멥핑을 정의하려면, 애플리케이션에서 반드시 FormatOptions.OwnMapRulesTrue로 지정하고 MapRules 컬렉션을 채워야 한다. 컬렉션에 담긴 각 항목은 TFDMapRule 클래스이며 하나의 맵핑 규칙이다. 결과 세트 컬럼의 경우, 각 규칙은 드라이버에서 반환한 소스 데이터 타입을 애플리케이션에서 선호하는 타겟 데이터 타입으로 변환하는 규칙을 정의한다. 명령(Command) 파라미터인 경우, 맵핑 규칙은 애플리케이션에서 지정한 타겟 데이터 타입을 드라이버에서 지원하는 소스 데이터 타입으로 변환하는 규칙을 정의한다. 이름-기반 규칙을 제외한 모든 규칙은 양방향으로 작동한다.


Each rule is defined by the TFDMapRule properties:

각 규칙은 TFDMapRule 프로퍼티에서 정의한다.

프로퍼티 설명
PrecMin/PrecMax 소스 데이터 타입 숫자의 정밀도 범위를 지정
ScaleMin/ScaleMax 소스 데이터 타입 소숫점 자리수 범위 지정
SizeMin/SizeMax 소스 데이터 타입 문자열 길이 범위 지정
SourceDataType 소스 데이터 타입
TargetDataType 타겟 데이터 타입
NameMask 컬럼 이름 마스크
TypeMask 컬럼 데이터 타입 마스크

If a precision, scale, or size is not used by the rule, then its value must be -1 (default value). If a source data type conforms to a certain rule, then a column data type will be defined using corresponding TargetDataType.

정밀도, 소숫점 자리수, 크기가 규칙에 지정되어 있이 않으면 (기본값인) -1, 즉, 해당없음으로 지정된다. SourceDataType이 지정되어 있으면 대응되는 TargetDataTyp에 따라 정의된다. 

 

예시 (Example)

To define mapping rules for the sample above, use the following code:

위의 사례를 맵핑 규칙으로 정의하는 코드는 다음과 같다. 

with FDConnection1.FormatOptions do begin
  OwnMapRules := True;
  with MapRules.Add do begin
    ScaleMin := 0;
    ScaleMax := 0;
    PrecMin := 0;
    PrecMax := 2;
    SourceDataType := dtBcd;
    TargetDataType := dtSByte;
  end;
  with MapRules.Add do begin
    ScaleMin := 0;
    ScaleMax := 0;
    PrecMin := 3;
    PrecMax := 4;
    SourceDataType := dtBcd;
    TargetDataType := dtInt16;
  end;
  with MapRules.Add do begin
    ScaleMin := 0;
    ScaleMax := 0;
    PrecMin := 5;
    PrecMax := 8;
    SourceDataType := dtBcd;
    TargetDataType := dtInt32;
  end;
  with MapRules.Add do begin
    ScaleMin := 4;
    ScaleMax := 4;
    PrecMin := 18;
    PrecMax := 18;
    SourceDataType := dtBcd;
    TargetDataType := dtCurrency;
  end;
end;

 

이 댓글 링크
다른 사이트에 공유하기

이 토의에 참여하세요

지금 바로 의견을 남길 수 있습니다. 그리고 나서 가입해도 됩니다. 이미 회원이라면, 지금 로그인하고 본인 계정으로 의견을 남기세요.

Guest
이 토픽(기고/질문)에 답하기

×   서식있는 텍스트로 붙여넣기.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   이전에 작성한 콘텐츠가 복원되었습니다..   편집창 비우기

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

중요한 정보

이용약관 개인정보보호정책 이용규칙 이 사이트가 더 잘 작동하기 위해 방문자의 컴퓨터에 쿠키가 배치됩니다. 쿠키 설정 변경에서 원하는 설정을 할 수 있습니다. 변경하지 않으면 쿠키를 허용하는 것으로 이해합니다.