Board index » delphi » Fields in SELECT clause v fields in underlying table

Fields in SELECT clause v fields in underlying table

I have been working on save/reopen functions (following some threads a
few weeks ago about bookmarks and their non-validity for that
purpose). For my purposes, all datasets which can be repositioned
contain a field 'ID'. The difficulty comes when I have an aggregate
query such as SELECT COUNT(*) FROM MYTABLE as well as a standard
dataset such as SELECT X,Y,Z FROM MYTABLE. Using

        (MyQuery as TDataset).FindField('ID').AsInteger

seems to return a non-nil value from both datasets, but of course when
I try

        MyQuery.Locate('ID', myOldIDValue, [])

I get an error on the aggregate dataset.

If push comes to shove, I guess I have to parse the SelectSQL, but
before I do that, is there a better way?
---
Sarah
[still fairly new to Delphi and OOP, but learning afap]

 

Re:Fields in SELECT clause v fields in underlying table


In article <3c7360ad.144978...@newsgroups.borland.com>, "my.name"@adp-
es.co.uk (Sarah Mould) says...

Quote
> I have been working on save/reopen functions (following some threads a
> few weeks ago about bookmarks and their non-validity for that
> purpose). For my purposes, all datasets which can be repositioned
> contain a field 'ID'. The difficulty comes when I have an aggregate
> query such as SELECT COUNT(*) FROM MYTABLE as well as a standard
> dataset such as SELECT X,Y,Z FROM MYTABLE. Using

>    (MyQuery as TDataset).FindField('ID').AsInteger

> seems to return a non-nil value from both datasets,

        Really?  If the query doesn't contain a field called ID then
FindField should return nil and calling .AsInteger on the result should
raise an access violation.

        Also, there is no need for the dynamic cast.

        -Craig

--
 Craig Stuntz (TeamB) Vertex Systems Corp. Columbus, OH
     Delphi/InterBase WebLog: http://delphi.weblogs.com
     InterBase PLANalyzer (Free IB optimization tool):
          http://delphi.weblogs.com/IBPLANalyzer

Other Threads