1. Tracy Lamb
  2. PowerBuilder
  3. Monday, 3 April 2023 15:56 PM UTC

Hi all,

I was so excited about changing quite a few fields from EDIT style to RICHTEXT style.  But I noticed today that the RICHTEXT edit style doesn't retrieve or display data entered into the database prior to changing the dw edit style to RICHTEXT on that column. When testing the RICHTEXT edit style, I tested mostly on new records, or didn't notice that the original data wasn't there (Who would have thunk of that?). If I change the edit style back to EDIT, the original data shows.

Field lengths may be NVARCHAR(255) or NVARCHAR(max).  

Also, I have a ue_keypress event on the dw control in the window, press F12 to insert time stamp.  This works when the edit style is EDIT, but not when the edit style is RICHTEXT.

Do I need to abandon my efforts to change the edit styles?

~~~Tracy

 

Accepted Answer
Tomáš Podzimek Accepted Answer Pending Moderation
  1. Wednesday, 5 April 2023 07:43 AM UTC
  2. PowerBuilder
  3. # Permalink

For converting texts to RTF we used our SQL function

CREATE  FUNCTION [dbo].[F_TEXT_TO_RTF]
 	(@TEXT text)
 RETURNS varchar(8000)
 AS
  
BEGIN
	DECLARE @RTF varchar(8000)
	DECLARE @CRLF VARCHAR(2)

	SET @CRLF = CHAR(13) + CHAR(10)
	
	select  @RTF =  '{\rtf1\ansi\ansicpg1250\uc1\deff0{\fonttbl {\f0\fswiss\fcharset238\fprq2 Arial;}}\fs20 ' + REPLACE(RTRIM(convert(varchar(8000), @TEXT)), @CRLF, '\par ') + '}'

	return @RTF
END

Just update it to nvarchar and font of your choice.

Tomáš

Comment
  1. Miguel Leeuwe
  2. Wednesday, 5 April 2023 10:30 AM UTC
Ah, nice one!
  1. Helpful
  1. Tracy Lamb
  2. Wednesday, 5 April 2023 15:19 PM UTC
Thank you Tomas!

I had 90% of this pieced together, but my solution put multi-line data onto a single line. So I updated my code as follows:



update notes

set notes = '{\rtf1\ansi\ansicpg1250\uc1\deff0{\fonttbl {\f0\fswiss\fcharset238\fprq2 Arial;}}\fs20 '

+ REPLACE(RTRIM(convert(nvarchar(max), notes)), CHAR(13) + CHAR(10), '\par ') + '}'

where notes not like '{\rtf1\%';

Works perfectly!

Many, many thanks for providing the missing link!

  1. Helpful 1
  1. Tomáš Podzimek
  2. Wednesday, 5 April 2023 17:32 PM UTC
You're welcome. Glad I could help.

You might consider to use codepage 1252 for english. 1250 is for Central Europe.
  1. Helpful 1
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 3 April 2023 18:04 PM UTC
  2. PowerBuilder
  3. # 1

Hi Tracy;

   The original data needs to be converted to conform to the rich text (RTF) data stream format.

FYI: https://en.m.wikipedia.org/wiki/Rich_Text_Format

Regards ... Chris 

Comment
  1. Tracy Lamb
  2. Monday, 3 April 2023 18:20 PM UTC
Can you be a little more explicit about how to convert existing data to conform to the RTF format? Do I need to add characters before/after each field in the DB?
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 3 April 2023 18:39 PM UTC
One easy way would be to retrieve the plain text data into a String variable. Then send it to MS-Word via an OLE session. Then command Word to SaveAs an RTF file. From there, read the saved RTF file data into your RTF DataWindow & then have it update the DB.

If you Google around as well, you'll find quite a few other options. HTH

Regards ... Chris

  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 3 April 2023 19:44 PM UTC
  2. PowerBuilder
  3. # 2

Hi,

Maybe another way of updating the blobs:

1. create a small window that retrieves all of your rows in a datawindow, with the edit style set to RTF /RTE.

2. run through all of your rows and do a SELECT for each one of them to get the text value of the column.

3. assign that selected value to your RTE column using the ReplaceText() or paste() function (make sure to first assign an empty value to the column, just in case). 

4. Update() the datawindow.

5. cross fingers that it works.

I cannot try it out myself at this moment, but I think it should work.

regards.

 

Comment
  1. Tracy Lamb
  2. Monday, 3 April 2023 21:16 PM UTC
They aren't blobs... they are nvarchar(255) or nvarchar(max).
  1. Helpful
  1. Miguel Leeuwe
  2. Monday, 3 April 2023 22:42 PM UTC
Same technique should still work., though if your current field length has been "filled up" already, RTE syntax might take up more space than you have available.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.