Page 1 of 1
more Memo field UTF8 adventures
Posted: Fri 10 Apr 2009 11:35
by pwatel
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
Posted: Mon 13 Apr 2009 07:54
by Plash
You should set the EnableMemos and UseUnicode options of TIBCConnection to True. In this case UTF8 BLOBs are automatically decoded by IBDAC.
UTF8 memo fields
Posted: Tue 14 Apr 2009 10:06
by pwatel
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
Posted: Tue 14 Apr 2009 10:49
by Plash
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;
And how to clear a parameter to NULL?
Posted: Wed 09 Dec 2009 09:47
by mischerr
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
Posted: Thu 10 Dec 2009 09:12
by Plash
In IBDAC you cannot change value of BLOB parameter using the TParam class. You should use TIBCParam or TDAParam.
Posted: Thu 10 Dec 2009 09:29
by mischerr
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?
Posted: Fri 11 Dec 2009 08:47
by Plash
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.