Solved

Insert picture in Database

Posted on 2001-06-24
12
207 Views
Last Modified: 2010-04-06
1- How can I store the images in databases, I use Oralce, Blob datatype. when I call LoadFromFile a message "can not open file" appears. the SetBlobData and GetBlobData a message "unablecable operation" appears.

2- Does the ADO supports Blob datatypes?

if the answer works I will increase the points to 150 points
0
Comment
Question by:newbuilder
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 150 total points
Comment Utility
You can store for example jpeg images in the database by using a blob field (Ole Object field in Access):


var fs: TFileStream;
bs: TBlobStream;


Writing to database:

with Table1 do
begin
Append;
fs := TFileStream.Create('image1.jpg', fmOpenRead);
bs := TBlobStream(CreateBlobStream(FieldByName('picture'), bmWrite));
bs.CopyFrom(fs, 0);
bs.Free;
fs.Free;
Post;
end;


Reading from database:

with Table1 do
begin
fs := TFileStream.Create('image1.jpg', fmOpenWrite or fmCreate);
bs := TBlobStream(CreateBlobStream(FieldByName('picture'), bmRead));
fs.CopyFrom(bs, 0);
bs.Free;
fs.Free;
end;


If you want to display JPEG images you can use a TJPEGImage and then assign it to a TImage:


var j: TJPEGImage;

with Table1 do
begin
bs := TBlobStream(CreateBlobStream(FieldByName('picture'), bmRead));
j := TJPEGImage.Create;
j.LoadFromStream(bs);
Image1.Picture.Assign(j);
bs.Free;
j.Free;
end;


Hope this helps...

Epsylon.
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Hello

  you need to use stream to save and restore the image in Blob fields, I did this by using stream, but u can't do that with loadfromfile
   
  here's a good article to help you in that, using ADO with access database

Pictures inside a database
http://delphi.about.com/compute/delphi/library/weekly/aa030601a.htm

also I asked a question about that to store images in oracle database
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20121415

Best regards
Mohammed Nasman

0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
This also works for ADO...
0
 

Author Comment

by:newbuilder
Comment Utility
Thank you Epsylon.

When I use TADOTable an error appear  "Data type not supported"
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
newbuilder, I have this problem with oracle database when i use ado with blob field, it's work fine with me with access blob field using ado, I changed my program from ado to use BDE with oracle

0
 

Author Comment

by:newbuilder
Comment Utility
so I did
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:newbuilder
Comment Utility
mnasman
I have still some problems with the processing images in data base.
I feel the components is not stable. and I do not trust in BDE, so I went to the oracle database documentation, they solve the problem directly. I have oracle 8.0.6 the free version in oracle side. If you use Bfile (it likes blob) you can get the data from the disk and then convert and copy it to blob field.
Oracle documentation explains this method. In my opinion this method is the best. You will find the method in
\orant\doc\index.htm
0
 
LVL 4

Expert Comment

by:YodaMage
Comment Utility
You are better off just storing the path to the image in a varchar field and adjusting the properties on which ever display component you are using at runtime. Storing images in the DB itself is a resource/performance disaster. JMHO
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
didn't have any problem storing blob field via bde into an oracle-database
from 7.3 to 8.1.7 with epsylons provided code, up to blobs > 20MB

be sure you've the latest bde and the bugfixed sql-link

could be found at www.borland.com/devsupport/bde

meikl ;-)
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
kretzschmar, BDE working fine with Oracle Blob field, but the problem with ADO and Oracle Blob field

0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
:-) ado is microsoft and will work properly with microsoft products, but may have problems with not microsoft products, as seen

i personell like to use doa from
http://www.allroundautomations.nl/doa.html
(comercial)
for work with oracle
(no ado or bde overhead and also no problems and faster than both)

meikl ;-)
0
 

Author Comment

by:newbuilder
Comment Utility
Epsylon
I give you the points.
I found your code in the help. But I do not like the BDE.

Thank you for all
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now