Lazarus
Programming => Databases => Topic started by: abilal on October 11, 2011, 04:09:59 pm
-
Hi Guys,
I am trying to Save an image (BMP) to MDB database via ODBC.
The good thing is that I can do it for images with file size less then 512 bytes.
When image size is greather than 512 bytes. I have ODBC Bind error (error screen is attached).
Any idea to fix the error?
my code is below:
procedure TForm1.ToDBClick(Sender: TObject);
var
BinStream: TMemoryStream;
begin
BinStream := TMemoryStream.Create;
SQLQuery1.ReadOnly := false;
SQLQuery1.SQL.Text := 'SELECT Pictures FROM Demo WHERE ID=1';
SQLQuery1.Active := True;
SQLQuery1.Open;
aImage.Picture.Bitmap.LoadFromFile('c:\temp\aaa.bmp');
aImage.Refresh;
aImage.Picture.Bitmap.SaveToStream(BinStream);
BinStream.Position:=0;
SQLQuery1.Edit;
TBlobField(SQLQuery1.FieldByName('Pictures')).Clear;
TBlobField(SQLQuery1.FieldByName('Pictures')).LoadFromStream(BinStream);
//Caption:= IntToStr(BinStream.Size);
SQLQuery1.Post;
SQLQuery1.ApplyUpdates;
SQLQuery1.Close;
SQLQuery1.Active := False;
BinStream.Free;
end;
-
Can you please post here some test application, which will show this error ?
-
I have attached a test project with test.MDB, test.bmp, test2.bmp files.
Note that, the test project works well done with 12x12pixel test2.bmp ;)
-
For me it works! also with test.bmp
Which version of FPC/Lazarus do you use (I use FPC 2.7.1 on Win98/XP ) ?
Can you test it with current snapshot ?
( ftp://ftp.freepascal.org/pub/lazarus/snapshots/ )
-
Well, About Lazarus says:
Version #:0.9.30
Date: 2011-03-08
FPC Version: 2.4.2
SVN Revision: 29749
i386-win32-win32/win64
what is your ODBC verison?
and do you have an MS Office installation?
-
I suspect that your problem is related to FPC version, from time of FPC 2.4.2 there was some fixes to TODBCConnection.
ODBC version? - Default with Win98 or WinXP or Vista (I tested it on all 3 environments)
MS Office? - Yes
-
Thank you very much for your interest ;)
Upgrade to FPC 2.7.1 fixes the problem :)
Now test-project works great for realy huge bmp files.
Problem Solved!
Cheers!