2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-24 20:27:02 +01:00
"""
ID : issue - 5039
ISSUE : 5039
2022-02-02 15:46:19 +01:00
TITLE : Command " Alter table <T> alter TYPE <C> <DOMAIN_WITH_NOT_NULL " does not verifies
data in column < C > and makes incorrect assignments in < C > to ZERO / JULIAN_DATE / ASCII ( 0 )
for types INT , TIMESTAMP and VARCHAR
2022-01-24 20:27:02 +01:00
DESCRIPTION :
JIRA : CORE - 4733
2022-02-02 15:46:19 +01:00
FBTEST : bugs . core_4733
2022-01-24 20:27:02 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
import pytest
from firebird . qa import *
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
db = db_factory ( )
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
- - Tests that manipulates with NULL fields / domains and check results :
- - CORE - 1518 Adding a non - null restricted column to a populated table renders the table inconsistent
- - CORE - 4453 ( Regression : NOT NULL constraint , declared in domain , does not work )
- - CORE - 4725 ( Inconsistencies with ALTER DOMAIN and ALTER TABLE with DROP NOT NULL and PRIMARY KEYs )
- - CORE - 4733 ( Command " Alter table <T> alter TYPE <C> <DOMAIN_WITH_NOT_NULL " does not verifies data in column < C > and makes incorrect assignments in < C > to ZERO / JULIAN_DATE / ASCII ( 0 ) for types INT , TIMESTAMP and VARCHAR )
create domain dm_nn_int int NOT null ;
create domain dm_nn_dts timestamp NOT null ;
create domain dm_nn_utf varchar ( 10 ) character set utf8 NOT null ;
create domain dm_nn_boo boolean NOT null ;
set list on ;
create table test ( num int , dts timestamp , str varchar ( 10 ) character set utf8 , boo boolean ) ;
commit ;
insert into test values ( null , null , null , null ) ;
commit ;
2022-01-24 20:27:02 +01:00
alter table test
2021-04-26 20:07:00 +02:00
alter num type dm_nn_int
2022-01-24 20:27:02 +01:00
, alter dts type dm_nn_dts
2021-04-26 20:07:00 +02:00
, alter str type dm_nn_utf
, alter boo type dm_nn_boo
;
commit ;
show table test ;
delete from test returning num , dts , str , boo ;
commit ;
2022-01-24 20:27:02 +01:00
alter table test
2021-04-26 20:07:00 +02:00
alter num type dm_nn_int
2022-01-24 20:27:02 +01:00
, alter dts type dm_nn_dts
2021-04-26 20:07:00 +02:00
, alter str type dm_nn_utf
, alter boo type dm_nn_boo
;
commit ;
insert into test values ( null , null , null , null ) ;
commit ;
show table test ;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
act = isql_act ( ' db ' , test_script )
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
expected_stdout = """
NUM INTEGER Nullable
DTS TIMESTAMP Nullable
STR VARCHAR ( 10 ) CHARACTER SET UTF8 Nullable
BOO BOOLEAN Nullable
2021-04-26 20:07:00 +02:00
NUM < null >
DTS < null >
STR < null >
BOO < null >
2022-01-24 20:27:02 +01:00
NUM ( DM_NN_INT ) INTEGER Not Null
DTS ( DM_NN_DTS ) TIMESTAMP Not Null
STR ( DM_NN_UTF ) VARCHAR ( 10 ) CHARACTER SET UTF8 Not Null
BOO ( DM_NN_BOO ) BOOLEAN Not Null
2021-12-22 20:23:11 +01:00
"""
2022-01-24 20:27:02 +01:00
expected_stderr = """
2021-04-26 20:07:00 +02:00
Statement failed , SQLSTATE = 22006
unsuccessful metadata update
- Cannot make field NUM of table TEST NOT NULL because there are NULLs present
- Cannot make field DTS of table TEST NOT NULL because there are NULLs present
- Cannot make field STR of table TEST NOT NULL because there are NULLs present
- Cannot make field BOO of table TEST NOT NULL because there are NULLs present
Statement failed , SQLSTATE = 23000
validation error for column " TEST " . " NUM " , value " *** null *** "
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version ( ' >=3.0 ' )
2022-01-24 20:27:02 +01:00
def test_1 ( act : Action ) :
act . expected_stdout = expected_stdout
act . expected_stderr = expected_stderr
act . execute ( )
assert ( act . clean_stderr == act . clean_expected_stderr and
act . clean_stdout == act . clean_expected_stdout )
2021-04-26 20:07:00 +02:00