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

RDB$GET_CONTEXT/RDB$SET_CONTEXT parameters incorrectly described as CHAR NOT NULL instead of VARCHAR NULLABLE. [CORE4156] #4483

Closed
firebird-issue-importer opened this issue Aug 3, 2013 · 17 comments

Comments

@firebird-issue-importer
Copy link

firebird-issue-importer commented Aug 3, 2013

Submitted by: @mrotteveel

Attachments:
trace_set_context.txt

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', ?) FROM RDB$DATABASE
with parameter 1 "TestProperty"

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it does send the actual length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value), so it seems to be specific to RDB$SET_CONTEXT with parameters.

EDIT:
See my comment at 04/Aug/13 01:56 PM: the cause seems to be the parameter description of the query with RDB$SET_CONTEXT: they are described as CHAR instead of VARCHAR.

Commits: 8a19e7a FirebirdSQL/fbt-repository@3a88585

====== Test Details ======

See comments inside .fbt related to sqltype for nullable args (differ in 2.5 vs 3.0).

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Modified by: @mrotteveel

description: The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', 'TestProperty', 'testValue') FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116,101,115,116,86,97,108,117,101,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar upto the declared length, padded with spaces, but it will prefix the right length (9). Testing with other varchars does not display this behavior.

=>

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', 'TestProperty', 'testValue') FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar upto the declared length, padded with spaces, but it will prefix the right length (9). Testing with other varchars does not display this behavior.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Modified by: @mrotteveel

description: The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', 'TestProperty', 'testValue') FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar upto the declared length, padded with spaces, but it will prefix the right length (9). Testing with other varchars does not display this behavior.

=>

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', 'TestProperty', 'testValue') FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it will declare the right length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value)

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Modified by: @mrotteveel

description: The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', 'TestProperty', 'testValue') FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it will declare the right length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value)

=>

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it will declare the right length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value)

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Modified by: @mrotteveel

description: The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it will declare the right length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value)

=>

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it does send the actual length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value), so it seems to be specific to RDB$SET_CONTEXT with parameters.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Commented by: @mrotteveel

Test is FBConnection.testClientInfo() (in trunk) or FBConnection4_0.testClientInfo() in branch Branch_2_2

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Commented by: @mrotteveel

Problem also applies to the variable name:

SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

does not produce a result, but

SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', ?) FROM RDB$DATABASE
with parameter 1 "TestProperty"

does.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 3, 2013

Modified by: @mrotteveel

description: The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') FROM RDB$DATABASE

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it does send the actual length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value), so it seems to be specific to RDB$SET_CONTEXT with parameters.

=>

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', ?) FROM RDB$DATABASE
with parameter 1 "TestProperty"

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it does send the actual length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value), so it seems to be specific to RDB$SET_CONTEXT with parameters.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Commented by: @mrotteveel

Trace in Firebird 3.0 shows (note the amount of whitespace):
Statement 21:
-------------------------------------------------------------------------------
SELECT rdb$set_context('USER_SESSION', ?, ?) session_context FROM rdb$database

param0 = varchar(80), "TestProperty "
param1 = varchar(255), "testValue ..."

2013-08-04T15:35:51.9100 (4940:0000000003184F10) SET_CONTEXT
D:\DEVELOPMENT\PROJECT\JAYBIRDECLIPSE\CLIENT-JAVA\FBTEST.FDB (ATT_8, SYSDBA:NONE, NONE, TCPv4:127.0.0.1)
(TRA_2, READ_COMMITTED | REC_VERSION | WAIT | READ_WRITE)
[USER_SESSION] TestProperty = "testValue "

In Firebird 2.5 it does:
Statement 40:
-------------------------------------------------------------------------------
SELECT rdb$set_context('USER_SESSION', ?, ?) session_context FROM rdb$database

param0 = varchar(80), "TestProperty"
param1 = varchar(255), "testValue"

2013-08-04T15:36:47.1510 (5136:00000000033C6020) SET_CONTEXT
D:\DEVELOPMENT\PROJECT\JAYBIRDECLIPSE\CLIENT-JAVA\FBTEST.FDB (ATT_3, SYSDBA:NONE, NONE, TCPv4:127.0.0.1)
(TRA_2, READ_COMMITTED | REC_VERSION | WAIT | READ_WRITE)
[USER_SESSION] TestProperty = "testValue"

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Commented by: @mrotteveel

Attached file with same data as previous comment, JIRA swallows the whitespace.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Modified by: @mrotteveel

Attachment: trace_set_context.txt [ 12358 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Commented by: @mrotteveel

Walking through the test using Firebird 2.5 and Firebird 3.0, I see that Firebird 2.5 describes the parameters to RDB$SET_CONTEXT as sqltype 449 (VARCHAR + nullable), but Firebird 3.0 describes it as sqltype 452 (CHAR + not nullable). The parameter type should be VARCHAR (and I'd say at least the value parameter should be nullable), see http://www.firebirdsql.org/file/documentation/reference_manuals/reference_material/html/langrefupd25-intfunc-set_context.html

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Modified by: @mrotteveel

description: The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', ?) FROM RDB$DATABASE
with parameter 1 "TestProperty"

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it does send the actual length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value), so it seems to be specific to RDB$SET_CONTEXT with parameters.

=>

The value returned by a query with RDB$GET_CONTEXT inside an XSQLVAR is padded with spaces upto the declared length (255), even though the value itself is declared as a VARCHAR(sqltype=449).

Eg setting the context using
SELECT RDB$SET_CONTEXT('USER_SESSION', ?, ?) FROM RDB$DATABASE
with parameter 1 "TestProperty" and parameter 2 "testValue"

And then retrieving the value using
SELECT RDB$GET_CONTEXT('USER_SESSION', ?) FROM RDB$DATABASE
with parameter 1 "TestProperty"

Will return "testValue<+246 spaces>" (or [116, 101, 115, 116, 86, 97, 108, 117, 101, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]

Firebird 2.5 and earlier exhibit the expected behavior (the returned value is "testValue" without any spaces). Strangely enough when I use flamerobin then the returned value is not padded, not even when I try with '|' || RDB$GET_CONTEXT('USER_SESSION', 'TestProperty') || '|', doing this with Jaybird does return the value padded (as "|testValue<+246 spaces>|").

The only reason I can think of is that the current version of Jaybird when sending the parameter value for the set context, it will send the varchar padded with spaces upto the declared length, but it does send the actual length (9). Testing with other varchars does not display this behavior (eg insert parametrized and select the value), so it seems to be specific to RDB$SET_CONTEXT with parameters.

EDIT:
See my comment at 04/Aug/13 01:56 PM: the cause seems to be the parameter description of the query with RDB$SET_CONTEXT: they are described as CHAR instead of VARCHAR.

summary: RDB$GET_CONTEXT value is padded with spaces upto the declared length (255) => RDB$SET_CONTEXT parameters incorrectly described as CHAR instead of VARCHAR

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Modified by: @asfernandes

assignee: Adriano dos Santos Fernandes [ asfernandes ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Modified by: @asfernandes

summary: RDB$SET_CONTEXT parameters incorrectly described as CHAR instead of VARCHAR => RDB$GET_CONTEXT/RDB$SET_CONTEXT parameters incorrectly described as CHAR NOT NULL instead of VARCHAR NULLABLE.

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Aug 4, 2013

Modified by: @asfernandes

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

resolution: Fixed [ 1 ]

Fix Version: 3.0 Alpha 2 [ 10560 ]

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented Mar 27, 2014

Modified by: @pcisar

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

@firebird-issue-importer
Copy link
Author

firebird-issue-importer commented May 28, 2015

Modified by: @pavel-zotov

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

QA Status: Done successfully

Test Details: See comments inside .fbt related to sqltype for nullable args (differ in 2.5 vs 3.0).

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