Storing StyledText in database

I am developing a desktop app. I want the user to type text into a textarea and use bold, colour, etc. I then store this in a blob in a SQLite database and retrieve it again into a textarea. The retrieved text shows for example, endofline, as a special character, and not a physical carriage return. Other features are also lost.

How can I collect styled text in a textarea, store it in my database, and retrieve it with its ‘style’ intact?

if you have a DesktopTextArea.StyledText
this object hava a property RTFData, this is what you would write/read at database field.

1 Like

you may also encode base64 when storing and decode when reading
to help for storing special chars.

Thank you. I tried styled text and got compile errors. I’m doing something wrong.

have you a short example please?

Have-you checked in the Examples ?

This link is Examples for Xojo 2026r1.1.

Look for:

2 Likes

always start with online manual to see what the class can do

1 Like

In this particular case, base64 isn’t necessary. By definition, RTF uses only ASCII values of < 128, there are no special characters. And whitespace characters, like Return or Tab, are designated by control words.

2 Likes

If my memory is correct, the above sentence is true and false: false because non ASCII characters are translated to code, true because they are nor removed but coded.

It is true in the only sense that’s relevant in this context. Jonathan is right in that a conversion to Base64 would be superfluous.

From the RTF Version 1.5 Specification (the last I’m aware of): “An RTF file consists of unformatted text, control words, control symbols, and groups. For ease of transport, a standard RTF file can consist of only 7-bit ASCII characters.”

All characters above ASCII 127 are converted to control words or control symbols, which contain only ASCII.

it is still a good practice to encode base64 something we don’t exactly know the real content…
are we sure that ALL special characters are correctly rtf encoded by xojo rtf parser ?
as example : https://tracker.xojo.com/xojoinc/xojo/-/issues/76848

anyway, I still find that rtf is badly supported today by xojo methods
you’ve better use html to store styled text in a database

and use this class to edit them just like styledtext does.

2 Likes

FWIW, I use RTF extensively, and it’s a waste of CPU time and storage space to base64-encode the ASCII. Second, I never use Xojo RTFData, which is slow beyond belief. I use RTFDataMBS (I only code for Mac, I don’t know about other platforms), but I presume it can also be done with declares. Finally, NSTextArea (API1) and DesktopTextArea (API2), which I use to render the RTF, are actually a native macOS control, NSTextView, and can render pretty much anything TextEdit can. I’ve used RTF to render tables, native bullet lists, super/subscript, and more. RTF is far more powerful than the very limited options provided by StyledText.

1 Like

In your original post, probably people with a CS degree wwill understand corerctly what you wrote. But this forum reader do not necessary is / are in this position as far as I understand. Some may understand it differently. That is why I chimed in.

Now, if this forum is reserved to members of the CS group, tell it, please.

Your chiming in that there are no “special” characters in RTF is “false because non ASCII characters are translated to code” was confusing and, as Michael Hussman alluded, missed the context and the point. I don’t think you need as CS degree to understand what ASCII 127 means, but you can look it up. I have nothing more to add.

I really appreciate all your expertise and knowledge, and thank you for your replies/conversation.

BUT, I simply want to learn how to collect styled text, store it in a SQLite database, and retrieve it.

The example from Xojo is not using aa database, so is not helpful.

Can someone, without the technical endoing debates, please help me with how to do what I need.

Thank you all again, I appreciate the Forum and the help you can give.

Like Markus said: The Textarea’s StyledText property gives you a StyledText object which has an RTFData property returning a string in RTF format that you can store in a database field.

I have been using the two routines at the end of this link to convert StyledText to and from a string that can be stored in SQLite.

You have plans to make your application cross-platform, web / desktop / win / mac etc… then RTF is a total no-go.

Use HTML / JSON. I wrote the RTEdit class, and when we expanded the app from Xojo Desktop that used a SupaBase backend, to Web (http://www.eldr.is), using React and the same backend and Supabase API / Edge functions etc., there was no adjustment needed.

1 Like