-
Notifications
You must be signed in to change notification settings - Fork 171
FreeTDS Forces UTF-8 Conversion Despite CP936 Setting in Sybase ASE #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I will try to explain why what you are trying to do is wrong. As you stated your database is installed with CP850 charset. That is the characters it should handle are CP850 that is like https://en.wikipedia.org/wiki/Code_page_850. As you can see this character set do not contain any Chinese character. What you are doing is inserting some binary code expecting to get the same bytes back. This could seems to work "mangle" your charset and then "un-mangle" back hoping for the best. However tools handling encoding as server expects will show "weird" characters. Query could seem to work too, until you realize that the string comparisons are not what you are expecting as the server is using CP850 collation. You could end up using tools like backup and restore corrupting your data. Now... one question is "Can I get the same dirty hack I used with PowerBuilder with FreeTDS?". I don't endorse this and if they ask I didn't suggest this but what you want is to set FreeTDS client encoding the same as server one. This way the bytes you send to FreeTDS library will be copied byte-to-byte to the server. Unless the PHP library uses wide characters, in this case FreeTDS will do the right thing and allows you to use CP850, not any random binary data. |
If I set the client DSN charset to CP850 and do not perform encoding conversion in the PHP script, the SQL statement is UTF-8 encoded. When executing the following code directly: $SQL = "update product set pro_scxkz='中文字符123' where pro_id='8124560'";
$conn->query($SQL); The result in freetds is If I encode the SQL statement as CP850 in PHP, this clearly fails—only CP936 works, but the stored value in the Sybase database remains non-standard.
When checking the freetds log, it appears freetds treats both Sybase and PHP-DSN as UTF-8. tdsdump_log(TDS_DBG_INFO1, "Converting from %s to %s\n", from->charset.name, to->charset.name);
tdsdump_log(TDS_DBG_INFO1, "Conversion direction: %s\n", (io == to_server) ? "to_server" : "to_client");
tdsdump_log(TDS_DBG_INFO1, "Client charset: %s\n", conv->from.charset.name);
tdsdump_log(TDS_DBG_INFO1, "Server charset: %s\n", conv->to.charset.name); Log Output:
I have no further way to debug freetds—the encoding behavior is strange. I tried recompiling freetds to force CP850/CP936/GB18030 encoding, but it still doesn’t work. I’m not very familiar with this and am just trying to make it function. When I set the DSN Due to non-standard programming practices at my company, I must insert Chinese characters into a Sybase database with CP850 charset. Please help.
|
Can you post some more logs? You can send to me privately. Also, it could be helpful to enable and send ODBC traces (refers to your driver manager documentation, see for instance https://www.freetds.org/userguide/logging.html#Logging.odbc). |
The logs have been sent to your e-mail. |
Uh oh!
There was an error while loading. Please reload this page.
Environment:
Problem Description:
When executing Chinese character updates via PHP PDO_ODBC:
Observed Behavior:
Update HEX result:
e4b8ade69687e5ad97e7aca6
(UTF-8 bytes)Expected behavior (as seen in PowerBuilder 6.5):
cbd53230313630333132
(CP936)Key Observations:
Request:
How to properly configure FreeTDS to:
Additional Notes:
No matter how much I change dsn= clientcharset=UTF-8 or CP936 or GB2312 , freetds seems to always send the SQL to the sybase server in UTF-8;
The text was updated successfully, but these errors were encountered: