🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #661

Re: BLOB Field

#661
From: Arnie
Date: Tue, 07 Feb 2006 20:15
84 lines
3472 bytes
"kev" <kev@isp.com> wrote in message 
news:43e8e007$1@newsgroups.borland.com...
>I am having a difficult time writing "BLOB" data into a SQL 
>Server database.
> I can read the data out with no problem using the following 
> code:
>
>        MemSize = Field1->DataSize; // add one for null 
> terminator
>        ByteBuffer = new byte[MemSize]; // Allocate the memory.
>        TempBuffer = new byte[MemSize]; // Allocate the memory.
>
>        Field1->GetData(ByteBuffer,true);
>
> A call to IsBlob() returns False so I have to use GetData(); 
> The database
> field is defined as VarBinary, Max=7800, allow nulls = no and 
> key = no.  At
> any rate the returned data is fine.
>
> This all works fine, however...
>
> Now I want to modify the data, create a new record and write 
> the "blob" back
> into the database.  All I can see seem to get is a record with 
> the blob
> field empty.  I have tried many different things with only 1 
> successful
> attempt.  The problem is I don't know exactly the steps I used 
> for that one.
> Here is a sample of what I am trying:
>
> TField * Field1 =
> (TField*)CalibrationTemplates->FieldByName("TemplateData");
> Templates->Append();  //TADODataSet
> // Write the Modified data bact to a new record.
> // ModBuffer is defined as shown above
> Field1->SetData(ModBuffer,true);
> Templates->UpdateRecord();
>
> I populate other fields using FieldByName->AsString etc.  The 
> new record
> sometimes will show up in the database, but the TemplateData is 
> empty.
>
> Any ideas?
>
> thanks,
> Kev

Hi Kev,

First, I'll show you how we sometimes read fairly small BLOB 
fields.  It's simple.  Then a way of writing them.

// Read
   AnsiString myBlob = qry->Fields->FieldByName( 
"MyBlob" )->AsString;

One note here.  The 'Fields' syntax may be incorrect; I guessed. 
We currently use DB objects that I designed that provide the old 
BDE API because we ported from it.  Use the proper ADO 
FieldByName();


// Writing
   TMemoryStream *MS = new TMemoryStream;
   MS->Write( m_MenuFlags, sizeof(m_MenuFlags) );
   MS->Seek( 0, soFromBeginning );
   qry->Parameters->Items[2]->LoadFromStream( MS, ftBlob );
   delete MS;
   qry->ExecSQL();

Part of the SQL statement is:

   qry->SQL->Add( "UPDATE UserGroup SET Description = :desc, 
Flags = :flgs, "

This writes an unsigned char array (m_MenuFlags) into the BLOB 
field which is parameter 2 (Flags) in the SQL statement.

I hope some of this may be of help to you.

- Arnie
Technical Details
Message-ID: <43e8ff03$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43e8e007$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,99fd46b69bb7e384
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Arnie" <none>
Newsgroups: borland.public.cppbuilder.database.ado
References: <43e8e007$1@newsgroups.borland.com>
Subject: Re: BLOB Field
Date: Tue, 7 Feb 2006 15:15:43 -0500
Lines: 86
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 24.151.53.204
Message-ID: <43e8ff03$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1139343107 24.151.53.204 (7 Feb 2006 12:11:47 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news1.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail