Problem with ZeosLib 8.00 Delphi Alexandria ZDbcCache

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
sglodek
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 13.02.2020, 20:08

Problem with ZeosLib 8.00 Delphi Alexandria ZDbcCache

Post by sglodek »

Hello,

my code worked fine with Delphi 10.4 and ZeosLib 7.2.14 and Firebird 2.5. But I need ZeosLib for Delphi 11 and only found 8.00-beta. Maybe there is a stable version I didn't find?

In ZeosLib 8.00 I get a problem with ZDBcCache using this code which uses a prepared SQL-String, adds a where-clause and reopen the query:

Code: Select all

    with theDataset as TZQuery do
    begin
      Close;
      SQL.Clear;
      SQL.Add(ReaderSQL +
          ' where upper(coalesce(Barcode,'''') || coalesce(LastName,'''') ||coalesce(firstname,'''')||coalesce(username,'''')) like ''%' + theFilter + '%''');
      open;
The resulting sql is this if theFilter is 'JOHN':

Code: Select all

select r.*,
 (select cu.lastname from readers cu where cu.id = r.createuser) as CreateUserName,
 (select uu.lastname from readers uu where uu.id = r.updateuser) as UpdateUserName, 
 left(cast(r.info as varchar(4000)),100) InfoAsString 
 from readers r
 where upper(coalesce(Barcode,'') || coalesce(LastName,'') ||coalesce(firstname,'')||coalesce(username,'')) like '%JOHN%';
The open of the query leads to an access violation in Unit ZDbcCache procedure TZRowAccessor.SetNull(ColumnIndex: Integer);

Code: Select all

procedure TZRowAccessor.SetNull(ColumnIndex: Integer);
var Data: PPointer;
begin
{$IFNDEF DISABLE_CHECKING}
  CheckColumnIndex(ColumnIndex);
{$ENDIF}
  {$R-}
  if (FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}]] = bIsNotNull) then begin  <<-- Access violation in this line
    Data := @FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}] + 1];
    FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}]] := bIsNull;
    {$IFDEF RangeCheckEnabled}{$R+}{$ENDIF}
    case FColumnTypes[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}] of
      stAsciiStream, stBinaryStream, stUnicodeStream:
          PIZLob(Data)^ := nil;
      stBytes, stString, stUnicodeString:
        if Data^ <> nil then begin
          System.FreeMem(Data^);
          Data^ := nil;
        end;
      {$IFDEF WITH_CASE_WARNING}else ;{$ENDIF}
    end;
  end;
end;
I use the same way of coding (take a prepared sql, close the query, add "where" to the sql and reopen it) with ZeosLib 8.0.0-beta for 5 other tables and it workes. Any Idea what goes wrong here?

Thanks for any hint to solve this problem.
Siegbert
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 798
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Problem with ZeosLib 8.00 Delphi Alexandria ZDbcCache

Post by aehimself »

Siegbert,

8.0 is a beta only because the documentation is incomplete as far as I'm aware; technically it's as close to stable as it gets. I'm not saying the issue is not in Zeos (from the information you given I do suspect something on this side) but the changes between 7.2 and 8.0 are enormous. It's also noteworthy that Zeos heavily relies on the library to provide information, which they can do incorrectly (I recall MySQL 5.5, older Oracle libs, even some FreeTDS builds had severe issues).
Therefore, until you can give a viable test case team Zeos is in the blind, basically. Protocol, client version, server version, codepages, data types, amount of records, usually contents of fields can make a difference.

If you can make the exception to be thrown consecutively you can try to put a breakpoint on the line and check each and every condition which can raise an AV:

Code: Select all

if (FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}]] = bIsNotNull)
- What is the amount of items in FBuffer.Columns?
- What is the amount of items in FColumnOffsets?
- What does ColumnIndex ( -1 ) return?
Once you nailed it down, it's only a matter of backtracking... where that comes from and why that amount? Is it correct?

If you don't have the time or urge to look into it, the minimum what will be needed is:
- Library version in use
- DB create script with dummy data loaded if needed
- A minimal Delphi application to make the call to .Open to fail each and every time
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: Problem with ZeosLib 8.00 Delphi Alexandria ZDbcCache

Post by miab3 »

As an aside, Zeos 7.2.14 patch has packages for Delphi 11.

Michał
sglodek
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 13.02.2020, 20:08

Re: Problem with ZeosLib 8.00 Delphi Alexandria ZDbcCache

Post by sglodek »

Hello,

@miab3:thank you for this hint - i found the patch in the subversion-tab :-)

@aehimself: thank you for thie hint to get some more information. I was able to find out that the error is not happening in the suspected SQL, but in a query that is connected as a slave to the master query.
Here is then columnindex = 37 and ColumnCount=1

I am trying to find out more details. As a workaround, I adjusted the affected line in the code so that if ColumnIndex-1>ColumnCount, the procedure is exited without further code execution.

regards,
Siegbert
sglodek
Fresh Boarder
Fresh Boarder
Posts: 11
Joined: 13.02.2020, 20:08

Re: Problem with ZeosLib 8.00 Delphi Alexandria ZDbcCache

Post by sglodek »

... with 7.2.14 patch for Delphi 11 all works fine!
Thanks to miab3 for the hint to that patch
Post Reply