[unixODBC-dev] Regarding return codes from SQLFetch();

Nick Gorham nick at lurcher.org
Mon Aug 28 15:13:56 BST 2006


sidhartha.bardoloye at wipro.com wrote:

> Hello,
>
> I have a query which is as follows:
>
> *select max( <id> ) from <table_name> where <column_name> = 
> ‘<some_name>’;*
>
> This query returns no rows but *SQLFetch()* returns a code *0* while 
> we were expecting the return code to be *SQL_NO_DATA_FOUND* or 100.
>
> However if we modify the above query to this *select <id> from 
> <table_name> where <column_name> = ‘<some_name>’; *then we find that 
> the *SQLFetch()* returns a code 100 when the query returns no rows.
>
> Is this the way it should behave? Does it behave this because we are 
> using aggregate functions like *max*. We are using easy soft drivers.
>
Hi,

Yes, thats exactly how it should behave. The effect of applying an 
aggregate function on a empty result set, is well defined, and the above 
MAX() should return a NULL value in exactly one result row. One of the 
tests of the FIPS conformance suite covers exactly this condition.

Its the same situation as if you did

select count(*) from table where 1 = 0

That will return one row containing the count of rows, in this case zero.

-- 
Nick Gorham
Easysoft Limited.




More information about the unixODBC-dev mailing list