File tree Expand file tree Collapse file tree 4 files changed +57
-4
lines changed Expand file tree Collapse file tree 4 files changed +57
-4
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ _mysql_Exception(_mysql_ConnectionObject *c)
180180#ifdef ER_NO_DEFAULT_FOR_FIELD
181181 case ER_NO_DEFAULT_FOR_FIELD :
182182#endif
183+ case ER_BAD_NULL_ERROR :
183184 e = _mysql_IntegrityError ;
184185 break ;
185186#ifdef ER_WARNING_NOT_COMPLETE_ROLLBACK
Original file line number Diff line number Diff line change 1111
1212
1313class DatabaseTest (unittest .TestCase ):
14-
1514 db_module = None
1615 connect_args = ()
1716 connect_kwargs = dict ()
@@ -20,7 +19,6 @@ class DatabaseTest(unittest.TestCase):
2019 debug = False
2120
2221 def setUp (self ):
23-
2422 db = connection_factory (** self .connect_kwargs )
2523 self .connection = db
2624 self .cursor = db .cursor ()
@@ -67,7 +65,6 @@ def new_table_name(self):
6765 i = i + 1
6866
6967 def create_table (self , columndefs ):
70-
7168 """Create a table using a list of column definitions given in
7269 columndefs.
7370
Original file line number Diff line number Diff line change 1212
1313
1414class test_MySQLdb (capabilities .DatabaseTest ):
15-
1615 db_module = MySQLdb
1716 connect_args = ()
1817 connect_kwargs = dict (
Original file line number Diff line number Diff line change 1+ import pytest
2+ import MySQLdb .cursors
3+ from configdb import connection_factory
4+
5+
6+ _conns = []
7+ _tables = []
8+
9+
10+ def connect (** kwargs ):
11+ conn = connection_factory (** kwargs )
12+ _conns .append (conn )
13+ return conn
14+
15+
16+ def teardown_function (function ):
17+ if _tables :
18+ c = _conns [0 ]
19+ cur = c .cursor ()
20+ for t in _tables :
21+ cur .execute ("DROP TABLE {}" .format (t ))
22+ cur .close ()
23+ del _tables [:]
24+
25+ for c in _conns :
26+ c .close ()
27+ del _conns [:]
28+
29+
30+ def test_null ():
31+ """Inserting NULL into non NULLABLE column"""
32+ # https://github.com/PyMySQL/mysqlclient/issues/535
33+ table_name = "test_null"
34+ conn = connect ()
35+ cursor = conn .cursor ()
36+
37+ cursor .execute (f"create table { table_name } (c1 int primary key)" )
38+ _tables .append (table_name )
39+
40+ with pytest .raises (MySQLdb .IntegrityError ):
41+ cursor .execute (f"insert into { table_name } values (null)" )
42+
43+
44+ def test_duplicated_pk ():
45+ """Inserting row with duplicated PK"""
46+ # https://github.com/PyMySQL/mysqlclient/issues/535
47+ table_name = "test_duplicated_pk"
48+ conn = connect ()
49+ cursor = conn .cursor ()
50+
51+ cursor .execute (f"create table { table_name } (c1 int primary key)" )
52+ _tables .append (table_name )
53+
54+ cursor .execute (f"insert into { table_name } values (1)" )
55+ with pytest .raises (MySQLdb .IntegrityError ):
56+ cursor .execute (f"insert into { table_name } values (1)" )
You can’t perform that action at this time.
0 commit comments