3 CompressBlobMode Problems

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
AndreyZ

Post by AndreyZ » Fri 18 Feb 2011 15:00

We are not planning to support such mapping because it can cause numerous problems.
You can solve this problem in the following way:
- create BLOB field on the server and map it as TBlobField on a client;
- use OnGetText and OnSetText event handlers in the folowing way:

Code: Select all

procedure TMainForm.MyQueryBLBGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
  Text := Sender.AsWideString;
end;

procedure TMainForm.MyQueryBLBSetText(Sender: TField; const Text: string);
begin
  Sender.AsWideString := Text;
end;

Justmade
Posts: 108
Joined: Sat 16 Aug 2008 03:51

Post by Justmade » Sat 19 Feb 2011 01:26

Thank you for your suggestion. However, it can only solve part of the problem when the code use TBlobField.Text.

Actually, even TDBMemo use AsString instead of Text when Load memo.

Code: Select all

procedure TDBMemo.LoadMemo;
begin
  if not FMemoLoaded and Assigned(FDataLink.Field) and FDataLink.Field.IsBlob then
  begin
    try
      Lines.Text := FDataLink.Field.AsString;
      FMemoLoaded := True;
    except
      { Memo too large }
      on E:EInvalidOperation do
        Lines.Text := Format('(%s)', [E.Message]);
    end;
    EditingChange(Self);
  end;
end;

function TBlobField.GetAsString: string;
begin
  // For backwards compatibility, read untyped data as Ansi.
  // Use TWideMemoField for blobs associated with Unicode string data.
  Result := string(GetAsAnsiString);
end;
So The OnGetText and OnSetText cannot make TDBMemo usable.

However, I understand the situation and appreciate your great effort spent to come out to the sad result of no possible solution within MYDAC. So I will settle with this result.

I had create my own version of TDBMemo, which add a property to distinguish using AsString / Text or AsWideString to load / save the text and it is working fine for a start but need more test to see if there are other problems.

Thanks again for your effort on resolving the issue.

AndreyZ

Post by AndreyZ » Mon 21 Feb 2011 09:32

I am glad you've found a solution with the TDBMemo component. Please contact us if you have any other questions.

Justmade
Posts: 108
Joined: Sat 16 Aug 2008 03:51

Post by Justmade » Tue 22 Feb 2011 04:03

AndreyZ wrote:I am glad you've found a solution with the TDBMemo component. Please contact us if you have any other questions.
Thanks.

I got a problem about this Memo that for those data that are saved to database using the original TDBMemo (which used AsString / Text), reading back using AsWideString will become messy characters. Those new input data is working fine as they are saved as wide string in the first place.

May I ask if there any method to check if the TBlobField is containing ansistring or widestring?

Justmade
Posts: 108
Joined: Sat 16 Aug 2008 03:51

Post by Justmade » Wed 23 Feb 2011 03:08

This had been solved by detecting if the blobfield contain widestring and if not use back Ansistring when loading.

I also test if there any dataloss if save as ansistring and do so if no data loss to save space.

Thanks for your help in the issue.

Post Reply