@@ -127,6 +127,71 @@ def test_bulk_insert_against_gaussdb_url_from_env():
127127 _drop_table (conn , table_name )
128128
129129
130+ @pytest .mark .integration
131+ def test_real_table_lifecycle_crud_against_gaussdb_url_from_env ():
132+ engine = _engine ()
133+ table_name = _table_name ("gdbdrv_lifecycle_ut" )
134+ metadata = MetaData ()
135+ table = Table (
136+ table_name ,
137+ metadata ,
138+ Column ("id" , Integer , primary_key = True ),
139+ Column ("name" , String (32 ), nullable = False ),
140+ Column ("score" , Integer , nullable = False ),
141+ )
142+
143+ try :
144+ with engine .begin () as conn :
145+ _drop_table (conn , table_name )
146+ inspector = inspect (conn )
147+ assert inspector .has_table (table_name ) is False
148+
149+ table .create (conn )
150+ inspector .clear_cache ()
151+ assert inspector .has_table (table_name ) is True
152+
153+ columns = {column ["name" ]: column for column in inspector .get_columns (table_name )}
154+ assert set (columns ) == {"id" , "name" , "score" }
155+ assert columns ["id" ]["nullable" ] is False
156+ assert columns ["name" ]["nullable" ] is False
157+ assert columns ["score" ]["nullable" ] is False
158+
159+ conn .execute (
160+ table .insert (),
161+ [
162+ {"id" : 1 , "name" : "alice" , "score" : 90 },
163+ {"id" : 2 , "name" : "bob" , "score" : 80 },
164+ {"id" : 3 , "name" : "carol" , "score" : 70 },
165+ ],
166+ )
167+
168+ rows = conn .execute (
169+ select (table .c .id , table .c .name , table .c .score )
170+ .where (table .c .score >= 80 )
171+ .order_by (table .c .id )
172+ ).all ()
173+ assert rows == [(1 , "alice" , 90 ), (2 , "bob" , 80 )]
174+
175+ conn .execute (
176+ table .update ().where (table .c .id == 2 ).values (score = 85 )
177+ )
178+ assert conn .execute (
179+ select (table .c .score ).where (table .c .id == 2 )
180+ ).scalar_one () == 85
181+
182+ conn .execute (table .delete ().where (table .c .score < 80 ))
183+ remaining = conn .execute (
184+ select (table .c .id , table .c .name , table .c .score ).order_by (table .c .id )
185+ ).all ()
186+ assert remaining == [(1 , "alice" , 90 ), (2 , "bob" , 85 )]
187+ finally :
188+ with engine .begin () as conn :
189+ _drop_table (conn , table_name )
190+ inspector = inspect (conn )
191+ inspector .clear_cache ()
192+ assert inspector .has_table (table_name ) is False
193+
194+
130195@pytest .mark .integration
131196def test_orm_crud_against_gaussdb_url_from_env ():
132197 engine = _engine ()
0 commit comments