BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Retrieving BLOB from database

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Randel Bjorkquist
Guest





PostPosted: Mon Jan 26, 2004 5:44 pm    Post subject: Retrieving BLOB from database Reply with quote



Hi all,

I've got my BLOB to load into the SQL Server just peachy, but I can't get
them back out. What I'm trying to do is store the BLOB file in the
database, along with its's file name (in a separate field of course). Then
extract the BLOB from the database, save it to a file, and use
ShellExecute() to open. Currently, I'm only trying to get this to work with
the Bitmap files.

Here is what I'm doing:
1 - I'm get the dataset,
2 - using the "CreateBlobStream()" method of the TDataSet
3 - NEED A WAY TO SAVE TO A PHYSICAL FILE
4 - use ShellExecute() to open.

Here is my code:
void __fastcall Tfrm_Main::OpenBlob(TObject *Sender)
{
AnsiString TestFile = "C:\Temp\Test.bmp";
TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TBlobField* Picture = new TBlobField(Data);
TBlobStream* PicStream = new TBlobStream(Picture, bmRead);
:
//TRY TO SAVE TO FILE HERE,
//USE THE FILE NAME "TestFile"
:
delete Picture;
delete PicStream;

ShellExecute(NULL, "open", TestFile.c_str(), NULL, "C:\", SW_SHOW);
}//end of "Tfrm_Main::OpenBlob" method

Thanks for any help,

Randel Bjorkquist


Back to top
Randel Bjorkquist
Guest





PostPosted: Mon Jan 26, 2004 6:26 pm    Post subject: Re: Retrieving BLOB from database Reply with quote



Hey all,

I got something to work, but I don't like it. Is this correct? Is there a
better way of doing this? I tried to base if off the "CreateBlobStream"
example.

//--------------------------------------------------------------------------
-
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
AnsiString TestFileName = "C:\Temp\";

TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TestFileName += Data->FieldByName("FileName")->AsString;

TFileStream* FileStream = new TFileStream(TestFileName, fmCreate);
TBlobStream* PicStream =
dynamic_cast<TBlobStream*>(Data->CreateBlobStream(Data->FieldByName("Picture
"), bmRead));

FileStream->CopyFrom(PicStream, PicStream->Size);
FileStream->Write(FileStream,PicStream->Size);

delete PicStream;
delete FileStream;

ShellExecute(NULL, "open", TestFileName.c_str(), NULL, "C:\", SW_SHOW);
}

Again, any help is desired.

Randel Bjorkquist

"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote

Quote:
Hi all,

I've got my BLOB to load into the SQL Server just peachy, but I can't get
them back out. What I'm trying to do is store the BLOB file in the
database, along with its's file name (in a separate field of course).
Then
extract the BLOB from the database, save it to a file, and use
ShellExecute() to open. Currently, I'm only trying to get this to work
with
the Bitmap files.

Here is what I'm doing:
1 - I'm get the dataset,
2 - using the "CreateBlobStream()" method of the TDataSet
3 - NEED A WAY TO SAVE TO A PHYSICAL FILE
4 - use ShellExecute() to open.

Here is my code:
void __fastcall Tfrm_Main::OpenBlob(TObject *Sender)
{
AnsiString TestFile = "C:\Temp\Test.bmp";
TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TBlobField* Picture = new TBlobField(Data);
TBlobStream* PicStream = new TBlobStream(Picture, bmRead);
:
//TRY TO SAVE TO FILE HERE,
//USE THE FILE NAME "TestFile"
:
delete Picture;
delete PicStream;

ShellExecute(NULL, "open", TestFile.c_str(), NULL, "C:\", SW_SHOW);
}//end of "Tfrm_Main::OpenBlob" method

Thanks for any help,

Randel Bjorkquist





Back to top
Randel Bjorkquist
Guest





PostPosted: Mon Jan 26, 2004 8:51 pm    Post subject: Re: Retrieving BLOB from database Reply with quote



Found a mistake, here is the corrected code:

//--------------------------------------------------------------------------
-
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
AnsiString TestFileName = "C:\Temp\";

TDataSet* Data = dm_Picture->ds_Picture->DataSet;
TestFileName += Data->FieldByName("FileName")->AsString;

TBlobStream* PicStream;
TFileStream* FileStream;

try{
FileStream = new TFileStream(TestFileName, fmCreate);
PicStream =
dynamic_cast<TBlobStream*>(Data->CreateBlobStream(Data->FieldByName("Picture
"), bmRead));

if(PicStream != NULL){
FileStream->CopyFrom(PicStream, 0);
}//end of "if(PicStream != NULL)"
}//end "try-block"
__finally{
delete PicStream;
delete FileStream;
}//end of "__finally"

ShellExecute(NULL, "open", TestFileName.c_str(), NULL, "C:\", SW_SHOW);
}



"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote

Quote:
Hey all,

I got something to work, but I don't like it. Is this correct? Is there
a
better way of doing this? I tried to base if off the "CreateBlobStream"
example.


//--------------------------------------------------------------------------
-
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
AnsiString TestFileName = "C:\Temp\";

TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TestFileName += Data->FieldByName("FileName")->AsString;

TFileStream* FileStream = new TFileStream(TestFileName, fmCreate);
TBlobStream* PicStream =

dynamic_cast<TBlobStream*>(Data->CreateBlobStream(Data->FieldByName("Picture
"), bmRead));

FileStream->CopyFrom(PicStream, PicStream->Size);
FileStream->Write(FileStream,PicStream->Size);

delete PicStream;
delete FileStream;

ShellExecute(NULL, "open", TestFileName.c_str(), NULL, "C:\", SW_SHOW);
}

Again, any help is desired.

Randel Bjorkquist

"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote in message
news:401551ec$1 (AT) newsgroups (DOT) borland.com...
Hi all,

I've got my BLOB to load into the SQL Server just peachy, but I can't
get
them back out. What I'm trying to do is store the BLOB file in the
database, along with its's file name (in a separate field of course).
Then
extract the BLOB from the database, save it to a file, and use
ShellExecute() to open. Currently, I'm only trying to get this to work
with
the Bitmap files.

Here is what I'm doing:
1 - I'm get the dataset,
2 - using the "CreateBlobStream()" method of the TDataSet
3 - NEED A WAY TO SAVE TO A PHYSICAL FILE
4 - use ShellExecute() to open.

Here is my code:
void __fastcall Tfrm_Main::OpenBlob(TObject *Sender)
{
AnsiString TestFile = "C:\Temp\Test.bmp";
TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TBlobField* Picture = new TBlobField(Data);
TBlobStream* PicStream = new TBlobStream(Picture, bmRead);
:
//TRY TO SAVE TO FILE HERE,
//USE THE FILE NAME "TestFile"
:
delete Picture;
delete PicStream;

ShellExecute(NULL, "open", TestFile.c_str(), NULL, "C:\", SW_SHOW);
}//end of "Tfrm_Main::OpenBlob" method

Thanks for any help,

Randel Bjorkquist







Back to top
Arnie Mauer
Guest





PostPosted: Tue Jan 27, 2004 2:13 pm    Post subject: Re: Retrieving BLOB from database Reply with quote

Quote:
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote in message
news:401551ec$1 (AT) newsgroups (DOT) borland.com...
Hi all,

I've got my BLOB to load into the SQL Server just peachy, but I can't
get
them back out. What I'm trying to do is store the BLOB file in the
database, along with its's file name (in a separate field of course).
Then
extract the BLOB from the database, save it to a file, and use
ShellExecute() to open. Currently, I'm only trying to get this to
work
with
the Bitmap files.

Here is what I'm doing:
1 - I'm get the dataset,
2 - using the "CreateBlobStream()" method of the TDataSet
3 - NEED A WAY TO SAVE TO A PHYSICAL FILE
4 - use ShellExecute() to open.

Here is my code:
void __fastcall Tfrm_Main::OpenBlob(TObject *Sender)
{
AnsiString TestFile = "C:\Temp\Test.bmp";
TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TBlobField* Picture = new TBlobField(Data);
TBlobStream* PicStream = new TBlobStream(Picture, bmRead);
:
//TRY TO SAVE TO FILE HERE,
//USE THE FILE NAME "TestFile"
:
delete Picture;
delete PicStream;

ShellExecute(NULL, "open", TestFile.c_str(), NULL, "C:\", SW_SHOW);
}//end of "Tfrm_Main::OpenBlob" method

Thanks for any help,

Randel Bjorkquist

Exactly what is it that doesn't work or that you are unhappy with?

- Arnie



Back to top
Randel Bjorkquist
Guest





PostPosted: Tue Jan 27, 2004 2:33 pm    Post subject: Re: Retrieving BLOB from database Reply with quote

Hey Arnie,

I guess with I just didn't understand how the TFileStream and TBlobStream
worked. When I first read the about them, I misinterpreted what it was
saying. It just didn't seem right to me, but it worked. I have been able
to get code to work, but was absolutely wrong, if you can understand. So I
just wanted to make sure I understood and or was doing it right. Also,
having to delete both pointers, when I only use the "new" keyword once,
really through me.

So if you have any comments or sugguestions, I'll be more then happy to read
them.

I really do thank you for your reply,

Randel Bjorkquist

The code in your reply is an older example of what I finally got working,
below is the most current.
//--------------------------------------------------------------------------
void __fastcall Tfrm_Main::SpeedButton1Click(TObject *Sender)
{
AnsiString TestFileName = "C:\Temp\";

TDataSet* Data = dm_Picture->ds_Picture->DataSet;
TestFileName += Data->FieldByName("FileName")->AsString;

TBlobStream* PicStream;
TFileStream* FileStream;

try{
FileStream = new TFileStream(TestFileName, fmCreate);
PicStream =
dynamic_cast<TBlobStream*>(Data->CreateBlobStream(Data->FieldByName("Picture
"), bmRead));

if(PicStream != NULL){
FileStream->CopyFrom(PicStream, 0);
}//end of "if(PicStream != NULL)"
}//end "try-block"
__finally{
delete PicStream;
delete FileStream;
}//end of "__finally"

ShellExecute(NULL, "open", TestFileName.c_str(), NULL, "C:\", SW_SHOW);
}



"Arnie Mauer" <xxx (AT) nowhere (DOT) net> wrote

Quote:
"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote in message
news:401551ec$1 (AT) newsgroups (DOT) borland.com...
Hi all,

I've got my BLOB to load into the SQL Server just peachy, but I
can't
get
them back out. What I'm trying to do is store the BLOB file in the
database, along with its's file name (in a separate field of
course).
Then
extract the BLOB from the database, save it to a file, and use
ShellExecute() to open. Currently, I'm only trying to get this to
work
with
the Bitmap files.

Here is what I'm doing:
1 - I'm get the dataset,
2 - using the "CreateBlobStream()" method of the TDataSet
3 - NEED A WAY TO SAVE TO A PHYSICAL FILE
4 - use ShellExecute() to open.

Here is my code:
void __fastcall Tfrm_Main::OpenBlob(TObject *Sender)
{
AnsiString TestFile = "C:\Temp\Test.bmp";
TDataSet* Data = dm_Picture->ds_Picture->DataSet;

TBlobField* Picture = new TBlobField(Data);
TBlobStream* PicStream = new TBlobStream(Picture, bmRead);
:
//TRY TO SAVE TO FILE HERE,
//USE THE FILE NAME "TestFile"
:
delete Picture;
delete PicStream;

ShellExecute(NULL, "open", TestFile.c_str(), NULL, "C:\",
SW_SHOW);
}//end of "Tfrm_Main::OpenBlob" method

Thanks for any help,

Randel Bjorkquist

Exactly what is it that doesn't work or that you are unhappy with?

- Arnie





Back to top
Arnie Mauer
Guest





PostPosted: Thu Jan 29, 2004 6:08 pm    Post subject: Re: Retrieving BLOB from database Reply with quote


"Randel Bjorkquist" <rbjorkquist (AT) coilcraft (DOT) com> wrote

Quote:
Hey Arnie,

*snip*

I don't know if this helps or not, but ...

One really easy way to read a BLOB (C++) is:

AnsiString myBlob = q->FieldByName( "MyBlob" )->AsString;

myBlob will contain the data and myBlob.Length() will give you the size of
the BLOB that was read. Then, you can do what you want with it.

- Arnie



Back to top
Crimson Rider
Guest





PostPosted: Tue Jul 13, 2004 10:20 am    Post subject: Re: Retrieving BLOB from database Reply with quote

I am also trying to retrieve a BLOB field from my database, but I am having the
problem that I can't seem to read any BLOB's greater then 32769 bytes, ie 32k
from it.

If I connect to my MySQL database from Mascon or the like I can see that there
is a picture of about 60k in the datafield, however I only seem to be able to
get the first 32k of it. What am I doing wrong ?

This is the code I use.

TMemoryStream * ptrLoadStream;
TJPEGImage * ptrJPEG = new TJPEGImage();

ptrLoadStream = new TMemoryStream();
ptrJPEG->Assign( DataMod->qImage );

ptrJPEG->SaveToFile("somefile.jpg");

Where qImage is the TBlobField that of the query that retrieves the image from
the databse in the first place.

Any help would be welcome.

Regards
Crimson

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.