|
| 1 | +#coding:utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +ID: issue-5962 |
| 5 | +ISSUE: https://github.com/FirebirdSQL/firebird/issues/5962 |
| 6 | +TITLE: Conversion from zero numeric literals to DECFLOAT results in incorrect value |
| 7 | +NOTES: |
| 8 | + Test should be added during initial migration from fbtest but did not, the reason is unknown. |
| 9 | + Noted by Anton Zuev: https://github.com/FirebirdSQL/firebird-qa/pull/6 |
| 10 | + Checked on 4.0.3.2904, 5.0.0.970 |
| 11 | +FBTEST: bugs.core_5696 |
| 12 | +""" |
| 13 | + |
| 14 | +import pytest |
| 15 | +from firebird.qa import * |
| 16 | + |
| 17 | +db = db_factory() |
| 18 | + |
| 19 | +test_script = """ |
| 20 | + set list on; |
| 21 | + recreate table df16(id_df16 int, val_df16 decfloat(16)); |
| 22 | + recreate table df34(id_df34 int, val_df34 decfloat(34)); |
| 23 | + commit; |
| 24 | +
|
| 25 | + -- 06-jan-2018 |
| 26 | + -- =========== |
| 27 | + insert into df16 values( 1, -0); |
| 28 | + insert into df16 values( 2, -0E300); |
| 29 | + insert into df16 values( 3, -0E+300); |
| 30 | + insert into df16 values( 4, -0.0E+300); |
| 31 | + insert into df16 values( 5, 0E+300); |
| 32 | + insert into df16 values( 6, 0E-300); |
| 33 | +
|
| 34 | + -- 22-jun-2019 |
| 35 | + -- =========== |
| 36 | + insert into df16 values( 7, 0e+370); |
| 37 | + insert into df16 values( 8, 0e-399); |
| 38 | + insert into df16 values( 9, 0e+6111); |
| 39 | + insert into df16 values( 10, 0e-6167); |
| 40 | +
|
| 41 | + insert into df16 values( 11, 1e-6176); |
| 42 | + insert into df16 values( 12, 1e+6111); -- must raise SQLSTATE = 22003 Decimal float overflow. The exponent of a result is greater than the magnitude allowed. |
| 43 | + insert into df16 values( 13, 1e+6144); -- must raise SQLSTATE = 22003 Decimal float overflow. The exponent of a result is greater than the magnitude allowed. |
| 44 | + insert into df16 values( 14, 1.234567890123456789012345678901234E0); |
| 45 | + insert into df16 values( 15, 9999999999999999E+369); |
| 46 | +
|
| 47 | + select t.* from df16 t; |
| 48 | +
|
| 49 | + ---------------------------------------------- |
| 50 | +
|
| 51 | + -- 22-jun-2019 |
| 52 | + -- =========== |
| 53 | + insert into df34 values( 1, 0e+370); |
| 54 | + insert into df34 values( 2, 0e-399); |
| 55 | + insert into df34 values( 3, 0e+6111); |
| 56 | + insert into df34 values( 4, 0e-6167); |
| 57 | + insert into df34 values( 5, 1e-6176); |
| 58 | + insert into df34 values( 6, 1e385); -- DID raise overflow in WI-T4.0.0.1535, i.e. before this ticket was fixed; ticket sample: 1e+6111 |
| 59 | + insert into df34 values( 7, -1e385); -- DID raise overflow in WI-T4.0.0.1535, i.e. before this ticket was fixed; ticket sample: 1e+6144 |
| 60 | + insert into df34 values( 8, 1e+6111); |
| 61 | + insert into df34 values( 9, 1.234567890123456789012345678901234E0); |
| 62 | + |
| 63 | + select t.* from df34 t; |
| 64 | +""" |
| 65 | + |
| 66 | +act = isql_act('db', test_script, substitutions=[('[ \t]+', ' ')]) |
| 67 | + |
| 68 | +expected_stdout = """ |
| 69 | + ID_DF16 1 |
| 70 | + VAL_DF16 -0 |
| 71 | +
|
| 72 | + ID_DF16 2 |
| 73 | + VAL_DF16 -0E+300 |
| 74 | +
|
| 75 | + ID_DF16 3 |
| 76 | + VAL_DF16 -0E+300 |
| 77 | +
|
| 78 | + ID_DF16 4 |
| 79 | + VAL_DF16 -0E+299 |
| 80 | +
|
| 81 | + ID_DF16 5 |
| 82 | + VAL_DF16 0E+300 |
| 83 | +
|
| 84 | + ID_DF16 6 |
| 85 | + VAL_DF16 0E-300 |
| 86 | +
|
| 87 | + ID_DF16 7 |
| 88 | + VAL_DF16 0E+369 |
| 89 | +
|
| 90 | + ID_DF16 8 |
| 91 | + VAL_DF16 0E-398 |
| 92 | +
|
| 93 | + ID_DF16 9 |
| 94 | + VAL_DF16 0E+369 |
| 95 | +
|
| 96 | + ID_DF16 10 |
| 97 | + VAL_DF16 0E-398 |
| 98 | +
|
| 99 | + ID_DF16 11 |
| 100 | + VAL_DF16 0E-398 |
| 101 | +
|
| 102 | + ID_DF16 14 |
| 103 | + VAL_DF16 1.234567890123457 |
| 104 | +
|
| 105 | + ID_DF16 15 |
| 106 | + VAL_DF16 9.999999999999999E+384 |
| 107 | +
|
| 108 | +
|
| 109 | +
|
| 110 | + ID_DF34 1 |
| 111 | + VAL_DF34 0E+370 |
| 112 | +
|
| 113 | + ID_DF34 2 |
| 114 | + VAL_DF34 0E-399 |
| 115 | +
|
| 116 | + ID_DF34 3 |
| 117 | + VAL_DF34 0E+6111 |
| 118 | +
|
| 119 | + ID_DF34 4 |
| 120 | + VAL_DF34 0E-6167 |
| 121 | +
|
| 122 | + ID_DF34 5 |
| 123 | + VAL_DF34 1E-6176 |
| 124 | +
|
| 125 | + ID_DF34 6 |
| 126 | + VAL_DF34 1E+385 |
| 127 | +
|
| 128 | + ID_DF34 7 |
| 129 | + VAL_DF34 -1E+385 |
| 130 | +
|
| 131 | + ID_DF34 8 |
| 132 | + VAL_DF34 1E+6111 |
| 133 | +
|
| 134 | + ID_DF34 9 |
| 135 | + VAL_DF34 1.234567890123456789012345678901234 |
| 136 | +""" |
| 137 | + |
| 138 | +expected_stderr = """ |
| 139 | + Statement failed, SQLSTATE = 22003 |
| 140 | + Decimal float overflow. The exponent of a result is greater than the magnitude allowed. |
| 141 | +
|
| 142 | + Statement failed, SQLSTATE = 22003 |
| 143 | + Decimal float overflow. The exponent of a result is greater than the magnitude allowed. |
| 144 | +""" |
| 145 | + |
| 146 | +@pytest.mark.version('>=4.0') |
| 147 | +def test_1(act: Action): |
| 148 | + act.expected_stdout = expected_stdout |
| 149 | + act.expected_stderr = expected_stderr |
| 150 | + act.execute() |
| 151 | + assert act.clean_stdout == act.clean_expected_stdout and act.clean_stderr == act.clean_expected_stderr |
0 commit comments