03-15-2011 01:14 PM
since I am new to Blackberry development, I ran into some problems concerning my database as well. I am developing an app in 4 different languages. I tried to solve my encoding problem (which is excactly the same as Patchou noted before) by his approach with inserting a single character into the databse and checking how it will be returned by the database or Row.getString().
This worked quite well on my Bold 9000, but on the Bold 9700 it didn't. I insert a "ß" and it is returned these two "garbage" characters in BOTH devices. But on the 9700 it just shows question marks instead of special characters, "umlaut", arabic oder japanese characters.
I am not really an expert at encoding/decoding...hopefully someone can help me here or give me new input, since I am really desperate to know what the problem is here and how i can fix it.
PS: 9000 (18.104.22.1681), 9700 (22.214.171.1242)
03-15-2011 05:50 PM
I have reviewed Patchou's workaround, and to be honest, thought it was potentially 'flaky'. The issue is, for databases that do not supply UTF-8 Strings, the text has been converted to characters using ISO-8859-1. Taking this text and doing this:
byte aChars = sText.getBytes("ISO-8859-1");
does not, for me, guarantee that you will get the same byte array as was originally supplied.
The approach that I am using
does guarantee that you will get the correct data. The issue is this approach is it is a significant overhead on devices where it is not needed.
So you could reduce this by determining if there is an issue with UTF-8 text data on the device, and if there is, obtain the text variables in hex and then convert to text. Otherwise use normal Select processing.
03-16-2011 12:32 PM
it seems like the database on 9700 is utf encoded while the one on the 9000 is not. I found a mistake in checking which encoding is used. What I do now is insert an arabic character in unicode encoding.
String character = "\u0645";
If the database returns a question mark ("?") with the select statement the encoding is not utf so I ensure UTF with every request statement I do afterwards. Both solutions, including the hex() method in the statement itself and converting the hex data to a utf-8 string as well as
byte chars = text.getBytes("ISO-8859-1"); String utf8 = new String(chars, "UTF-8");
work for me.
Thanks so much, you both helped me a lot.