每次都插入相同的值。
import re
import MySQLdb
db = MySQLdb.connect("localhost","root","123","tc" )
cursor = db.cursor()
for x in range(1,2):
file = '/tmp/tc/'
file +=`x`
file +=".txt"
f = open(file, 'r')
print x
listTC = re.findall(r'[1-9]{1}[0-9]{10}', f.read())
for item in listTC:
print item
sql = "INSERT INTO TCNO (tcno) VALUES(%s);"
cursor.execute(sql % (item))
MYSQL SERVER中的OUTPUT:
| 94006 | 2147483647 | NULL |
| 94007 | 2147483647 | NULL |
| 94008 | 2147483647 | NULL |
| 94009 | 2147483647 | NULL |
| 94010 | 2147483647 | NULL |
| 94011 | 2147483647 | NULL |
| 94012 | 2147483647 | NULL |
| 94013 | 2147483647 | NULL |
| 94014 | 2147483647 | NULL |
| 94015 | 2147483647 | NULL |
| 94016 | 2147483647 | NULL |
| 94017 | 2147483647 | NULL |
| 94018 | 2147483647 | NULL |
| 94019 | 2147483647 | NULL |
| 94020 | 2147483647 | NULL |
| 94021 | 2147483647 | NULL |
| 94022 | 2147483647 | NULL |
| 94023 | 2147483647 | NULL |
+-------+------------+------+
94023 rows in set (0.11 sec)
但是,在我打印项目的控制台中:
69619195972
32386362700
70930135288
20371250224
25069684954
32414357302
55660438298
12352807312
18566819172
53425735712
19622042220
34060374108
49126586180
13184124554
18772590346
38074262024
37765310686
15491265104
16139670014
16799684314
22231833554
22231833554
21389016246
44923993452
50902266134
30742937128
34071994144
35011994174
答案 0 :(得分:2)
2147483647
为0x7fffffff
,因此您可能会达到max signed int value。
查看数据库设计人员在该字段上的数据类型,并可能使用Big Integer或更大的数据类型。
参考:http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html#id603844
答案 1 :(得分:0)
这是因为范围(1,2):
for x in range(1,2):
... print x
...
1
for x in range(0,2):
... print x
...
0
1