Display VARBINARY(MAX) in FreeTDS

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
brick08
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 13.01.2021, 03:27

Display VARBINARY(MAX) in FreeTDS

Post by brick08 »

Hi,
when displaying a column with a type VARBINARY(MAX) in MSSQL Server, an error occurs in ZDbcCache.pas:

Code: Select all

    stBytes: if (FColumnLengths[ColumnIndex] <= 0) or (FColumnLengths[ColumnIndex] = MaxInt)
      then Result := TZRowAccessorBytesLob.CreateWithDataAddess(PZVarLenDataRef(TempBlob), zCP_Binary, ConSettings, FOpenLobStreams)
      else goto Fail; 
because the value of FColumnLengths[ColumnIndex] is 1073741823.
It seems to me that you need to add a check for this value in ZDbcResultSetMetadata.pas:

Code: Select all

      if (ColumnType = stBytes) and ((Precision = 2147483647) or (Precision = 1073741823)) then begin 
        Precision := 0;
        Scale := 0;
      end; 
I added screenshot of tdslog with size of this type
You do not have the required permissions to view the files attached to this post.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Display VARBINARY(MAX) in FreeTDS

Post by marsupilami »

Hello brick08,

I changed Zeos trunk and Zoes 8 accordingly. Could you please test if it works?

Best regards,

Jan
brick08
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 13.01.2021, 03:27

Re: Display VARBINARY(MAX) in FreeTDS

Post by brick08 »

marsupilami wrote: 28.03.2023, 14:57 Could you please test if it works?
Yes, now its ok, thanks.

I'll add more so I don't create a new topic.
When ZConnection.Reconnect or after lost connection I do ZQuery.Close and ZQuery.Open. And If query has parameters, then an error occurs, because query text is garbled. I think that TZAbstractDBLibStatement = class(TZRawParamDetectPreparedStatement) does not follow the procedure TZRawParamDetectPreparedStatement.GetRawEncodedSQL(const SQL: SQLString): RawByteString when Query.Open again. So TZQuestionMarkBindList(BindList)[InParamCount].QMarkPosition value don't updated. And in module ZDbcDbLibStatement.pas code SQLWriter.AddText(P+LastPos, QMarkBindValue.QMarkPosition - LastPos, Result) add wrong string because QMarkBindValue.QMarkPosition value is 0.
Code forexample, use mssql protocol type:

Code: Select all

ZQuery.Close;
    ZQuery.SQL.Text := 'select id from tmp_table where id = :id';
    ZQuery.ParamByName('id').AsInteger := 1;
    ZQuery.Open;
    ZConnection.Reconnect;
    ZQuery.Close;
    ZQuery.Open;
P.S.
And I want to copy ZMemTable without data. i suggest to add parameter to copy data. Attached patch for example. Thanks.
You do not have the required permissions to view the files attached to this post.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Display VARBINARY(MAX) in FreeTDS

Post by marsupilami »

brick08 wrote: 29.03.2023, 08:19 When ZConnection.Reconnect or after lost connection I do ZQuery.Close and ZQuery.Open. And If query has parameters, then an error occurs, because query text is garbled. I think that TZAbstractDBLibStatement = class(TZRawParamDetectPreparedStatement) does not follow the procedure TZRawParamDetectPreparedStatement.GetRawEncodedSQL(const SQL: SQLString): RawByteString when Query.Open again. So TZQuestionMarkBindList(BindList)[InParamCount].QMarkPosition value don't updated. And in module ZDbcDbLibStatement.pas code SQLWriter.AddText(P+LastPos, QMarkBindValue.QMarkPosition - LastPos, Result) add wrong string because QMarkBindValue.QMarkPosition value is 0.
Code forexample, use mssql protocol type:

Code: Select all

ZQuery.Close;
    ZQuery.SQL.Text := 'select id from tmp_table where id = :id';
    ZQuery.ParamByName('id').AsInteger := 1;
    ZQuery.Open;
    ZConnection.Reconnect;
    ZQuery.Close;
    ZQuery.Open;
I think we fixed that one. Could you please check if the current revision of Zeos 7.3 from SVN works? Github should be updated tomorrow.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Display VARBINARY(MAX) in FreeTDS

Post by marsupilami »

brick08 wrote: 29.03.2023, 08:19 And I want to copy ZMemTable without data. i suggest to add parameter to copy data. Attached patch for example. Thanks.
I applied the patch. Thank you :)
brick08
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 13.01.2021, 03:27

Re: Display VARBINARY(MAX) in FreeTDS

Post by brick08 »

marsupilami wrote: 04.04.2023, 11:50 I think we fixed that one. Could you please check if the current revision of Zeos 7.3 from SVN works?
Now, its work fine. Thanks. :wink:
marsupilami wrote: 04.04.2023, 12:05 I applied the patch. Thank you :)
Thank you too :)
Post Reply