Page 1 of 2

insert blob from tmemorystream delphi

Posted: Tue 10 Jul 2007 15:05
by Pisco
Hi! How INSERT into BLOB one tmemorystream using DELPHI.
thanks.

Posted: Wed 11 Jul 2007 13:53
by Antaeus
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.

Posted: Thu 19 Feb 2009 07:35
by vga
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;

Posted: Thu 19 Feb 2009 12:08
by Dimon
please describe in more details what is the problem.

retrieve data

Posted: Mon 20 Sep 2010 13:18
by rcdc69
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

Posted: Wed 22 Sep 2010 11:48
by Dimon
I can not reproduce the problem.
Try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

Fixed

Posted: Thu 23 Sep 2010 17:50
by rcdc69
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.

Posted: Fri 24 Sep 2010 07:16
by Dimon
If there is anything else I can help you with, please contact me.

Posted: Thu 21 Oct 2010 03:11
by vga
{
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 ?

Posted: Wed 27 Oct 2010 11:09
by AndreyZ
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.

Posted: Tue 02 Nov 2010 00:21
by vga
thank you.


I use Delphi 2007, MyDac_v5.90.0.55

Posted: Tue 02 Nov 2010 15:05
by AndreyZ
Was the problem solved? If not, please contact me.

Posted: Thu 04 Nov 2010 03:06
by vga
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.

Posted: Fri 05 Nov 2010 10:13
by AndreyZ
Try using this code:

Code: Select all

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

Posted: Sat 06 Nov 2010 06:21
by vga
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.