Open without result set

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Romano
Posts: 41
Joined: Tue 10 Feb 2009 11:21

Open without result set

Post by Romano » Mon 16 Feb 2009 08:56

Hi,
I have problem with TMSQuery.Open x Execute. I have for example this script:

DBCC CHECKDB (MyTestDB) WITH NO_INFOMSGS, TABLERESULTS

or

IF OBJECT_ID('dbo.ep_DF01','P')IS NOT NULL
BEGIN
EXEC dbo.ep_DF01 1, 'xxx', 2 -- it returns some SELECT
END

In both cases I need to run script with Open, because I expected result set in some cases. But it is possible that it will return no result set and it such case I get error message 'Query must return exactly one result set - use Execute'. I need to call Open and I cannot check all my scripts in the whole application (~2.000.000 rows).
What I can do it? Our old component for SQL Server said RecordCount = 0 (or IsEmpty = True) in case to return no result set...

Thanks a lot
Roman

Romano
Posts: 41
Joined: Tue 10 Feb 2009 11:21

Open without result set

Post by Romano » Mon 16 Feb 2009 14:51

I found that problem is in unit OLEDBAccess in

Code: Select all

function TOLEDBRecordSet.Fetch(FetchBack: boolean = False): boolean;
...
begin
  ...
  try
    if Fields.Count = 0 then
      DatabaseError(SNoResultSet, nil); /// Warning - constant SNoResultSet used for detecting in TCustomMSDataSet.OpenNext
  ...
end;
The comment says that constant SNoResultSet is used in other place but I found it in unit MSConsts only (and in OLEDBAccess of cause).

If I change source code to

Code: Select all

if Fields.Count = 0 then Exit;
all works OK (I didn't get any error yet). Can I do it? Or it is bad solution?

SDAC 4.70.0.44

Thanks
Roman

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 17 Feb 2009 12:49

When a SQL query in your components return zero or more than one result set you should use the Execute method, which allows to use any queries. If SQL statement is a query, Execute calls the Open method.

Post Reply