| View previous topic :: View next topic |
| Author |
Message |
Stephen Lee-Woolf Guest
|
Posted: Mon May 17, 2004 12:20 pm Post subject: BLOB Fields and SQL |
|
|
Please excuse the simplicity of this question, but I have not worked
with BLOB fields before and am completely ignorant on the subject.
I have an application that creates a .TIF file which forms the basis of
a FAX message. What I need to do is to put the graphic into the blob
field of a table (Firebird 1.5) and to be able to subsequently access it
from there.
Can someone point me in the right direction for this?
Thanks
--
Steve Lee-Woolf
Manchester,
United Kingdom
"There are 10 types of people:
Those who understand Binary,
and those who don't"
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Mon May 17, 2004 12:53 pm Post subject: Re: BLOB Fields and SQL |
|
|
Use a parameterized INSERT statement and use the parameter object's
LoadFromFile method to assign the contents of the file to the
parameter.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Stephen Lee-Woolf Guest
|
Posted: Mon May 17, 2004 1:16 pm Post subject: Re: BLOB Fields and SQL |
|
|
DOn't quite follow. ...
IBQuery1.ParamByName('BB').AsBlob := ????
In article <0ddha0hc0ub13715m3u6ntfn3rbjmh4eag (AT) 4ax (DOT) com>, [email]no (AT) no (DOT) com[/email]
says...
| Quote: | Use a parameterized INSERT statement and use the parameter object's
LoadFromFile method to assign the contents of the file to the
parameter.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
--
Steve Lee-Woolf
Manchester,
United Kingdom
"There are 10 types of people:
Those who understand Binary,
and those who don't"
|
|
| Back to top |
|
 |
Del Murray Guest
|
Posted: Mon May 17, 2004 3:10 pm Post subject: Re: BLOB Fields and SQL |
|
|
What Bill means is ..
assuming that the tiff image is a file and that tablex has a blob column
called sometifimage ...
create a tadodataset with a command property of
insert into tablex (sometifimage) values(:tifimage) .. notice the
colon in front of "tifimage" (this is a parameter and it is referenced as
tadoquery.parameters[0].value assuming that it is the only parameter ..
they start counting at 0.
you can say in code ..
tadoquery.parameters[0].value := 'xxx' or
tadoquery.parameters[0].loadfromfile( filename, etc) // check the docs
for all the parms for "loadfromfile"
this method will read the data from file for you and put it in the value of
the first parameter . you then only need "post" the tadodataset
|
|
| Back to top |
|
 |
Stephen Lee-Woolf Guest
|
Posted: Mon May 17, 2004 4:08 pm Post subject: Re: BLOB Fields and SQL |
|
|
Nice one Del, thanks. That seems to work fine for putting the .tif into
the table, but how do I get it out (into a new file)? If I use a SELECT
query isn't the SQL parser going to get confused and try to look for the
filename as the value of the blob field?
In article <40a8d522$1 (AT) newsgroups (DOT) borland.com>,
[email]Del.Murray (AT) N_S_CreditHawk (DOT) Net[/email] says...
| Quote: | What Bill means is ..
assuming that the tiff image is a file and that tablex has a blob column
called sometifimage ...
create a tadodataset with a command property of
insert into tablex (sometifimage) values(:tifimage) .. notice the
colon in front of "tifimage" (this is a parameter and it is referenced as
tadoquery.parameters[0].value assuming that it is the only parameter ..
they start counting at 0.
you can say in code ..
tadoquery.parameters[0].value := 'xxx' or
tadoquery.parameters[0].loadfromfile( filename, etc) // check the docs
for all the parms for "loadfromfile"
this method will read the data from file for you and put it in the value of
the first parameter . you then only need "post" the tadodataset
|
--
Steve Lee-Woolf
Manchester,
United Kingdom
"There are 10 types of people:
Those who understand Binary,
and those who don't"
|
|
| Back to top |
|
 |
Del Murray Guest
|
Posted: Mon May 17, 2004 4:37 pm Post subject: Re: BLOB Fields and SQL |
|
|
No, you're not putting the file name into the blob, your putting the
contents of the file (load from file) into the blob. You might store the
filename in another column just for grins so that you know where it came
from, but the actual tiff will be in the column that you updated with the
loadfromfile method. Getting it out depends on what you are going to do with
it. You treat the blob data just like anyother data. You can say ...
select mytiffimage from tifftable where ImageName = 'SomeNudeChick'
Now you have the tiff in a column object of an ado object. You can do what
ever you need from there.
Got it?
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Mon May 17, 2004 6:10 pm Post subject: Re: BLOB Fields and SQL |
|
|
In addition to Del's excellent explanation, note that the TBlobField
field object has a SaveToFile method so you can do:
(IBDataSet1.FieldByName('TheTif') as
TBlobField).SaveToFile('c:fooatif.tif');
Note that FieldByName returns a reference to a TField so you have to
cast it to TBlobField to have access to the SaveToFile method.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Del Murray Guest
|
Posted: Mon May 17, 2004 6:48 pm Post subject: Re: BLOB Fields and SQL |
|
|
I am honored the Bill Todd thinks my explanation is excellent ... do I win
anything? :-)
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Mon May 17, 2004 7:33 pm Post subject: Re: BLOB Fields and SQL |
|
|
Del Murray wrote:
| Quote: | I am honored the Bill Todd thinks my explanation is excellent ... do
I win anything?
|
A year's worth of TeamB salary. <g>
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Mon May 17, 2004 8:03 pm Post subject: Re: BLOB Fields and SQL |
|
|
I'll send you half of my next TeamB bonus check.<g>
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Del Murray Guest
|
Posted: Mon May 17, 2004 9:05 pm Post subject: Re: BLOB Fields and SQL |
|
|
I knew you guys make the big bucks .... I'll invest it in Enron stock when
it comes ;-)
|
|
| Back to top |
|
 |
Stephen Lee-Woolf Guest
|
Posted: Tue May 18, 2004 8:06 am Post subject: Re: BLOB Fields and SQL |
|
|
Got it. It's really not that difficult when you get down to it is it?
Thanks for your help Del.
In article <40a8e991 (AT) newsgroups (DOT) borland.com>,
[email]Del.Murray (AT) N_S_CreditHawk (DOT) Net[/email] says...
| Quote: | No, you're not putting the file name into the blob, your putting the
contents of the file (load from file) into the blob. You might store the
filename in another column just for grins so that you know where it came
from, but the actual tiff will be in the column that you updated with the
loadfromfile method. Getting it out depends on what you are going to do with
it. You treat the blob data just like anyother data. You can say ...
select mytiffimage from tifftable where ImageName = 'SomeNudeChick'
Now you have the tiff in a column object of an ado object. You can do what
ever you need from there.
Got it?
|
--
Steve Lee-Woolf
Manchester,
United Kingdom
"There are 10 types of people:
Those who understand Binary,
and those who don't"
|
|
| Back to top |
|
 |
Stephen Lee-Woolf Guest
|
Posted: Tue May 18, 2004 8:07 am Post subject: Re: BLOB Fields and SQL |
|
|
Thanks Bill. I'm getting the hang of this now!
In article <brvha0t6ti3tjm0k519s07i0133hflupfk (AT) 4ax (DOT) com>, [email]no (AT) no (DOT) com[/email]
says...
| Quote: | In addition to Del's excellent explanation, note that the TBlobField
field object has a SaveToFile method so you can do:
(IBDataSet1.FieldByName('TheTif') as
TBlobField).SaveToFile('c:fooatif.tif');
Note that FieldByName returns a reference to a TField so you have to
cast it to TBlobField to have access to the SaveToFile method.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
--
Steve Lee-Woolf
Manchester,
United Kingdom
"There are 10 types of people:
Those who understand Binary,
and those who don't"
|
|
| Back to top |
|
 |
Stephen Lee-Woolf Guest
|
Posted: Tue May 18, 2004 9:39 am Post subject: Re: BLOB Fields and SQL |
|
|
Bill
The only problem with that is that my D7 installation doesn't appear to
recognise the AsTBlobField casting. Is there an additional unit I need
to use in my project?
In article <brvha0t6ti3tjm0k519s07i0133hflupfk (AT) 4ax (DOT) com>, [email]no (AT) no (DOT) com[/email]
says...
| Quote: | In addition to Del's excellent explanation, note that the TBlobField
field object has a SaveToFile method so you can do:
(IBDataSet1.FieldByName('TheTif') as
TBlobField).SaveToFile('c:fooatif.tif');
Note that FieldByName returns a reference to a TField so you have to
cast it to TBlobField to have access to the SaveToFile method.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
--
Steve Lee-Woolf
Manchester,
United Kingdom
"There are 10 types of people:
Those who understand Binary,
and those who don't"
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Tue May 18, 2004 1:34 pm Post subject: Re: BLOB Fields and SQL |
|
|
No. All you need is the DB unit. Show us the line that fails and the
full text of the error message.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
|