Spanish Characters Encoding issue with Ignition while committing to SQL Server DB

We have some incoming inventory XMLs which has Spanish characters. We store the XML in a SQL Server DB table with XML datatype for the column. XML datatype already supports UTF-8 encoding, so there shouldn’t be any issue with storing Spanish characters.

If I directly use an insert command to store Spanish characters on SQL Server, they remain intact. But when I try to insert the XML using system.db.runUpdateQuery() with N’ ‘ prefix or system.db.runPrepUpdate with ? parameters from a script, the Spanish encoding breaks during storage in DB. Garbled characters get stored.

Has anyone else seen this behavior from Ignition script or know a fix for this ?

I also saw this old post. Not sure whether a similar issue could be there for XML data type on SQL Server DB - Special Characters

Maybe make sure you’re passing a real Unicode string from Jython u" befreo store it on the SQL Server

xml_u = unicode(xml_string) # or ensure it’s u"..."
system.db.runPrepUpdate("INSERT ... VALUES (?)", [xml_u], "CONN")

1 Like

Tried this. Didn’t work.

I wonder if you need to also add the "u" in front of the SQL query like so:

xml_u = unicode(xml_string) # or ensure it’s u"..."
system.db.runPrepUpdate(u"INSERT ... VALUES (?)", [xml_u], "CONN")

Have you tried via a named query?

At the point where you get the XML from the external source, log repr(xml) to see if the encoding is broken before you ever try to put it in the DB.

1 Like

@michael.flagler - Tried your recommendation. Didn’t work.