title: Delphi stream to/from database with FireDAC
body: <p>Originaly I want to save/retrieve report from fastreports which uses SaveToStream/LoadToStream for this purpose. I use RAD Studio XE6(upd1).</p>
  
  <p>In database I have table Reports with index field 'StVn'type int and field 'Definition' type ntext. Database is MSSQL and for saving report I use:</p>
  
  <pre><code>  FDCommand.CommandText.Text:='UPDATE Reports SET Definition= :pDefinition WHERE StVn=1';
    FDCommand.Params.ParamByName('pDefinition').LoadFromStream(MyStream, ftWidememo);
    FDCommand.Execute;
  </code></pre>
  
  <p>and for retrieving:</p>
  
  <pre><code>  FDQuery.SQL.Text:='SELECT * FROM Reports WHERE StVn=1';
    FDQuery.Open();
    MyStream:=FDQuery.CreateBlobStream(FDQuery.FieldByName('Definition'),bmRead);
  </code></pre>
  
  <p>This worked for some short reports, but for any real one saving/restoring corrupts report definition.</p>
  
  <p>So I make an test case on new form with just an Memo and tried to save/restore it with same data acess setup (FDConnection, FDCommand, FDQuery) and following code:</p>
  
  <pre><code>procedure TForm1.BMemoSaveClick(Sender: TObject);
  var TmpStream:TStream;
  begin
    TmpStream:=TMemoryStream.Create;
    Memo1.Lines.SaveToStream(TmpStream);
    ShowMessage(IntToStr(TmpStream.Size));
    FDCommand1.Params.Clear;
    FDCommand1.CommandText.Text:='UPDATE Reports SET Definition= :pDefinition WHERE StVn=1';
    FDCommand1.Params.ParamByName('pDefinition').LoadFromStream(TmpStream,ftWideMemo);
    FDCommand1.Execute();
    TmpStream.Free;
  end;
  
  procedure TForm1.BMemoLoadClick(Sender: TObject);
  var TmpStream:TStream;
  begin
    FDQuery.SQL.Text:='SELECT * FROM Reports WHERE StVn=1';
    FDQuery.Open();
    TmpStream:=FDQuery.CreateBlobStream(FDQuery.FieldByName('Definition'),bmRead);
    ShowMessage(IntToStr(TmpStream.Size));
    Memo1.Lines.LoadFromStream(TmpStream);
    TmpStream.Free;
  end;
  </code></pre>
  
  <p>As you can see I have inserted ShowMessage to see the stream size at saving and at retrieving and if I save just default text 'Memo1' I get length of 7 at saving and length of 14 at loading the memo (it is allways doubled).</p>
  
  <p>Any ideas what I am doing wrong ?</p>