开发者

DELPHI ADOQuery - detect if dataset will be returned

开发者 https://www.devze.com 2023-02-27 08:06 出处:网络
开发者_如何学GoI\'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.

开发者_如何学GoI'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 ?


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消