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
Attempt to insert in CHAR(1) UTF8 (and connection UTF8) throws string truncation error on native/embedded [JDBC233] #282
Comments
Modified by: @mrotteveelassignee: Roman Rokytskyy [ rrokytskyy ] => Mark Rotteveel [ avalanche1979 ] |
Modified by: @mrotteveelVersion: Jaybird 2.1.6 [ 10285 ] |
Modified by: @mrotteveel |
Commented by: @mrotteveel To check: |
Commented by: @mrotteveel With a database created with default characterset ISO8859_1, connection characterset NONE does work, UTF8 still returns an error. |
Commented by: @mrotteveel Simplified reproduction script using native library (see included readme.txt) |
Modified by: @mrotteveelAttachment: core3701.zip [ 12100 ] |
Commented by: @mrotteveel Found the cause. The data array in the XSQLVAR was shorter than the sqllen defined, either reducing the sqllen to the actual length or padding the data array seems to fix it. Padding might be the required course of action, because I believe the XSQLVARs are reused for multiple executions, and reducing the sqllen would break things. |
Commented by: @mrotteveel Found a workaround: Cast the parameter to a VARCHAR of the same type |
Commented by: @mrotteveel It looks like the code in xsqlda_wrapper.cpp should take care of padding, I need to find out why it isn't actually being executed for the SQL_TEXT. |
Commented by: @mrotteveel That padding code also contains a (potential) bug for character set NONE: It seems to be padding use 0x20 always, while I think NONE should pad with 0x00. |
Commented by: @mrotteveel Found the problem. The code for copying the Java XSQLVAR to a native XSQLVAR would first assign the (java) byte array size (two bytes) to the sqldata field, and then overwrite it with the bytearray. This poses no problem for any structure longer than two bytes, but in the case of single byte characters (in any encoding), this would cause a buffer overflow. In the case of single byte encodings this would not be a big problem (as the data area is 1 byte bigger then needed), but for UTF8 it would cause the padding to be overwritten by an unexpected byte value (eg for 'W' it would write out 0x57 0x00 0x20 0x20 instead of the expected 0x57 0x20 0x20 0x20. I also expect this could introduce unexpected characters in CHAR fields with a size longer than 1 when a single character is assigned. |
Modified by: @mrotteveelstatus: Open [ 1 ] => Resolved [ 5 ] resolution: Fixed [ 1 ] Fix Version: Jaybird 2.2 [ 10053 ] |
Modified by: @mrotteveelstatus: Resolved [ 5 ] => Closed [ 6 ] |
Submitted by: @mrotteveel
Replaces CORE3701
Attachments:
core3701.zip
Votes: 1
See CORE3701 for original issue.
Using a PreparedStatement to insert a single character into a CHAR(1) field in a UTF8 database using the UTF8 or NONE connection characterset using native or embedded results in:
SQL error code = -303
arithmetic exception, numeric overflow, or string truncation
string right truncation
This problem does not occur with the pure-java implementation.
Commits: 91c11e8
The text was updated successfully, but these errors were encountered: