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

Values greater than number of days between 01.01.0001 and 31.12.9999 (=3652058) can be added or subtracted from DATE [CORE6241] #6485

Closed
firebird-issue-importer opened this issue Feb 1, 2020 · 5 comments

Comments

@firebird-issue-importer
Copy link

@firebird-issue-importer firebird-issue-importer commented Feb 1, 2020

Submitted by: @pavel-zotov

Consider following statements. Some of them PASS but they obviously are pointless and must fail (checked on 2.5.9, 3.0.6, 4.0.0 -- result is the same).

set list on;

-- J4YI:
-- select datediff( day from date '01.02.2020' to date '31.12.9999') from rdb$database; -- 2914603
-- select datediff( day from date '01.01.0001' to date '01.02.2020') from rdb$database; -- 737455
-- select datediff( day from date '01.01.0001' to date '31.12.9999') from rdb$database; -- 3652058
-- set echo on;

-- #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠ 1. ADDITION #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠

select date '01.02.2020' + 2914603 from rdb$database; -- OK, as expected: 9999-12-31

select date '01.02.2020' + 2914604 from rdb$database; -- OK, as expected: SQLSTATE = 22008 (value exceeds the range for valid dates)

select date '01.02.2020' + 2147483647 from rdb$database; -- OK, as expected: SQLSTATE = 22008

select date '01.02.2020' + 2147483648 from rdb$database; -- OK, as expected: SQLSTATE = 22008

select date '01.02.2020' + 4294229840 from rdb$database; -- OK, as expected: SQLSTATE = 22008

select date '01.02.2020' + 4294229841 from rdb$database; -- ???? 0001-01-01; NB: 4294967296 - 4294229841 = 737455 -- days since 01.01.0001 to 01.02.2020

select date '01.02.2020' + 9223372036854775807 from rdb$database; -- ???? 2020-01-31

-- #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠ 2. SUBTRACTION #⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠#⁠

select date '01.02.2020' - 737455 from rdb$database; -- OK, as expected: 0001-01-01

select date '01.02.2020' - 737456 from rdb$database; -- OK, as expected: SQLSTATE = 22008 (value exceeds the range for valid dates)

select date '01.02.2020' - 2147483648 from rdb$database; -- OK, as expected: SQLSTATE = 22008

select date '01.02.2020' - 4292052692 from rdb$database; -- OK, as expected: SQLSTATE = 22008

select date '01.02.2020' - 4292052693 from rdb$database; -- ???? 9999-12-31; NB: 4294967296 - 4292052693 = 2914603 -- days since 01.02.2020 to 31.12.9999

select date '01.02.2020' - 9223372036854775807 from rdb$database; -- ???? 2020-02-02

select date '01.02.2020' + -9223372036854775808 from rdb$database; -- ???? 2020-02-01

PS.

IMO, this is not a bug from practice point of view (i can not imagine that such expressions can be in use in any apps ). But compiler (or engine ?) for sure must decline all terms that we attempt to add/subtract from DATE with magniotude more that allowed by built-in limits of this type.

Commits: baf8bc1 0734f69 53e74d2 fcae494

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 2, 2020

Modified by: @asfernandes

assignee: Adriano dos Santos Fernandes [ asfernandes ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 3, 2020

Modified by: @asfernandes

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

resolution: Fixed [ 1 ]

Fix Version: 4.0 Beta 2 [ 10888 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 3, 2020

Modified by: @asfernandes

issuetype: Improvement [ 4 ] => Bug [ 1 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 4, 2020

Modified by: @pavel-zotov

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

QA Status: No test => Done successfully

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Feb 4, 2020

Modified by: @pavel-zotov

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

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

Successfully merging a pull request may close this issue.

None yet
2 participants