1
1
#!/usr/bin/env python
2
2
import capabilities
3
+ from datetime import timedelta
3
4
import unittest
4
5
import MySQLdb
5
6
import warnings
6
7
8
+
7
9
warnings .filterwarnings ('ignore' )
8
10
11
+
9
12
class test_MySQLdb (capabilities .DatabaseTest ):
10
13
11
14
db_module = MySQLdb
12
15
connect_args = ()
13
16
connect_kwargs = dict (use_unicode = True , sql_mode = "ANSI,STRICT_TRANS_TABLES,TRADITIONAL" )
14
17
create_table_extra = "ENGINE=INNODB CHARACTER SET UTF8"
15
18
leak_test = False
16
-
19
+
17
20
def quote_identifier (self , ident ):
18
21
return "`%s`" % ident
19
22
20
23
def test_TIME (self ):
21
- from datetime import timedelta
22
24
def generator (row ,col ):
23
25
return timedelta (0 , row * 8000 )
24
26
self .check_data_integrity (
@@ -27,23 +29,23 @@ def generator(row,col):
27
29
28
30
def test_TINYINT (self ):
29
31
# Number data
30
- def generator (row ,col ):
32
+ def generator (row , col ):
31
33
v = (row * row ) % 256
32
34
if v > 127 :
33
35
v = v - 256
34
36
return v
35
37
self .check_data_integrity (
36
38
('col1 TINYINT' ,),
37
39
generator )
38
-
40
+
39
41
def test_stored_procedures (self ):
40
42
db = self .connection
41
43
c = self .cursor
42
44
self .create_table (('pos INT' , 'tree CHAR(20)' ))
43
45
c .executemany ("INSERT INTO %s (pos,tree) VALUES (%%s,%%s)" % self .table ,
44
46
list (enumerate ('ash birch cedar larch pine' .split ())))
45
47
db .commit ()
46
-
48
+
47
49
c .execute ("""
48
50
CREATE PROCEDURE test_sp(IN t VARCHAR(255))
49
51
BEGIN
@@ -57,7 +59,7 @@ def test_stored_procedures(self):
57
59
self .assertEquals (len (rows ), 1 )
58
60
self .assertEquals (rows [0 ][0 ], 3 )
59
61
c .nextset ()
60
-
62
+
61
63
c .execute ("DROP PROCEDURE test_sp" )
62
64
c .execute ('drop table %s' % (self .table ))
63
65
@@ -71,7 +73,29 @@ def generator(row,col):
71
73
self .check_data_integrity (
72
74
('col1 char(1)' ,'col2 char(1)' ),
73
75
generator )
74
-
76
+
77
+ def test_BIT (self ):
78
+ c = self .cursor
79
+ try :
80
+ c .execute ("""create table test_BIT (
81
+ b3 BIT(3),
82
+ b7 BIT(10),
83
+ b64 BIT(64))""" )
84
+
85
+ one64 = '1' * 64
86
+ c .execute (
87
+ "insert into test_BIT (b3, b7, b64)"
88
+ " VALUES (b'011', b'1111111111', b'%s')"
89
+ % one64 )
90
+
91
+ c .execute ("SELECT b3, b7, b64 FROM test_BIT" )
92
+ row = c .fetchone ()
93
+ self .assertEqual (row [0 ], b'\x03 ' )
94
+ self .assertEqual (row [1 ], b'\x03 \xff ' )
95
+ self .assertEqual (row [2 ], b'\xff ' * 8 )
96
+ finally :
97
+ c .execute ("drop table if exists test_BIT" )
98
+
75
99
def test_bug_2671682 (self ):
76
100
from MySQLdb .constants import ER
77
101
try :
@@ -102,7 +126,7 @@ def test_reraise_exception(self):
102
126
return
103
127
self .fail ("Should raise ProgrammingError" )
104
128
105
-
129
+
106
130
if __name__ == '__main__' :
107
131
if test_MySQLdb .leak_test :
108
132
import gc
0 commit comments