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

FBClient: non-nullable parameter with null value should be sent as nullable [CORE3913] #4248

Open
firebird-automations opened this issue Aug 29, 2012 · 7 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @mrotteveel

Relate to JDBC271

Votes: 1

In Firebird 2.5.0 and 2.5.1 (and probably earlier), parameters are described with the nullability of their columns. If a user of the fbclient library sets everything correct for this parameter in the xsqlvar to send a NULL value (eg sets sqlind to -1), but does not enable the nullable bit of sqltype, then the fbclient will ignore the sqlind value and send the parameter as if it was a NON NULL value (eg empty string for (VAR)CHAR, 0 for INT, etc).

I think it would be better if - for sending parameters from client to server - the sqlind value is leading, not the nullability flag of sqltype (the server doesn't care, as this is exactly what the pure Java implementation of Jaybird does).

The current parameter description can lead to situation where you think you are using NULL, where in reality you are using the NOT NULL counterpart.

For example:
CREATE TABLE SINGLE_VARCHAR
(
VARCHARCOLUMN Varchar(1) NOT NULL
);

Now we try to insert using:
INSERT INTO SINGLE_VARCHAR(VARCHARCOLUMN) VALUES (?)

With the native client and doing everything in the xsqlvar except setting the nullable bit of sqltype will result in the empty string being inserted instead of getting GDS Exception. 335544347. validation error for column VARCHARCOLUMN, value "*** null ***" as the client library will send the value as if it is not null.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

BTW: This is related to CORE3475 and JDBC271

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Component: API / Client Library [ 10040 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

description: In Firebird 2.5.0 and 2.5.1 (and probably earlier), parameters are described with the nullability of their columns. If a user of the fbclient library sets everything correct for this parameter in the xsqlvar to send a NULL value (eg sets sqlind to -1), but does not enable the nullable bit of sqltype, then the fbclient will ignore the sqlind value and send the parameter as if it was a NON NULL value (eg empty string for (VAR)CHAR, 0 for INT, etc).

I think it would be better if - for sending parameters from client to server - the sqlind value is leading, not the nullability flag of sqltype (the server doesn't care, as this is exactly what the pure ava implementation of Jaybird does).

The current parameter description can lead to situation where you think you are using NULL, where in reality you are using the NOT NULL counterpart.

For example:
CREATE TABLE SINGLE_VARCHAR
(
VARCHARCOLUMN Varchar(1) NOT NULL
);

Now we try to insert using:
INSERT INTO SINGLE_VARCHAR(VARCHARCOLUMN) VALUES (?)

With the native client and doing everything in the xsqlvar except setting the nullable bit of sqltype will result in the empty string being inserted instead of getting GDS Exception. 335544347. validation error for column VARCHARCOLUMN, value "*** null ***" as the client library will send the value as if it is not null.

=>

In Firebird 2.5.0 and 2.5.1 (and probably earlier), parameters are described with the nullability of their columns. If a user of the fbclient library sets everything correct for this parameter in the xsqlvar to send a NULL value (eg sets sqlind to -1), but does not enable the nullable bit of sqltype, then the fbclient will ignore the sqlind value and send the parameter as if it was a NON NULL value (eg empty string for (VAR)CHAR, 0 for INT, etc).

I think it would be better if - for sending parameters from client to server - the sqlind value is leading, not the nullability flag of sqltype (the server doesn't care, as this is exactly what the pure Java implementation of Jaybird does).

The current parameter description can lead to situation where you think you are using NULL, where in reality you are using the NOT NULL counterpart.

For example:
CREATE TABLE SINGLE_VARCHAR
(
VARCHARCOLUMN Varchar(1) NOT NULL
);

Now we try to insert using:
INSERT INTO SINGLE_VARCHAR(VARCHARCOLUMN) VALUES (?)

With the native client and doing everything in the xsqlvar except setting the nullable bit of sqltype will result in the empty string being inserted instead of getting GDS Exception. 335544347. validation error for column VARCHARCOLUMN, value "*** null ***" as the client library will send the value as if it is not null.

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

Link: This issue relate to JDBC271 [ JDBC271 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @aafemt

No way. Data access components must throw an exception when user is trying to assign NULL to non-nullable parameter.
sqlind may be not initialized (filled with random value) for such parameters and client library will cause AV trying to get value from random memory address.

@firebird-automations
Copy link
Collaborator Author

Commented by: @mrotteveel

I get your point. I forgot that sqlind is a pointer.

I however disagree with your statement that the access component should throw an exception when assigning NULL to a non-nullable parameter. There are sufficient use cases where you as an end-user of the access component want to be able to set null to a non-nullable parameter. For example having a NOT NULL column with a trigger which will - for example - assign a generated value if the column is NULL.

Maybe instead Firebird should describe parameters as always being nullable, but that would prevent clientside decisions based on the nullability.

@firebird-automations
Copy link
Collaborator Author

Modified by: @mrotteveel

priority: Major [ 3 ] => Minor [ 4 ]

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

No branches or pull requests

1 participant