#1 2015-06-28 14:34:32

Celso
Member
Registered: 2013-05-14
Posts: 55

SetFieldvalue with blob field

ab, I am using the following code to update my data:

         v_sqlrc := TSQLMyRecord.Create;
         for v_count := 0 to v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].FieldCount - 1 do
         begin
            v_value := v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].AsString;
            v_sqlrc.SetFieldValue(v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].FullName,
                                  PUTF8Char(v_value));
         end;
         v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].FieldByName('ID').Value := frmDM.fRestClient.Add(v_sqlrc,True,False);

But I have a blob field (picture). How do I save this field correctly?

Offline

#2 2015-06-28 16:58:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: SetFieldvalue with blob field

See TSQLRest.UpdateBlob/UpdateBlobFields methods
and  http://synopse.info/files/html/Synopse% … l#TITLE_59

BTW, use a local variable to store v_CadastroCDS[tbc_Cadastro.ActiveTab.Index], your code would be much more readable, and also faster.

Offline

#3 2015-07-02 15:21:35

Celso
Member
Registered: 2013-05-14
Posts: 55

Re: SetFieldvalue with blob field

ab, good morning.

Wonder. I managed to save. I did so and it worked:

v_sqlrc := TSQLMyRecord.Create;
for v_count := 0 to v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].FieldCount - 1 do
begin
   if v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].DataType <> TFieldType.ftBlob then
   begin
      v_value := v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].AsString;
      v_sqlrc.SetFieldValue(v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].FullName,
                                    PUTF8Char(v_value));
   end;
end;
v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].FieldByName('ID').Value := frmDM.fRestClient.Add(v_sqlrc,True,False);
for v_count := 0 to v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].FieldCount - 1 do
begin
   if v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].DataType = TFieldType.ftBlob then
   begin
      v_ms := TMemoryStream.Create;
      TGraphicField(v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count]).SaveToStream(v_ms);
      v_ms.Position := 0;
      frmDM.fRestClient.UpdateBlob(v_sqlrc.RecordClass,
                                              v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].FieldByName('ID').AsInteger,
                                              S2U(v_CadastroCDS[tbc_Cadastro.ActiveTab.Index].Fields[v_count].FullName),
                                              v_ms);
      v_ms.free;
end;

Now I have another problem. To consult, do this:

   v_ressql := AProps.ExecuteInlined('SELECT * FROM MYTABLE',True);
   v_table := v_ressql.FetchAllAsJSON(False);
   JSONToClientDataSet(v_CadastroCDS[v_count],v_table,nil,cdsReplace);

In variable v_table, the blob is Base64. But when running JSONToClientDataSet, he is transforming the blob field to RawUTF8, giving error.

v_table variable:
'{"fieldCount":9,"values":["ID","IDPRODUCT","PRODUCT_PHOTO","INC_DATE","MOD_DATE","INC_USER","INC_NAME","MOD_USER","MOD_NAME",5,1,"￰iVBORw0KGgoAAAANSUhEUgAAAMgAAACsCAYAAAA+PePSAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAANUdSURBVHhe7P0HlCTZeR6IfpEZLr0pX9XVvnump8c7WAIkDEECNCIfnUSJK7tv5fbpyB8dicvzjlZv35OhdFaUREmkuJIoUitCogNAAAQIM8B43zM97X35Su/CZb7vu1nZU2j0dIOCIMxQc7tvRWRkZMQ1v/m+a63V//P7R3g7vB3eDjcNqZ3j2+Ht8Ha4SXhbQd4Ob4dbhJTw1dvx7fh2vHl824O8Hd4Otwgpi3/ejm/Ht+PN49se5O3wdrhFeFtB3g5vh1uE2/aDxIaqKKRgWXQ6Ix3HeqXPSRBgJF/EMOJnXdPnyXEYjn9vfrsTdp8PhxFSqdT1OL42vB4n194opDC8/jwdJ3HyOY5jc/5GYXLvJOz+rPMk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