Access ole field can not fetch correct, why?
Access ole field can not fetch correct, why?
i do not know how can i upload file, so i paste code here
1: first; create an access mdb file and a table sys_report
has two field id,(string) , reportdata(ole object)
write this code:
procedure TForm1.Button1Click(Sender: TObject);
var
filename:String;
begin
self.ADOQuery1.ConnectionString := Format('Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s; User Id=admin; Password=',[ExtractFilePath(Application.ExeName) + 'jzxxsjx.mdb']);
Self.ADOQuery1.Close;
Self.ADOQuery1.SQL.Clear;
Self.ADOQuery1.SQL.Add('Select * from SYS_REPORT where id=''60bcde8c-fc5c-4d64-bccf-1af919adb485''');
Self.ADOQuery1.Open;
filename := 'c:\aaa.doc';
TBlobField(Self.ADOQuery1.FieldByName('reportData')).SaveToFile(filename);
ShellExecute(0,PAnsiChar('open'),PAnsiChar(filename),nil,nil,1);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
coner : TUniConnection;
Gqry : TUniQuery;
filename:String;
begin
coner := TUniConnection.Create(Self); ;
Gqry := TUniQuery.Create(Self);
coner.ProviderName :='ACCESS';
coner.database := ExtractFilePath(Application.ExeName) + 'jzxxsjx.mdb';
coner.Connect;
Gqry.Connection := coner;
with Gqry do
begin
Close;
sql.Clear;
sql.Add('Select * from SYS_REPORT where id=''60bcde8c-fc5c-4d64-bccf-1af919adb485''');
open;
filename := 'c:\aaa_DAC.doc';
TBlobField(FieldByName('reportData')).SaveToFile(filename);
ShellExecute(0,PAnsiChar('open'),PAnsiChar(filename),nil,nil,1);
end;
end;
this demo show the same access ole object field,
the ado query can get fine data but
the unidac can not get fine data
why? the saved data is the same size but content is not the same
delphi7+ UNIDAC3.08
quickly ,, the program must finished next week; thanks [/url][/list]
1: first; create an access mdb file and a table sys_report
has two field id,(string) , reportdata(ole object)
write this code:
procedure TForm1.Button1Click(Sender: TObject);
var
filename:String;
begin
self.ADOQuery1.ConnectionString := Format('Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s; User Id=admin; Password=',[ExtractFilePath(Application.ExeName) + 'jzxxsjx.mdb']);
Self.ADOQuery1.Close;
Self.ADOQuery1.SQL.Clear;
Self.ADOQuery1.SQL.Add('Select * from SYS_REPORT where id=''60bcde8c-fc5c-4d64-bccf-1af919adb485''');
Self.ADOQuery1.Open;
filename := 'c:\aaa.doc';
TBlobField(Self.ADOQuery1.FieldByName('reportData')).SaveToFile(filename);
ShellExecute(0,PAnsiChar('open'),PAnsiChar(filename),nil,nil,1);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
coner : TUniConnection;
Gqry : TUniQuery;
filename:String;
begin
coner := TUniConnection.Create(Self); ;
Gqry := TUniQuery.Create(Self);
coner.ProviderName :='ACCESS';
coner.database := ExtractFilePath(Application.ExeName) + 'jzxxsjx.mdb';
coner.Connect;
Gqry.Connection := coner;
with Gqry do
begin
Close;
sql.Clear;
sql.Add('Select * from SYS_REPORT where id=''60bcde8c-fc5c-4d64-bccf-1af919adb485''');
open;
filename := 'c:\aaa_DAC.doc';
TBlobField(FieldByName('reportData')).SaveToFile(filename);
ShellExecute(0,PAnsiChar('open'),PAnsiChar(filename),nil,nil,1);
end;
end;
this demo show the same access ole object field,
the ado query can get fine data but
the unidac can not get fine data
why? the saved data is the same size but content is not the same
delphi7+ UNIDAC3.08
quickly ,, the program must finished next week; thanks [/url][/list]
Hello
I got your sample. The cause of this problem is that UniDAC with Access data provider and ADO connection uses different ODBC drivers for Access database. The content of the saved file fully depends on the ODBC driver that you are using.
To resolve this issue you should set the ODBC data provider instead of Access data provider for TUniConnection. And for selected ODBC data provider you should select the same Access ODBC driver that is used by ADO connection. There are three Access ODBC drivers installed on my computer and all of them save file with different content. I tried all tree drivers one by one and found a driver that returned the same result as ADO connection.
I got your sample. The cause of this problem is that UniDAC with Access data provider and ADO connection uses different ODBC drivers for Access database. The content of the saved file fully depends on the ODBC driver that you are using.
To resolve this issue you should set the ODBC data provider instead of Access data provider for TUniConnection. And for selected ODBC data provider you should select the same Access ODBC driver that is used by ADO connection. There are three Access ODBC drivers installed on my computer and all of them save file with different content. I tried all tree drivers one by one and found a driver that returned the same result as ADO connection.
Please create a new empty application and try to execute the following code:
And please provide us the result.
Code: Select all
var
file_name1: string;
file_name2: string;
db_path: string;
ms1, ms2: TMemoryStream;
ado_query: TADOQuery;
uni_connection: TUniConnection;
uni_query: TUniQuery;
b1, b2: byte;
begin
file_name1 := 'c:\aaa_ADO.ods';
file_name2 := 'c:\aaa_Access.ods';
db_path := ExtractFilePath(Application.ExeName) + 'jzxxsjx.mdb';
ado_query := TADOQuery.Create(self);
ado_query.ConnectionString := Format('Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s; User Id=admin; Password=',[db_path]);
ado_query.Close;
ado_query.SQL.Text := 'Select * from SYS_REPORT where id=''60bcde8c-fc5c-4d64-bccf-1af919adb485''';
ado_query.Open;
TBlobField(ado_query.FieldByName('O_VALUE')).SaveToFile(file_name1);
uni_connection := TUniConnection.Create(Self);
uni_connection.ProviderName :='ACCESS';
uni_connection.database := db_path;
uni_connection.Connect;
uni_query := TUniQuery.Create(Self);
uni_query.Connection := uni_connection;
uni_query.sql.Text := 'Select * from SYS_REPORT where id=''60bcde8c-fc5c-4d64-bccf-1af919adb485''';
uni_query.open;
TBlobField(uni_query.FieldByName('O_VALUE')).SaveToFile(file_name2);
ms1 := TMemoryStream.Create;
ms2 := TMemoryStream.Create;
try
ms1.LoadFromFile(file_name1);
ms2.LoadFromFile(file_name2);
ms1.Seek(0, soFromBeginning);
ms2.Seek(0, soFromBeginning);
while ms1.Position b2 then
raise Exception.Create('!!! Content is not equal !!!');
end;
finally
ms1.Destroy;
ms2.Destroy;
end;
ShowMessage('Compare is finished: content is equal');
end;
Please send me your file that you cannot save correctly (you can fill this form: http://www.devart.com/company/contact.html). It seems like your problem depends on the file. As soon I will get this file I will try to help you.
you can use the example i had send, and if you get the demo ok, you can send to [email protected], thanks ,
i guess this bug will appare each file large than 10k;
i guess this bug will appare each file large than 10k;