在 Delphi 的 Unicode 版本中访问记录的真实缓冲区 - ADO

发布于 2024-12-07 16:29:31 字数 552 浏览 3 评论 0原文

在升级到 Delphi 2010 之前,我们能够提取存储在访问数据库字符串字段中的数据,该字段实际上包含字节数组。

这是通过以下方式实现的:

  GetMem(buff, 66);
  try
    if Table.FieldByName('BytesInStrField').GetData(buff, True) then //True false ignored anyway
    begin
      Move(Buff^, X, 65);
    end;
  finally
    //
  end;

由于我们已经升级,甚至缓冲区似乎在 #0#0(字符串终止符)的第一个实例处停止读取

问题是我们不再可以访问这些数据。我想提一下,并不是我自己决定将字节数组放入 Microsoft Access 字符串字段中。

有谁知道我如何在不截断的情况下读取整个文件,我正在努力避免编写自己的整个数据库的直接二进制读取。

由于这是 Delphi 访问 Microsoft Access 我正在使用 TADO 组件。

感谢您的阅读。

Prior to upgrading to Delphi 2010 we were able to extract data stored in a access database string field which actually contains an array of bytes.

This was achieved with something like:

  GetMem(buff, 66);
  try
    if Table.FieldByName('BytesInStrField').GetData(buff, True) then //True false ignored anyway
    begin
      Move(Buff^, X, 65);
    end;
  finally
    //
  end;

Since we have upgraded even the Buffer seems to stop reading at the first instance of #0#0 (String terminator)

The problem is that this data is no longer accessible to us. I would like to mention it was not myself who decided to put an array of Bytes in a Microsoft Access String Field.

Does anyone have any idea's how I can read the entire filed without truncation, I am trying hard to avoid writing my own Direct Binary Read of the entire DB.

As this is Delphi Accessing Microsoft Access I am using the TADO components.

Thanks for reading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灵芸 2024-12-14 16:29:31

TCustomADODataSet 的 GetFieldData 方法正是您所需要的。一共有三个:

function GetFieldData(Field: TField; Buffer: Pointer): Boolean; override;
function GetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean): Boolean; override;
function GetFieldData(FieldNo: Integer; Buffer: Pointer): Boolean; overload; override;

第二个中完成了艰苦的工作,这也是 TField.GetData 方法中使用的一个。

您将需要派生您自己的 TADODataSet 后代,并用您自己的版本覆盖 GetFieldData 方法的第二个版本。对所有其他字段调用继承,但对于特定的 BytesInString 字段,请自行读取缓冲区并避免在 TCustomADODataSet.GetFieldData 方法中完成的变体转换。

如果您想避免在任何地方插入自己的后代,请在 ADOInterceptor 单元中声明一个拦截器类:

TADODataSet = class(ADODB.TADODataSet)
public
  function GetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean): Boolean; override;
;

并确保在使用 ADODB 的任何地方都使用此单元,并且它出现在 use 子句中的 ADODB 单元之后。

The GetFieldData methods of TCustomADODataSet are what you need. There are three:

function GetFieldData(Field: TField; Buffer: Pointer): Boolean; override;
function GetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean): Boolean; override;
function GetFieldData(FieldNo: Integer; Buffer: Pointer): Boolean; overload; override;

The hard work is done in the second one, which is also the one used from the TField.GetData method.

You will need to derive your own descendant of TADODataSet, override the second version of the GetFieldData method with your own version. Call inherited for all other fields, but for your specific BytesInString field, read the buffer yourself and avoid the variant conversion that is done in the TCustomADODataSet.GetFieldData method.

If you want to avoid having to insert your own descendant everywhere, declare an interceptor class in a, for example, ADOInterceptor unit:

TADODataSet = class(ADODB.TADODataSet)
public
  function GetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean): Boolean; override;
;

And make sure that this unit is used everywhere that ADODB is used and it appears AFTER the ADODB unit in the uses clause.

心如狂蝶 2024-12-14 16:29:31

您是否尝试过Table.FieldByName('BytesInStrField').AsBytes

Did you try Table.FieldByName('BytesInStrField').AsBytes

压抑⊿情绪 2024-12-14 16:29:31

您是否尝试过Table.GetBlobFieldData()

Have you tried Table.GetBlobFieldData()?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文