|
Debug Source 디렉토리 내 DBCommon.pas까지 뒤져봤으나 제대로 동작하지 않는 관계로
하루동안 고민해본 끝에 다음과 같은 편법을 사용하였습니다... 약간 엽기적(?)이긴 하지만...
1. 최초 SQL 작성시 Select절의 Field를 <TableName><Delimiter><FieldName>과 같은 형태로 작성
ex) select Table1.Field1 As Table1_dlmt_Field1, Table1.Field2 As Table1_dlmt_Field2,
Table2.Field1 As Table2_dlmt_Field1
from Table1, Table2;
2. TADOQuery 를 Override한 Component 작성, 아래와 같은 Index Property 생성
class TMyADOQuery : public TADOQuery {
...
protected:
String __fastcall TMyQuery::GetTableAndFieldNames(int FieldIndex, int Index);
...
public:
__property String TableNames[int FieldIndex] = {read = GetTableAndFieldNames, index=0};
__property String FieldNames[int FieldIndex] = {read = GetTableAndFieldNames, index=1};
}
String __fastcall TMyADOQuery::GetTableAndFieldNames(int FieldIndex, int Index)
{
TStringList* tmpStringList = new TStringList;
//TableName / FieldName 구분
tmpStringList->Text = StringReplace(Fields->Fields[FieldIndex]->FullName, "_dlmt_",
"\r\n", TReplaceFlags() << rfReplaceAll);
return tmpStringList->Strings[Index];
}
3. 사용법
TMyADOQuery* AQuery;
...
AQuery->SQL->Add(...); //앞에서 Delimiter 적용한 SQL 사용
AQuery->Open();
for(int i=0; i < AQuery->FieldCount)
ShowMessage(AQuery->TableNames[i] + "," + AQuery->FieldNames[i]);
초보 님이 쓰신 글 :
: 이를테면 TADOQuery를 통해
:
: select A.aaa, B.bbb
: from table_1 as A, table_2 as B
:
: 와 같은 SQL 을 TQuery로부터 날렸을 때 (혹은 Join 문을 사용했을 경우)
:
: 각 필드명 aaa, bbb를 갖고 해당 필드의 원 소속 테이블명을 알 수 있는 방법을 알고자 합니다.
:
: 그런데 ADOQuery의 TField/TFieldList/TFieldDefs속성을 모두 참조하여도 소속 테이블명에 대한 정보는
:
: 찾을 수 없었으며
:
: TADOQuery->Connection 속성에 GetTableNames() / GetFieldNames() method가 존재하여
:
: connection내 전체 테이블 목록 및 테이블내 전체 필드명을 가져올 수 있는 것을 확인하였으나
:
: 이것만 가지고는 여러 테이블에서 동일한 이름의 필드가 있을 경우 처리할 방법이 난감합니다...
:
: 이 경우 부득이하게 SQL 파싱을 해야 될 지, 아니면 다른 좋은 방법이 있는지
:
: 고수님들의 가르침 부탁드립니다.
:
|