Arthur
Arthur

Reputation: 43

DELPHI ADOQuery - detect if dataset will be returned

I'm struggling with correct procedure for executing SQL query.

Basically, I have text field where user can enter SQL code and program will execute it. Unfortunately, I don't know if the dataset will be returned, so I cant tell which function to use: ADOQuery.Open or ADOQuery.ExecSQL

But I need to make some calculations if there is results returned.

Is there any way of predicting if query will return some result or if it is UPDATE only ... how to handle this situation ?

Upvotes: 3

Views: 2784

Answers (3)

philnext
philnext

Reputation: 3402

The best way is to analyse the query before execute it. You will found an exemple of 'how to' with this open source software

Upvotes: 0

user160694
user160694

Reputation:

Forget about TADOQuery, TADOTable, TADOStoredProc. They are components designed to ease porting from applications using the BDE that used their counterparts. In your situation you can use TADOCommand, its Execute() method will return a recorset when needed, and you can access it via a TADODataset assigning Execute() return value to its RecordSet property.

Upvotes: 4

Viktor Svub
Viktor Svub

Reputation: 1469

Without completely parsing and analysing the query text, you can not tell for sure.

But you can (and in your case should) use ADOQuery.Open everytime, as in the case of a not returning command, an empty resultset will be returned - which you can easily detect via TADOQuery.Bof and TADOQuery.Eof or a more low-level property TADOQuery.Recordset.

Upvotes: 0

Related Questions