Solved

Insert picture in Database

Posted on 2001-06-24
12
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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