Solved

Insert picture in Database

Posted on 2001-06-24
12
210 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
ID: 6222632
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:Mohammed Nasman
ID: 6222633
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
ID: 6222634
This also works for ADO...
0
 

Author Comment

by:newbuilder
ID: 6222651
Thank you Epsylon.

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

Expert Comment

by:Mohammed Nasman
ID: 6222660
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
ID: 6222668
so I did
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:newbuilder
ID: 6222802
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
ID: 6224660
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
ID: 6224755
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:Mohammed Nasman
ID: 6225790
kretzschmar, BDE working fine with Oracle Blob field, but the problem with ADO and Oracle Blob field

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6226652
:-) 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
ID: 6226904
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

22 Experts available now in Live!

Get 1:1 Help Now