Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Blob fields and ADO ?

73 views
Skip to first unread message

Brian Driscoll

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to
Hello all.


Does anyone know how I can write and read to a binary (or blob) field using
Delphi and ADO Express ?
I've looked for SaveToFile and LoadFromFile, but no such luck.

Any help would be greatly appreciated.

Thanks.

Delphi 5 (Update Pack 2)
ADOExpress (Update Pack 2)
Database MSSQL 7.0 (SP2)

--
----------------------------------------------------------------------------
-
Brian Driscoll, MCSD
Technicien senior systèmes ordinés
brian.d...@groupecadec.com

Groupe Cadec
Bromptonville, Québec, Canada

http://www.groupecadec.com
----------------------------------------------------------------------------
-


Jan Lesniak

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to
I use TADOBlobStream for writing and reading data from BLOB. TADOBlobStream is replacement of TBlobStream for using with ADO Express.

Jan.

Brian Driscoll

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to

Any reason why the following doesn't work (but doesn't return any error) ?

{---------------------------------------------------------------------------
-------}
procedure TfrmMain.SaveTest();
var
sFileName : string;
BS: TADOBlobStream;
begin
dmData.qryVersion.Open;

dialOpen.Execute;
sFileName := dialOpen.FileName;
ShowMessage(sFileName);
// Place in edit mode.
if not (dmData.qryVersion.State in [dsEdit, dsInsert]) then
dmData.qryVersion.Edit;

// Create blob stream.
BS :=
TADOBlobStream.Create(TBlobField(dmData.qryVersion.FieldByName('binaryExec')
), bmReadWrite);
try
BS.LoadFromFile(sFileName);
dmData.qryVersion.Post;
finally
BS.Free;
end;

dmData.qryVersion.Close;
end;
{---------------------------------------------------------------------------
-------}

Brian Driscoll <brian.d...@groupecadec.com> wrote in message
news:8iah3p$i7...@bornews.borland.com...

Mark Edington (Borland)

unread,
Jun 15, 2000, 3:00:00 AM6/15/00
to
Brian Driscoll <brian.d...@groupecadec.com> wrote in message
news:8iaptr$lt...@bornews.borland.com...

Not too sure why that code wouldn't work. Technically the blobstream should be
freed before the Post, so that may be the problem. TBlobField also has a
LoadFromFile method which you can call
directly:

TBlobField(dmData.qryVersion.FieldByName('binaryExec') ).LoadFromFile(sFileName)
;

Give that a shot.

Mark


Brian Driscoll

unread,
Jun 16, 2000, 3:00:00 AM6/16/00
to
Hello Mark.

Tried the code...

>
TBlobField(dmData.qryVersion.FieldByName('binaryExec') ).LoadFromFile(sFileN
ame)

but I'm getting an 'invalid class typecast'. Any idea why.

BTW the MSSQL field in question is defined as a varbinary.

Thanks again.

Brian Driscoll

Mark Edington (Borland) <medi...@nolunchmeat.com> wrote in message
news:39494331@dnews...

Mark Edington (Borland)

unread,
Jun 16, 2000, 3:00:00 AM6/16/00
to
Brian Driscoll <brian.d...@groupecadec.com> wrote in message
news:8idb19$e8...@bornews.borland.com...

> but I'm getting an 'invalid class typecast'. Any idea why.
> BTW the MSSQL field in question is defined as a varbinary.

Ok, I think we are getting somewhere now. If the field is a VarBinary then it
won't be mapped to a TBlobField and therefore the code I gave you is invalid.
For a VarBinary field you'll need a helper function to read the file into the
field:

Try this:

function StringFromFile(const FileName: string): string;
begin
with TFileStream.create(FileName, fmOpenRead) do
try
SetLength(Result, Size);
Read(Pointer(Result)^, Size);
finally
Free;
end;
end;

dmData.qryVersion.FieldByName('binaryExec')
.SetAsString(StringFileFile(AFileName));

That ought to do it.

Mark


Brian Driscoll

unread,
Jun 19, 2000, 3:00:00 AM6/19/00
to
Hi Mark.

I ended up changing the MSSQL field to an Image type (which is probably
more
appropriate for the type of data I'm using). Now the LoadFromFile and
SaveToFile work fine.

Thanks for putting me on the right track.
BTW, there is no SetAsString with a TVarBinaryField, only for the
TIBStringField (which is InterBase I think).


----- Original Message -----
From: Mark Edington (Borland) <medi...@nolunchmeat.com>
Newsgroups: borland.public.delphi.database.ado
Sent: Friday, June 16, 2000 2:34 PM
Subject: Re: Blob fields and ADO ?

Mark Edington (Borland)

unread,
Jun 19, 2000, 3:00:00 AM6/19/00
to
Brian Driscoll <brian.d...@groupecadec.com> wrote in message
news:8il6ic$qe...@bornews.borland.com...

> I ended up changing the MSSQL field to an Image type (which is probably
> more appropriate for the type of data I'm using). Now the LoadFromFile and
> SaveToFile work fine.

Sounds good.

> BTW, there is no SetAsString with a TVarBinaryField, only for the
> TIBStringField (which is InterBase I think).

Whoops. That should've read:

dmData.qryVersion.FieldByName('binaryExec').AsString :=
StringFileFile(AFileName);

Sorry about the confusion.

Mark


0 new messages