Hello Inductive Team,
I’m struggling with a textarea. In a popup window a user can enter some data manually in a TextArea. Data get stored in a MS SQL server V14.0.1. If he enters e.g. a temperatur value like 8°C and it get stored int the DB all is fine. But if he want to edit those data and I read the record back from the DB and load it into the TextArea I get: 8Â°C.
When I store (update) the record into the DB that Â get stored too.
Any idea, how I can prevent that?
Make sure the table column is set to use a unicode or utf8 encoding.
The table column is set to varchar(50) and the collation to SQL_Latin1_General_CP1_CI_AS.
Unicode or utf8 is not selectable. What setting do I have to change?
nvarchar to store unicode data - https://docs.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql?view=sql-server-2017 - you’ll need to change the column or migrate your data into a new column.
Thanks’ for the remark. I made a new column in my table as nvarchar(50) and wrote a new record to the DB into that new column. If I have a look into the DB - it is fine, if I show the record in a power table - looks good, but if I read it to a text field or area still the same problem.
How are you displaying it in a text field? A direct query binding, or using a script?
It’s a script.
I found the problem, even I do not see the problem.
system.gui.getParentWindow(event).getComponentForPath(‘Root Container.TxtA_Note’).text = (data.getValueAt(0,“NOTE”)) that works now.
system.gui.getParentWindow(event).getComponentForPath(‘Root Container.TxtA_Note’).text = str(data.getValueAt(0,“NOTE”)) do not work.
That’s because Python makes a difference between
unicode objects. What you get back from your DB is a
unicode object, but if you cast it to
str, the result will use the environment encoding, so possibly lose information.
There’s no reason to cast anything here, so just leave out the cast.
Leave out the cast, or use the built in
unicode() to cast, instead of
str(), so that you don’t lose non-ASCII characters.