insert blob from tmemorystream delphi

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Pisco
Posts: 1
Joined: Tue 10 Jul 2007 15:01

insert blob from tmemorystream delphi

Post by Pisco » Tue 10 Jul 2007 15:05

Hi! How INSERT into BLOB one tmemorystream using DELPHI.
thanks.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 11 Jul 2007 13:53

You can try a code like this:

Code: Select all

var
  BlobField: TBlobField;
begin
  ...
  BlobField := MyQuery.FieldByName('Picture') as TBlobField;
  BlobField.LoadFromStream(FileName);
  ...
end;
You can also see the Picture demo included in MyDAC General Demo. It demonstrates how to load BLOB values from files.

vga
Posts: 58
Joined: Sat 08 Jul 2006 12:04

Post by vga » Thu 19 Feb 2009 07:35

procedure TForm1.Button1Click(Sender: TObject);
var
stream: TMemorystream;
begin
if not OpenImageEnDialog1.Execute then exit;
stream := TMemorystream.Create;
stream.LoadFromFile(OpenImageEnDialog1.FileName);
stream.Position := 0;

MyQuery1.SQL.Text :=
'insert into `test` (pic_id, pic_name) values (null, :picname, :Image)';
MyQuery1.ParamByName('picname').AsString := OpenImageEnDialog1.FileName;

MyQuery1.ParamByName('Image').LoadFromStream(stream, ftBlob);
// MyQuery1.ParamByName('Image').LoadFromFile(OpenImageEnDialog1.FileName, ftBlob);
MyQuery1.Execute;

stream.Free;
end;

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 19 Feb 2009 12:08

please describe in more details what is the problem.

rcdc69
Posts: 2
Joined: Mon 20 Sep 2010 13:11

retrieve data

Post by rcdc69 » Mon 20 Sep 2010 13:18

Hi

I have used that data to save a Blob and the database shows that there is data because it now has 2.6Kb as Blob size

However when I try to retrieve the data and put it back in a TmemoryStream there is no data

BlobField := FieldByName(Field) AS TBlobField;
BlobField.SaveToStream(BlobStrm);

Should I be doing something different to put the data back into a Tmemory stream?
Thanks

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 22 Sep 2010 11:48

I can not reproduce the problem.
Try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

rcdc69
Posts: 2
Joined: Mon 20 Sep 2010 13:11

Fixed

Post by rcdc69 » Thu 23 Sep 2010 17:50

Thanks very much for trying, it turns out that it wasn't a problem with MYDAC, it was an issue with the component that the data was being saved from and loaded back into.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 24 Sep 2010 07:16

If there is anything else I can help you with, please contact me.

vga
Posts: 58
Joined: Sat 08 Jul 2006 12:04

Post by vga » Thu 21 Oct 2010 03:11

{
CREATE TABLE `test` (
`Pic_Id` int(11) NOT NULL AUTO_INCREMENT,
`image` longblob,
`Pic_Name` varchar(80) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`Pic_Id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
}

procedure TForm1.btn1Click(Sender: TObject);
begin
myqry1.SQL.Text := 'insert into test (image, pic_name) values (:image, :pic_name)';
myqry1.ParamByName('image').LoadFromFile('c:\3.jpg', ftBlob);
myqry1.ParamByName('pic_name').AsString := '錦';
myqry1.ExecSQL;
end;

procedure TForm1.con1AfterConnect(Sender: TObject);
begin
con1.ExecSQL('set names utf8', [])
end;


Any one can execute ?

AndreyZ

Post by AndreyZ » Wed 27 Oct 2010 11:09

Hello,

I have tried to run this code and it was executed successfully. Please specify the exact problem that occurs when you are executing this code.

vga
Posts: 58
Joined: Sat 08 Jul 2006 12:04

Post by vga » Tue 02 Nov 2010 00:21

thank you.


I use Delphi 2007, MyDac_v5.90.0.55

AndreyZ

Post by AndreyZ » Tue 02 Nov 2010 15:05

Was the problem solved? If not, please contact me.

vga
Posts: 58
Joined: Sat 08 Jul 2006 12:04

Post by vga » Thu 04 Nov 2010 03:06

yeh,

but I'v got another problem:

I could not run

con1.ExecSQL(
'set names utf8;'+
'insert into batch set ImagePath=''C:\图像'', BatchName=''图像''', []);

more than 2 times.


delphi 2010 & mydac 5.9.0.55

thank you.

AndreyZ

Post by AndreyZ » Fri 05 Nov 2010 10:13

Try using this code:

Code: Select all

  con1.ExecSQL('set names utf8', []);
  con1.ExecSQL('insert into batch set ImagePath=''C:\图像'', BatchName=''图像''', []);

vga
Posts: 58
Joined: Sat 08 Jul 2006 12:04

Post by vga » Sat 06 Nov 2010 06:21

thank you.

the Error msg is:

ReceiveHeader: Net packets out of order: received[x], expected[x]


to reproduce:

get more than 2 connection and some query, open all connections ,
connect to different database of one server, then execute sql.

Post Reply