more Memo field UTF8 adventures

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
pwatel
Posts: 39
Joined: Wed 11 Feb 2009 09:42

more Memo field UTF8 adventures

Post by pwatel » Fri 10 Apr 2009 11:35

As everything these days are unicode
New Delphi, WEB pages, windows, Firebird (UTF8) and memo fields
It is kind of natural that you could use a database blob aka memo to store
for example a web page full of unicode...

Yet why is it such a headache that one cannot do simply with your product
the following

Database and field being UTF8
SELECT from WHERE etc

Open the query and
Q.fields[0].asstring showing the right stuff
how involved it has to be????
I have spent 2 days dicking around to try to get the stuff to work
and if I cut and paste the content of the memo to a file or to an editor it work...
Please any ideas ???

by the way it should be as simple to do on a update or insert a block of text

thanks regards
Philippe Watel

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 13 Apr 2009 07:54

You should set the EnableMemos and UseUnicode options of TIBCConnection to True. In this case UTF8 BLOBs are automatically decoded by IBDAC.

pwatel
Posts: 39
Joined: Wed 11 Feb 2009 09:42

UTF8 memo fields

Post by pwatel » Tue 14 Apr 2009 10:06

Thaks for your answer
It works on the select now
but how about on Update or insert
what is the correct synax

q.sql := 'update
Set memofield = :memofield';
q.ParamByName(memofield).Value := bigstring;
q.execute
or you have to add
q.ParamByName(memofield).DataType := ftblob;
q.ParamByName(memofield).AsIbBlob.IsUnicode := Self.UseUnicode;
The documentation or help is a bit non existant (or at least could not find examples)
regards
PW

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 14 Apr 2009 10:49

You should set DataType of the parameter to ftWideMemo:

Code: Select all

q.ParamByName(memofield).DataType := ftWideMemo; 
q.ParamByName(memofield).Value := bigstring; 
q.Execute;
In this case IBDAC encodes parameter's value to UTF8 before it sends the value to the server.

You can also set the UnicodeMemoParameters global variable from the IBC unit to True. In this case values of ftMemo parameters will be also encoded to UTF8:

Code: Select all

q.ParamByName(memofield).AsMemo := bigstring; 
q.Execute;

mischerr
Posts: 3
Joined: Wed 09 Dec 2009 09:25

And how to clear a parameter to NULL?

Post by mischerr » Wed 09 Dec 2009 09:47

Hello.

This works fine, but on the BDE it was possible to set a parameter to NULL.

Code: Select all

    if Text = '' then begin
      Param.Clear;
      Param.DataType := ftMemo;
    end else
      Param.AsMemo := Text;
Param is TParam - the result of ParamByName().

When I do this with IBDAC, I get an AV when I execute my SQL statement.

What is the suggested way to set a parameter for Blob / Memo to NULL?

Rgds,
Michael

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 10 Dec 2009 09:12

In IBDAC you cannot change value of BLOB parameter using the TParam class. You should use TIBCParam or TDAParam.

mischerr
Posts: 3
Joined: Wed 09 Dec 2009 09:25

Post by mischerr » Thu 10 Dec 2009 09:29

Well, the param is the result of ParamByName() called on an TIBCQuery.
So it is a TIBCParam. It's only passed to my function as TParam like this:

Code: Select all

procedure SetMemoParam (const Param : TParam; const Text : string);
begin
  if Assigned(Param) then begin
    if Text = '' then begin
      Param.Clear;
      Param.DataType := ftMemo;
    end else
      Param.AsMemo := Text;
  end;
end;
As TIBCParam inherites from TParam this shoud be possible.

So, how is it possible to set a blob parameter to NULL with a TIBCParam without changing the SQL statement?

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 11 Dec 2009 08:47

TDAParam has its own code for setting the parameter value. Methods in TParam are not virtual. So the code in TDAParam is not executed if you access the parameter using the TParam variable.

Post Reply