Insert Blob SQL
Insert Blob SQL
Hello
Is it posible to get a example with inserting BLOB with SQL.
Not only refering to "Please see MyDAC/Demos/Pictures project"
THis is the code i am using. and it works some times....
var
m:TmemoryStream
begin
...
MyQuery1.Close;
MyQuery1.sql.Text:= Trim('Update vRapport set rapport=:BB where id=9');
MyQuery1.ParamByName('BB').DataType:=ftBlob;
MyQuery1.ParamByName('BB').ParamType := ptInputOutput;
MyQuery1.ParamByName('BB').SetBlobData(m.Memory, m.Size);
MyQuery1.Execute;
Anybody that hase any code that works?
Stians
Is it posible to get a example with inserting BLOB with SQL.
Not only refering to "Please see MyDAC/Demos/Pictures project"
THis is the code i am using. and it works some times....
var
m:TmemoryStream
begin
...
MyQuery1.Close;
MyQuery1.sql.Text:= Trim('Update vRapport set rapport=:BB where id=9');
MyQuery1.ParamByName('BB').DataType:=ftBlob;
MyQuery1.ParamByName('BB').ParamType := ptInputOutput;
MyQuery1.ParamByName('BB').SetBlobData(m.Memory, m.Size);
MyQuery1.Execute;
Anybody that hase any code that works?
Stians
This is the real code i use:
Function Tzdb.SaveBlobToDB(SQL:String; m:TmemoryStream):Integer;
begin
Result:=-1;
Self.MyConnection1.StartTransaction;
MyQuery1.Close;
MyQuery1.sql.Text:= Trim(SQL);
MyQuery1.ParamByName('BB').DataType:=ftBlob;
MyQuery1.ParamByName('BB').ParamType := ptInputOutput;
MyQuery1.ParamByName('BB').SetBlobData(m.Memory, m.Size);
try
MyQuery1.Execute;
zdb.MyConnection1.Commit;
Result:=1;
Except
zdb.MyConnection1.Rollback;
end;
end;
The problem is on line: myQuery1.ParamByName('BB').SetBlobData(m.Memory, m.Size);
I get a exception every time. If i remove the try except i somthimes can insert blobs. and sometimes i i get a accesviolation.
S.
Function Tzdb.SaveBlobToDB(SQL:String; m:TmemoryStream):Integer;
begin
Result:=-1;
Self.MyConnection1.StartTransaction;
MyQuery1.Close;
MyQuery1.sql.Text:= Trim(SQL);
MyQuery1.ParamByName('BB').DataType:=ftBlob;
MyQuery1.ParamByName('BB').ParamType := ptInputOutput;
MyQuery1.ParamByName('BB').SetBlobData(m.Memory, m.Size);
try
MyQuery1.Execute;
zdb.MyConnection1.Commit;
Result:=1;
Except
zdb.MyConnection1.Rollback;
end;
end;
The problem is on line: myQuery1.ParamByName('BB').SetBlobData(m.Memory, m.Size);
I get a exception every time. If i remove the try except i somthimes can insert blobs. and sometimes i i get a accesviolation.
S.
Please specify exact version of Delphi or Kylix you use and exact version of MyDAC, you can see it in About sheet of TMyConnection Editor.
Possibly there is something wrong with the MemoryStream object. We can not draw a conclusion about the reason of the problem if we do not have an examle that demonstrates the problem. If the problem appears in a big application try to curtail this application to minimum extent.
Possibly there is something wrong with the MemoryStream object. We can not draw a conclusion about the reason of the problem if we do not have an examle that demonstrates the problem. If the problem appears in a big application try to curtail this application to minimum extent.
-
ca_cruiser
- Posts: 13
- Joined: Tue 17 May 2005 12:59
MyQuery.Params.ParamByName(fnBlob).SetBlobData(BlobData,Bytes - BytesWritten)
does not work when the data has \0 values.
How can I accomplish this ? i.e. how to escape the binary data?
I currently have to do the following:
ms := TMemoryStream.Create;
ms.WriteBuffer(BlobData^, Bytes - BytesWritten);
ms.Position := 0;
MyQuery.Params.ParamByName(fnBlob).LoadFromStream(ms,ftBlob);
ms.Free;
does not work when the data has \0 values.
How can I accomplish this ? i.e. how to escape the binary data?
I currently have to do the following:
ms := TMemoryStream.Create;
ms.WriteBuffer(BlobData^, Bytes - BytesWritten);
ms.Position := 0;
MyQuery.Params.ParamByName(fnBlob).LoadFromStream(ms,ftBlob);
ms.Free;
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;
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;
have you received my program?
Dear Dimon, have you received my program?
"We have investigate this problem and fixed it. This fix will be included in the next MyDAC build."
---- http://devart.com/forums/viewtopic.php?t=14254
thanks
---- http://devart.com/forums/viewtopic.php?t=14254
thanks