C++Builder/Delphi 通過 ADO 存取Oracle 的 Blob 欄位
來源:互聯網
上載者:User
今天報表組的人說CB5裡用ADO讀取Oracle的Blob欄位報錯,於是我試了試,還真是這樣,錯誤資訊是“資料類型不被支援”。
我又試了試Delphi7,也是一樣的錯。
我想,BCB/Delphi的ADO是封裝過了,會不會是封裝得有問題?
於是跑到VB下寫了個Demo,居然成功了~看來真的是封裝的問題。
看來只有通過OLE直接操縱ADO了,寫了段代碼,試了試,也成功了
BCB代碼如下: 1 void __fastcall TForm1::Button1Click(TObject *Sender)
2 {
3 const AnsiString sql = "SELECT * FROM Table WHERE ROWNUM <= 1";
4
5 Variant Conn;
6 Variant ResultSet;
7 Variant ResultField;
8 Variant Size, Value;
9
10 Conn = Variant::CreateObject("adodb.connection");
11 Conn.OlePropertySet("Provider", "OraOLEDB.Oracle");
12 Conn.OleFunction("Open", "Database", "UserName", "Password");
13
14 ResultSet = Variant::CreateObject("adodb.recordset");
15 ResultSet.OleFunction("Open", sql, Conn, 0, 1);
16 ResultField = ResultSet.OlePropertyGet("Fields", "FieldNameOrIndex");
17 Size = ResultField.OlePropertyGet("ActualSize");
18 Value = ResultField.OleFunction("GetChunk", Size);
19
20 void* Data = NULL;
21 SafeArrayAccessData(Value.parray, &Data);
22 try
23 {
24 TFileStream* Stream = new TFileStream("C:\\blob.txt", fmCreate);
25 try
26 {
27 Stream->Write(Data, Size);
28 } __finally {
29 delete Stream;
30 }
31 } __finally {
32 SafeArrayUnaccessData(Value.parray);
33 }
34 }