Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: CreateBlobStream problem?
CreateBlobStream problem?
Posted: 2007/09/25 05:42
 
Hello,
I have this piece of code in my app.


 With TADQuery.Create(Self) do   Begin   Connection:=someADConnection;   SQL.Text:=someQuery// returns 1 row   Open;   bs:=CreateBlobStream(FieldByName('CONTENT'),bmWrite);   With bs do     Begin     Write(Body,SizeOf(Body));     Free;     end;   Close;   Free;   End;



bs is a TStream and Body is a String.
When, at runtime, execution reaches bs:=CreateBlobStream(FieldByName('CONTENT'),bmWrite), it raises an "Invalid typecast".
Which BTW is not the case when I use i.e. TADOQuery etc.
I tried to figure out what's wrong, but no luck so far...
Any ideas?

Magafourakis George
TEI of Crete
Greece
Re:CreateBlobStream problem?
Posted: 2007/09/25 06:00
 
Hello

What is your DBMS and how is idefined field CONTENT ? Looks like AnyDAC does not create for it TBlobField, but TStringField. If so, then you can just write: FieldByName('CONTENT').AsString := Body.

Regards,
Dmitry
Re:CreateBlobStream problem?
Posted: 2007/09/26 00:01
 
You are right, I forgot to give you this info.
The DBMS is MSSQL2000 and the field CONTENT is defined as varbinary(8000).
Putting a string in that field is one of many possibilities. It is defined that way so that it can accept anything, from an integer to a video clip...

Magafourakis George
TEI of Crete
Greece
Re:CreateBlobStream problem?
Posted: 2007/09/26 01:42
 
1) AnyDAC will define this field as ftVarBinary and will create for it TVarBytesField. Current AnyDAC version does not support CreateBlobStream for non TBlobField's. Possible workarounds:
a) Set FormatOptions.MaxStringSize to values less than 8000. Then all string / binary fields with length greater than 8000 will be defined as blob fields.
b) Include following code, which will force all binary fields to be defined as blobs:

 with ADQuery1.FormatOptions do begin   OwnMapRules := True;   with MapRules.Add do begin     SourceDataType := dtByteString;     TargetDataType := dtBlob;   end; end;


2) AnyDAC 2.0.3 will have fix for that.

Regards,
Dmitry
Re:CreateBlobStream problem?
Posted: 2007/09/26 05:25
 
Hi,
Just to let you know, solution (b) worked fine!
I didn't test (a), (b) seemed more reasonable.
I hope 2.0.3 comes out soon, to improve a work already well done!

Thanks again
Magafourakis George
TEI of Crete
Greece