🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Read an mssql varbinary feild from an ADO query?

#1431
From: Arnie Mauer
Date: Wed, 21 Jul 2004 12:45
55 lines
2705 bytes
"Chemile" <chemile@qwest.net> wrote in message
news:40fd95b4$1@newsgroups.borland.com...
> I've been trying to figure out how to read from a varbinary field
for quite
> some time without any luck.  Some of the symbols return as question
marks.
> I'm using Borload C++ Builder 6 and ADO components.  I did figure
out how to
> update a field in hexadecimal.
>
>     pQuery->Close();
>     pQuery->SQL->Clear();
>     pQuery->SQL->Add("insert into tablename (key,binfield) values
> ('1',0x"+hexVal+")");
>     pQuery->ExecSQL();
>
> I also figured a way around it that worked for a while.  I used
"IdHTTP1" to
> download a php webpage that returned the fields data.  But once a
field got
> larger then 256 bytes that stopped working.
>
> I've heard that blobs do not work with varbinary fields.  I'm not
sure if
> that is true, but I haven't been able to retrieve it as a blob.
>
> TADOBlobStream *Stream = new
> TADOBlobStream((TBlobField*)pQuery->Fields->Fields[0],bmRead);
>
> Is there a way to return a query in hexadecimal or in a stream so
that
> extended character info is saved?  Should I change components?
>
> Thanks

We read and write SQL Server VARBINARY and Oracle BLOB fields with the
same routines.  See below.

// Read a VARBINARY or BLOB.  The TADOQuery has been opened.
AnsiString varBin = q->FieldByName( "VarBinField" )->AsString;
// varBin.Length() is how many bytes were read.  Now, do whatever you
want with it.

// Write -
// The SQL is: "INSERT INTO ATable (VarBinField ) VALUES ( :vb )"
   TMemoryStream *MS = new TMemoryStream;
   MS->Write( myBlob, sizeof(myBlob) );
   MS->Seek( 0, soFromBeginning );
   q->Parameters->Items[0]->LoadFromStream( MS, ftBlob );
   delete MS;

I'm sure there are many other, possibly better ways of doing it.

HTH
- Arnie
Technical Details
Message-ID: <40fe6588$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed.iinet.net.au!newsfeed.iinet.net.au!PeerFeed.KWeb.on.ca!news.kweb.on.ca!newsgroups.borland.com!not-for-mail
References: <40fd95b4$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,78c5f45d66599a8f
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Arnie Mauer" <xxx@nowhere.net>
Newsgroups: borland.public.cppbuilder.database.ado
References: <40fd95b4$1@newsgroups.borland.com>
Subject: Re: Read an mssql varbinary feild from an ADO query?
Date: Wed, 21 Jul 2004 08:45:22 -0400
Lines: 58
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 12.29.236.34
Message-ID: <40fe6588$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090413960 12.29.236.34 (21 Jul 2004 05:46:00 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed.iinet.net.au!newsfeed.iinet.net.au!PeerFeed.KWeb.on.ca!news.kweb.on.ca!newsgroups.borland.com!not-for-mail