TADODataSet and missing ROWID
- From: "Clayton Arends" <nospam_claytonarends@xxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 11:00:16 -0700
Friends,
I ran across this problem today when I was porting a project. It access
Oracle directly and we are converting it to use ADO instead. Some tables
that it accesses have no unique record identifiers and instead use the ROWID
field for this purpose. When porting the following SQL I found that the
ROWID column was missing from the result set:
select ROWID, somefield from sometable
I performed a Google search and found plenty of people who had asked this
question but never found an answer to solve the problem (aside from answers
like "design your tables to have a unique record id"). So, I am writing
this post to show my solution and find out other people's opinions on this
subject.
I looked at ADODB.PAS and found that the VCL implementation was
intentionally hiding row id fields:
{ in TCustomADODataSet.InternalInitFieldDefs }
if ((adFldRowID and F.Attributes) <> 0) then
Attributes := Attributes + [faHiddenCol];
My solution is to descend a class from TADOQuery (since that's the component
I am really using) and override InternalInitFieldDefs:
TMyADOQuery = class(TADOQuery)
protected
procedure InternalInitFieldDefs; override;
end;
procedure TMyADOQuery.InternalInitFieldDefs;
var
i : integer;
begin
inherited;
for i := 0 to FieldDefs.Count - 1 do
begin
with FieldDefs.Items[index] do
Attributes := Attributes - [faHiddenCol];
end;
end;
Does anyone know the reasoning behind Borland's decision to hide row id
fields? Does this solution appear to be the best one given the
circumstances?
- Clayton
BTW - I am a BCB programmer and have translated my code to OP for this post.
Please forgive me if it's not entirely compilable. I posted here since the
Delphi groups have a greater user base than the equivalent BCB groups. I
used BCB6 for this solution and haven't tested it in BDS2006 yet.
.
- Prev by Date: Re: Connecting to an Access Database in Delphi 2006
- Next by Date: Re: Connecting to an Access Database in Delphi 2006
- Previous by thread: Connecting to an Access Database in Delphi 2006
- Index(es):