5
5
import decimal
6
6
import math
7
7
import os
8
- import string
9
8
import unittest
10
9
11
10
from requests .exceptions import InvalidJSONError
@@ -1202,9 +1201,11 @@ def test_character_lengths(self):
1202
1201
if 'http' in self .conn .driver :
1203
1202
self .skipTest ('Character lengths too long for HTTP interface' )
1204
1203
1204
+ tbl_id = str (id (self ))
1205
+
1205
1206
self .cur .execute ('DROP TABLE IF EXISTS test_character_lengths' )
1206
- self .cur .execute (r '''
1207
- CREATE TABLE `test_character_lengths ` (
1207
+ self .cur .execute (rf '''
1208
+ CREATE TABLE `test_character_lengths_ { tbl_id } ` (
1208
1209
`id` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
1209
1210
`char_col` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
1210
1211
`int_col` INT,
@@ -1216,46 +1217,43 @@ def test_character_lengths(self):
1216
1217
SQL_MODE='STRICT_ALL_TABLES'
1217
1218
''' )
1218
1219
1219
- CHAR_STR = string .ascii_letters * 1
1220
- SHORT_STR = string .ascii_letters * 10
1221
- INT24_STR = string .ascii_letters * 1500
1222
- INT64_STR = string .ascii_letters * 1500000
1220
+ CHAR_STR_SHORT = 'a'
1221
+ CHAR_STR_LONG = 'a' * (2 ** 8 - 1 )
1222
+ SHORT_STR_SHORT = 'a' * ((2 ** 8 - 1 ) + 1 )
1223
+ SHORT_STR_LONG = 'a' * (2 ** 16 - 1 )
1224
+ INT24_STR_SHORT = 'a' * ((2 ** 16 - 1 ) + 1 )
1225
+ INT24_STR_LONG = 'a' * (2 ** 24 - 1 )
1226
+ INT64_STR_SHORT = 'a' * ((2 ** 24 - 1 ) + 1 )
1227
+ INT64_STR_LONG = 'a' * ((2 ** 24 - 1 ) + 100000 )
1223
1228
1224
1229
data = [
1225
- ['CHAR' , CHAR_STR , 123456 ],
1226
- ['SHORT' , SHORT_STR , 123456 ],
1227
- ['INT24' , INT24_STR , 123456 ],
1228
- ['INT64' , INT64_STR , 123456 ],
1230
+ ['CHAR_SHORT' , CHAR_STR_SHORT , 123456 ],
1231
+ ['CHAR_LONG' , CHAR_STR_LONG , 123456 ],
1232
+ ['SHORT_SHORT' , SHORT_STR_SHORT , 123456 ],
1233
+ ['SHORT_LONG' , SHORT_STR_LONG , 123456 ],
1234
+ ['INT24_SHORT' , INT24_STR_SHORT , 123456 ],
1235
+ ['INT24_LONG' , INT24_STR_LONG , 123456 ],
1236
+ ['INT64_SHORT' , INT64_STR_SHORT , 123456 ],
1237
+ ['INT64_LONG' , INT64_STR_LONG , 123456 ],
1229
1238
]
1230
1239
1231
1240
self .cur .executemany (
1232
- 'INSERT INTO test_character_lengths (id, char_col, int_col) '
1241
+ f 'INSERT INTO test_character_lengths_ { tbl_id } (id, char_col, int_col) '
1233
1242
'VALUES (%s, %s, %s)' , data ,
1234
1243
)
1235
1244
1236
- self .cur .execute (
1237
- 'SELECT id, char_col, int_col FROM test_character_lengths '
1238
- 'WHERE id = "CHAR"' ,
1239
- )
1240
- assert data [0 ] == list (list (self .cur )[0 ])
1241
-
1242
- self .cur .execute (
1243
- 'SELECT id, char_col, int_col FROM test_character_lengths '
1244
- 'WHERE id = "SHORT"' ,
1245
- )
1246
- assert data [1 ] == list (list (self .cur )[0 ])
1247
-
1248
- self .cur .execute (
1249
- 'SELECT id, char_col, int_col FROM test_character_lengths '
1250
- 'WHERE id = "INT24"' ,
1251
- )
1252
- assert data [2 ] == list (list (self .cur )[0 ])
1245
+ for i , row in enumerate (data ):
1246
+ self .cur .execute (
1247
+ f'SELECT id, char_col, int_col FROM test_character_lengths_{ tbl_id } '
1248
+ 'WHERE id = %s' ,
1249
+ [row [0 ]],
1250
+ )
1251
+ assert data [i ] == list (list (self .cur )[0 ])
1253
1252
1254
- self .cur .execute (
1255
- 'SELECT id, char_col, int_col FROM test_character_lengths '
1256
- 'WHERE id = "INT64"' ,
1257
- )
1258
- assert data [3 ] == list (list (self .cur )[0 ])
1253
+ try :
1254
+ self .cur .execute (f'DROP TABLE test_character_lengths_{ tbl_id } ' )
1255
+ except Exception :
1256
+ pass
1259
1257
1260
1258
1261
1259
if __name__ == '__main__' :
0 commit comments