Options

reading value of type image from sql server

jksjks Member Posts: 277
Hi all,

I want to retrieve a value of type Image(blob in navision) from sql table and want to assign that value to one text variable( my blob contains only characters)

for that i have declared variables of type automation.
I chose following Automation Server
'Microsoft ActiveX Data Objects Recordset 2.5 Library'

CREATE(varrecord);
strsql:='select * from "Windowmaker Software Limited$Licence" where "Record id"=1';
strconnection:= 'Provider=SQLOLEDB;User Id=xyz;Password=xyz;Data Source=IM33;DATABASE=Navision Demodatabase';

varrecord.CursorType(0);
varrecord.CursorLocation(1);
varrecord.Open (strsql,strconnection);

varfield:= varrecord.Fields;
varfieldobj:= varfield.Item(19);
textvar:=varfieldobj.value; // gives an error here

Do i need to create a stream?

Please help.

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,090
    A stream would be the easiest,fasted working and most beautiful solution.

    If you work with a version that hasn't streams, you can write the BLOB to disk. Then open it with a File-variable and read it into your text-variable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    kinekine Member Posts: 12,562
    Warning! If you are reading BLOB through SQL (without using C/AL), you will get compressed data... If you want to read BLOB without using Navision (or using Navision but reading through other tools) you need to disable compression of the field.

    I am not sure if it is applicable to your case but...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    jksjks Member Posts: 277
    How can i store blob to the disk?

    How can i create stream using varfieldobj, because that is the variable refering to the column of the table?
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Store BLOB to disk:

    example with field Picture of Item-table
    IF recItem.Picture.HASVALUE THEN BEGIN
      recItem.CALCFIELDS(Picture);
      recItem.Picture.EXPORT(txtFilename,FALSE);
    END;
    

    PS : if the BLOB-field in SQL in NOT a Navision-table, you need to create a Navision-table that points to that table (Table Property : "LinkedObject")


    Or instead of doing this:
    textvar:=varfieldobj.value; // gives an error here
    

    try this:
    BLOBvar := varfieldobj.value;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    jksjks Member Posts: 277
    How to declare a variable of type blob?
    because when you see the drop down menu in c/al globals blob is not there.

    Thanks for any help
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Use a record where a Blob is present (like Item or Object).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    jksjks Member Posts: 277
    Hello Kriki

    Can you please explain your point in some detail? I am not able to understand it.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Define a global of type record with subtype "Item".
    In the Item-table, there is a field "Picture". This field is a BLOB-field.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    jksjks Member Posts: 277
    According to your suggesting i made one entry in c/al globals as below:
    blobvar Record Item

    then if i write
    blobvar:=varfieldobj.value
    then it gives an run time error that multiple-step oledb generated errors.
  • Options
    krikikriki Member, Moderator Posts: 9,090
    Create a file as binary for writing. Then write your variant in it.
    filMyFile.WRITE(varfieldobj.value);
    

    then close the file.
    Open the file with a text-editor to see if it has been written correctly.
    If it is written correctly you can open the file to read and put everything directly in a text-variable.

    Other possibility is still to create a Navision table with the same layout as the SQL-table and connect the Navision table directly to the SQL-table. In this case you can do a find for the record and you have it in your BLOB. Store that on disk and then open the file to read and put everything directly in a text-variable.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.