[Lazarus] Accessing MS SQLServer database from Lazarus/FPC?
Michael Van Canneyt
michael at freepascal.org
Mon Jan 24 22:20:38 CET 2011
On Mon, 24 Jan 2011, Bo Berglund wrote:
> On Mon, 24 Jan 2011 19:15:13 +0100, "Dipl. Phys. Jörg Schläger"
> <js at jsdevelop.de> wrote:
>
>>>
>>> Thanks, this was the simple way I have been looking for!
>>> Now that I did that the patch activated and I could see that it no
>>> longer barfs at the EXEC verb.
>>> Still only returns one record out of 4, though.
>>
>> is it possible for you to do something like this ?>
>>
>>
>> ii := 0;
>> Query1.open;
>> while not Query1.eof do
>> begin
>> iii := ii + 1;
>> Query1.next;
>> end;
>>
>> then check ii.
>>
>> In Delphi the behavour of Query1.recordcount with ODBC and MSsql is mystic
>>
>
> The actual code I use is this:
>
> query.Open;
> S := '';
> while not query.EOF do
> begin
> S := S + query.FieldByName('AppNo').AsString + ' - ' +
> query.FieldByName('AppInfo').AsString + #13#10;
> query.Next;
> end;
>
> After the Open call the while loop is entered and the query.Next
> statement causes the query.EOF flag to be set so the loop exits.
> This is what I interpreted as caused by the Open method interpreting
> the return as having only one record.
>
> As an experiment I added a line as follows after the query.Open
> statement:
> i := query.RecordCount;
>
> But this only affirms the fact that the recordset handled by the query
> only contains a single record, i = 1.
In general RecordCount cannot be trusted;
It can be updated as the TDataset fetches records.
In each case: SQLDB relies on ODBC to connect to MS-SQL.
>From testing with MS-Access and MySQL I know that ODBC works fine with other
databases, at least for SELECT Statements.
1. Can you test a regular SELECT statement on the same SQL database ?
If that doesn't work either, we know the problem is in the ODBC connection component.
2. Can you test the same EXEC statement in a Delphi app through ODBC ?
If this gives problems, it means the ODBC driver is well - weird.
(although this would surprise me)
3. If both previous attempts work, there is nothing left but to debug the ODBC connection component.
That means stepping through your code with the debugger.
Michael.
More information about the Lazarus
mailing list