[Lazarus] Accessing MS SQLServer database from Lazarus/FPC?

Bo Berglund bo.berglund at gmail.com
Tue Jan 25 20:08:14 CET 2011


On Tue, 25 Jan 2011 09:13:42 +0000, Mark Morgan Lloyd
<markMLl.lazarus at telemetry.co.uk> wrote:

>Bo Berglund wrote:
>
>> Both work, but return only one record (there should be 4).
>> Or at least the code loop below only traverses once:
>> 
>>   while not query.EOF do
>>   begin
>>     S := S + query.FieldByName('AppNo').AsString + #13#10;
>>     query.Next;
>>   end;
>
>What happens if you put an explicit .First before the loop?
>
>   query.Active:= true;
>   query.First;
>   while not query.EOF do
>   begin
>     S := S + query.FieldByName('AppNo').AsString + #13#10;
>     query.Next;
>   end;
>

This does not help at all...
The query.Recordcount property shows the number of records as 1 and
this is also what is listed in the loop.

A similar Delphi 7 test program using the same ODBC data source but
with Delphi's TADOConnection and TADOQuery correctly delivers the
expected 4 records.
So the ODBC datasource is not at fault by itself.

I believe that there is some assumption made inside the SQLdb system,
which tries to estimate what the query text is going to accomplish and
in this case when it sees the EXEC verb it assumes a simple return,
not a collection of records...

But I am in no position to prove or disprove this because I don't know
the inner workings of database components.
I just use them RAD style.

Hoping that someone here that is more capable will find a solution.


-- 
Bo Berglund
Developer in Sweden





More information about the Lazarus mailing list