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

Can assign null to a small integer not-null column [CORE1252] #1676

Closed
firebird-automations opened this issue May 9, 2007 · 11 comments
Closed

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Hashim Kubba (hkubba)

Attachments:
screenshot-1.jpg
data.fdb

Say I have this in my database:

CREATE DOMAIN D_BOOLEAN
AS SMALLINT
DEFAULT 0
NOT NULL
CHECK (VALUE IN (1, 0));

CREATE TABLE ADDRESS
(
POSTALCODE Varchar(7) NOT NULL,
STREET Varchar(100),
CITY Varchar(100),
CHECKED D_Boolean NOT NULL,
PRIMARY KEY (POSTALCODE)
);

Theatrically; I can not assign null to the checked column, yet running:

INSERT INTO ADDRESS (POSTALCODE, STREET, CITY, CHECKED)
VALUES (
'POSTALCODE',
'STREET',
'CITY',
NULL
)

Returns no error, and the record is added to the database

Regards,

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

What is the value of CHECKED in the database?

@firebird-automations
Copy link
Collaborator Author

Commented by: Hashim Kubba (hkubba)

valur in database is null

@firebird-automations
Copy link
Collaborator Author

Modified by: Hashim Kubba (hkubba)

Attachment: screenshot-1.jpg [ 10360 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Is this the exact sequence of commands to reproduce?
I can't reproduce using the same versions as you.

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

I cannot reproduce it either. Tried 1.5.3, 2.0.0 and 2.0.1. By the way, column POSTALCODE should be at least 10 characters long to make your INSERT workable.

@firebird-automations
Copy link
Collaborator Author

Commented by: Hashim Kubba (hkubba)

OK here is the sequence:
I first created my tables with these scripts

CREATE DOMAIN D_BOOLEAN
AS SMALLINT
DEFAULT 0
NOT NULL
CHECK (VALUE IN (1, 0));

CREATE TABLE ADDRESS
(
POSTALCODE Varchar(7) NOT NULL,
STREET Varchar(100),
CITY Varchar(100),
CHECKED D_Boolean NOT NULL,
PRIMARY KEY (POSTALCODE)
);

GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON ADDRESS TO SYSDBA WITH GRANT OPTION;

CREATE TABLE PROPERTY
(
MLS Varchar(8) NOT NULL,
ADDRESS Varchar(7),
PRICE Float,
CONDOFEE Float,
AREA Smallint,
DISTANCETOSQ1 Smallint,
TIMETOSQ1 Time,
PRIMARY KEY (MLS)
);

ALTER TABLE PROPERTY ADD CONSTRAINT FKF373CDD58C0439D3
FOREIGN KEY (ADDRESS) REFERENCES ADDRESS (POSTALCODE);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON PROPERTY TO SYSDBA WITH GRANT OPTION;

If I use the insert now it will not work as expected
So running
INSERT INTO ADDRESS (POSTALCODE, STREET, CITY, CHECKED)
VALUES (
'POSTAL',
'STREET',
'CITY',
NULL
);

Will give an error :
Message: isc_dsql_execute2 failed

SQL Message : -625
The insert failed because a column definition includes validation constraints.

Engine Code : 335544347
Engine Message :
validation error for column CHECKED, value "*** null ***"

This is correct,

What I did then is tried to use hibernate and jaybird to connect to my java program, yet I did not set any thing in the checked field thinking it will use 0 by default, and I used the java.lang.Short object which can be null,

Inserting from there showed a value of NULL

And afterwards, when I run my insert it will be accepted:

INSERT INTO ADDRESS (POSTALCODE, STREET, CITY, CHECKED)
VALUES (
'POSTAL',
'STREET',
'CITY',
NULL
)

Will result
Starting transaction...
Preparing query: INSERT INTO ADDRESS (POSTALCODE, STREET, CITY, CHECKED)
VALUES (
'POSTAL',
'STREET',
'CITY',
NULL
)
Prepare time: 00:00:00.
Plan not available.

Executing...
Done.
1 row(s) affected.
Execute time: 00:00:00.

Attached also is the database I used

@firebird-automations
Copy link
Collaborator Author

Modified by: Hashim Kubba (hkubba)

Attachment: data.fdb [ 10370 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

The database you attached is not as the one you described.
ADDRESS.CHECKED is not based on D_BOOLEAN, hasn't check constraint and is NULLable.

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

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

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

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

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 12061 ] => Firebird [ 15563 ]

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