Thread View: borland.public.cppbuilder.database.ado
2 messages
2 total messages
Started by kev
Tue, 07 Feb 2006 18:03
BLOB Field
Author: kev
Date: Tue, 07 Feb 2006 18:03
Date: Tue, 07 Feb 2006 18:03
36 lines
2178 bytes
2178 bytes
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
Re: BLOB Field
Author: Arnie
Date: Tue, 07 Feb 2006 20:15
Date: Tue, 07 Feb 2006 20:15
84 lines
3472 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads