Skip to content
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

JNI Implementation for writing VARCHAR (SQL_VARYING) writes too much data [JDBC237] #286

Closed
firebird-automations opened this issue Feb 15, 2012 · 9 comments

Comments

@firebird-automations
Copy link

Submitted by: @mrotteveel

The XSQLVAR handling for a VARCHAR (SQL_VARYING) writes to much data. It uses sqllen + 3 bytes (and 0x20 pads it) where actual data length + 2 is sufficient.

Also for both SQL_TEXT and SQL_VARYING it is null-terminating the byte-array, which is not necessary.

See thread: http://sourceforge.net/mailarchive/forum.php?thread_name=4F37C03E.40105%40lawinegevaar.nl&forum_name=firebird-devel

Commits: 0a4ee8b FirebirdSQL/fbt-repository@47cf080

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

description: The XSQLVAR handling for a VARCHAR (SQL_VARYING) writes to much data. It uses sqllen + 3 bytes (and 0x20 pads it) where actual data length + 2 is sufficient.

Also for both SQL_TEXT and SQL_VARYING it is null-terminating the byte-array, which is not necessary.

=>

The XSQLVAR handling for a VARCHAR (SQL_VARYING) writes to much data. It uses sqllen + 3 bytes (and 0x20 pads it) where actual data length + 2 is sufficient.

Also for both SQL_TEXT and SQL_VARYING it is null-terminating the byte-array, which is not necessary.

See thread: http://sourceforge.net/mailarchive/forum.php?thread_name=4F37C03E.40105%40lawinegevaar.nl&forum_name=firebird-devel

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Check pure-java implementation as well.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Fix Version: Jaybird 2.3 [ 10440 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

The approach taken by FDB is interesting: it saves the sqllen and sqltype in a separate location at preparation time. At execute time it restores the original values, and converts sqltype SQL_VARYING to SQL_TEXT and sets the sqllen for SQL_VARYING and SQL_TEXT to the actual data length.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Changed JnaStatement to set sqllen to the minimum of the field length or the actual data length in the case of SQL_TEXT and SQL_VARYING. Need to double check if this works correctly with multibyte character sets.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

assignee: Roman Rokytskyy [ rrokytskyy ] => Mark Rotteveel [ avalanche1979 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Added test that writes a UTF8 CHAR and VARCHAR field and reads back the inserted value.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment