on 03-27-2015 2:11 PM
Hi Experts,
I'm executing a simple select inside a xsjs service, and after, returning the result in a json format. All works fine, except that, after SP9 (rev 93) upgrade, the charset is no longer working. See below:
Table PEOPLE:
Name | Surname
João | Silva
Here the XSJS file:
$.response.contentType = 'application/json; charset=utf-8';
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement( 'select * from "PEOPLE"' );
var rs = pstmt.executeQuery();
var jsonArr = [];
while (rs.next()){
jsonArr.push({
name: rs.getString(1),
suname: rs.getString(2)
});
}
rs.close();
pstmt.close();
conn.close();
$.response.setBody(JSON.stringify(jsonArr));
$.response.status = $.net.http.OK;
When running SP8, the result was the following:
[
]
Now running SP9, the result is:
[
-{
]
Do you know how can I solve this?
Thanks and regards,
Roberto Falk
You are using the wrong get function.
Returns a string value of the specified column. getString is used for CHAR and VARCHAR column types. ASCII only, not suitable for strings containing Unicode characters.
Returns a string value of the specified column. getNString is used for NCHAR, NVARCHAR, SHORTTEXT column types.
I'm not sure why it even worked on SPS 08. It really shouldn't have.
I might point out that if you are on SPS 09, you can use the new database interface which directly returns JSON and doesn't require the use of any type specific get or set functions. This would also avoid your problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
I read about this new hdb interface, but in fact the code is much bigger than this example, so, I still need to plan this refactoring.
The funny thing is that, even in the web catalog "/sap/hana/ide/catalog/" this error regarding the charset occurs (now on SP9 - SP8 was also fine).
Anyway, thanks for the fast answer.
Schönes Wochenende.
Roberto Falk
Its probably one of those situations where getString wasn't technically working correctly in SPS 08. It was returning a UTF-8 string when it should have been returning an ASCII one. People built upon that bug and were happy. Now the bug is fixed and people are unhappy. That's my guess at least.
Hi, is it posible that we just got this bug fixed? we were using this $.db.resultSet.getString function and everything was working fine, just now we had to change to getText and foud this post. Needless to say we will work with $.hdb in the future.
We are working con HANA 1.00.122.18.1531375173 since september 2019.
We had to migrate the system to another host last month, I dont know if that could have changed something.
Thanks!
Hi Roberto,
We found the same problem today, after we updated to SP9.
As we use a library to return all sql select statments ("readSql()"), we just put an javascript function in our .xsjs code:
Ex: decodeURIComponent(escape(rs.getString(i)))
Regards
Caio Melzer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.