在 Delphi 的 Unicode 版本中访问记录的真实缓冲区 - ADO
在升级到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TCustomADODataSet 的 GetFieldData 方法正是您所需要的。一共有三个:
第二个中完成了艰苦的工作,这也是 TField.GetData 方法中使用的一个。
您将需要派生您自己的 TADODataSet 后代,并用您自己的版本覆盖 GetFieldData 方法的第二个版本。对所有其他字段调用继承,但对于特定的 BytesInString 字段,请自行读取缓冲区并避免在 TCustomADODataSet.GetFieldData 方法中完成的变体转换。
如果您想避免在任何地方插入自己的后代,请在 ADOInterceptor 单元中声明一个拦截器类:
并确保在使用 ADODB 的任何地方都使用此单元,并且它出现在 use 子句中的 ADODB 单元之后。
The GetFieldData methods of TCustomADODataSet are what you need. There are three:
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:
And make sure that this unit is used everywhere that ADODB is used and it appears AFTER the ADODB unit in the uses clause.
您是否尝试过
Table.FieldByName('BytesInStrField').AsBytes
Did you try
Table.FieldByName('BytesInStrField').AsBytes
您是否尝试过
Table.GetBlobFieldData()
?Have you tried
Table.GetBlobFieldData()
?