Page 1 of 1
Display VARBINARY(MAX) in FreeTDS
Posted: 28.03.2023, 11:43
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
Re: Display VARBINARY(MAX) in FreeTDS
Posted: 28.03.2023, 14:57
by marsupilami
Hello brick08,
I changed Zeos trunk and Zoes 8 accordingly. Could you please test if it works?
Best regards,
Jan
Re: Display VARBINARY(MAX) in FreeTDS
Posted: 29.03.2023, 08:19
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.
Re: Display VARBINARY(MAX) in FreeTDS
Posted: 04.04.2023, 11:50
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.
Re: Display VARBINARY(MAX) in FreeTDS
Posted: 04.04.2023, 12:05
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
Re: Display VARBINARY(MAX) in FreeTDS
Posted: 04.04.2023, 12:39
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.
marsupilami wrote: ↑04.04.2023, 12:05
I applied the patch. Thank you
Thank you too