| View previous topic :: View next topic |
| Author |
Message |
Vadim Guest
|
Posted: Thu Apr 21, 2005 7:55 am Post subject: storing jpeg in sql server using Tquery and TParam |
|
|
Hi,
I am using Sql server, D7, BDE, trying to use Tparam.asBlob of TQuery to
save jpeg in the database.
Tried to save jpeg to TMemoryStream and then assign it to TParam.asBlob but
it turned out asBlob requires string.
Does anybody know how to do this?
Thank you
Vadim
|
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Thu Apr 21, 2005 2:49 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
Vadim wrote:
| Quote: | Tried to save jpeg to TMemoryStream and then assign it to
TParam.asBlob but it turned out asBlob requires string.
|
Use TParam.LoadFromStream instead of AsBlob.
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
|
|
| Back to top |
|
 |
Vadim Guest
|
Posted: Thu Apr 21, 2005 6:04 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
Thank you very much.
I'll try this.
"Craig Stuntz [TeamB]" <craig_stuntz (AT) nospam (DOT) please [a.k.a. acm.org]> wrote
in message news:4267af57 (AT) newsgroups (DOT) borland.com...
| Quote: | Vadim wrote:
Tried to save jpeg to TMemoryStream and then assign it to
TParam.asBlob but it turned out asBlob requires string.
Use TParam.LoadFromStream instead of AsBlob.
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
|
|
|
| Back to top |
|
 |
Topprolmc Guest
|
Posted: Thu Oct 13, 2005 8:13 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
"Craig Stuntz [TeamB]" wrote:
| Quote: |
Vadim wrote:
Tried to save jpeg to TMemoryStream and then assign it to
TParam.asBlob but it turned out asBlob requires string.
Use TParam.LoadFromStream instead of AsBlob.
|
And how do you get it out of the DB using a Query?
|
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Thu Oct 13, 2005 8:26 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
Topprolmc wrote:
| Quote: | Use TParam.LoadFromStream instead of AsBlob.
And how do you get it out of the DB using a Query?
|
TField.SaveToStream/SaveToFile.
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
All the great TeamB service you've come to expect plus (New!)
Irish Tin Whistle tips: http://learningtowhistle.blogspot.com
|
|
| Back to top |
|
 |
Topprolmc Guest
|
Posted: Sat Oct 15, 2005 1:55 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
"Craig Stuntz [TeamB]" wrote:
| Quote: |
Topprolmc wrote:
Use TParam.LoadFromStream instead of AsBlob.
And how do you get it out of the DB using a Query?
TField.SaveToStream/SaveToFile.
|
Funny thing is, I save a jpeg (267KB) like that, and pull it out,
and when saved to file it is 667KB.
|
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Mon Oct 17, 2005 12:37 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
Topprolmc wrote:
| Quote: | Funny thing is, I save a jpeg (267KB) like that, and pull it out,
and when saved to file it is 667KB.
|
Then you'rd doing something wrong. Write the simplest possible test
case which demonstrates the problem and post it here. Please include
your SQL and Delphi code.
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Want to help make Delphi and InterBase better? Use QC!
http://qc.borland.com -- Vote for important issues
|
|
| Back to top |
|
 |
Topprolmc Guest
|
Posted: Sat Oct 29, 2005 2:24 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
"Craig Stuntz [TeamB]" wrote:
| Quote: |
Topprolmc wrote:
Funny thing is, I save a jpeg (267KB) like that, and pull it out,
and when saved to file it is 667KB.
Then you'rd doing something wrong. Write the simplest possible test
case which demonstrates the problem and post it here. Please include
your SQL and Delphi code.
|
The field is the MS SQL IMAGE type.....
Here is the insert:
Var
Name,Full,TN,Ext:String;
Pic:TJPEGIMAGE;
Strm:TmemoryStream;
I:integer;
begin
pic:=TJpegImage.Create;
strm:=tmemorystream.Create;
Datasource1.DataSet.DisableControls;
For i:=0 to Listbox1.items.count-1 do
Begin
Name:=extractFileName(Listbox1.Items.Strings[I]);
TN:=ExtractFilePath(Listbox1.Items.Strings[i])+'TN_00'+InttoStr(i)+'.JPG';
Full:=Name;
Ext:=ExtractFileExt(Name);
While Pos(Ext,Name)>0 do
Begin
Delete(Name,pos(ext,Name),Length(Ext));
End;
Pic.LoadFromFile(Listbox1.Items.Strings[I]);
strm.Seek(0,0);
pic.SaveToStream(strm);
Strm.seek(0,0);
AdoQuery1.active:=False;
AdoQuery1.Sql.Clear;
AdoQuery1.SQL.Add('INSERT INTO TEST.dbo.IMAGE_TBL
(PK_IMAGE_TBL,Image_Name,Image_full)'+
' Values (NEWID(), '''+Name+''', :Image);
Commit;');
AdoQuery1.ParamCheck:=true;
AdoQuery1.Parameters[0].LoadFromStream(strm,ftblob);
Adoquery1.ExecSQL;
AdoQuery1.close;
End;
Datasource1.dataset.Enablecontrols;
AdoTable1.close;
AdoTable1.open;
FreeAndNil(Strm);
FreeAndNil(pic);
end;
And here is the extraction:
Var
Pic:TJPEGIMAGE;
Strm:TmemoryStream;
begin
begin
pic:=TJpegImage.Create;
strm:=tmemorystream.Create;
strm.Seek(0,0);
try
Begin
TBlobField(datasource1.DataSet.FieldByName('Image_full')).SavetoStream(Strm);
Strm.Position:=0;
Pic.LoadFromStream(strm);
Pic.SaveToFile(Datasource1.DataSet.fieldbyName('Image_name').asString+'.jpg');
Image1.Picture.Assign(pic);
End;
Except
End;
FreeandNil(Strm);
FreeandNil(Pic);
end;
end;
|
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Mon Oct 31, 2005 12:50 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
I don't see anything there which would cause the problem you describe,
although there are problems with the code, such as the empty exception
handler. Try and make an even simpler case -- one which saves only one
picture, and loads it again without involving any visual controls at
all. You need to start with code which works and add to it, rather than
starting with code which doesn't work and removing stuff.
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Useful articles about InterBase development:
http://blogs.teamb.com/craigstuntz/category/21.aspx
|
|
| Back to top |
|
 |
Topprolmc Guest
|
Posted: Wed Nov 02, 2005 12:22 pm Post subject: Re: storing jpeg in sql server using Tquery and TParam |
|
|
"Craig Stuntz [TeamB]" wrote:
| Quote: |
I don't see anything there which would cause the problem you describe,
although there are problems with the code, such as the empty exception
handler. Try and make an even simpler case -- one which saves only one
picture, and loads it again without involving any visual controls at
all. You need to start with code which works and add to it, rather than
starting with code which doesn't work and removing stuff.
|
I added a "Strm.Clear;" to the load loop and now it works fine..
|
|
| Back to top |
|
 |
|