python执行批量新增sql报错 not enough arguments for format string
import pyodbc
from sqlConfig import MySQLConnectionPool
连接数据库
conn = pyodbc.connect(r’Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\东和.accdb’)
创建连接池对象
ConnPool = MySQLConnectionPool()
创建游标
cursor = conn.cursor()
查询数据
cursor.execute(‘SELECT * FROM 配方列表’)
list1 = []
逐行读取数据
for row in cursor.fetchall():
list1.append(row)
print(list1)
#list = cursor.fetchall()
sql_update_one = “delete from plan_peifang_list where 1=%s”
ConnPool.update_one(sql_update_one, (1,))
a= [(‘D033’, ‘吉林建龙’, ‘AMC72/10Z5-8A2’, None, ‘2024/5/31 924’, None), (‘D074’, ‘鞍钢联众’, ‘MAC65/18F5-10Pa24’, None, ‘2024/4/30 9
50’, None), (‘D033’, ‘吉林建龙’, ‘AMC72/10Z5-8A2’, None, ‘2024/5/31 9
24’, None), (‘D033’, ‘吉林建龙’, ‘AM88/6W-L10’, None, ‘2024/5/29 15:31:16’, None), (‘E005’, ‘塔塔布衫’, ‘MC14H2Pa24-42C3D3’, None, ‘2024/6/1 15:34:59’, None), (‘D033’, ‘吉林建龙’, ‘MC12H4P2-4S9’, None, ‘2024/6/3 6
35’, None), (‘E005’, ‘塔塔布衫’, ‘MC12H3Pa24-41C3G1’, None, ‘2024/6/3 8
18’, None), (‘E035’, ‘米塔尔’, ‘MC13H2PA24-4C2’, None, ‘2024/6/3 15:19:34’, None), (‘E024’, ‘香港泰科’, ‘MC10H3P2-3D3’, None, ‘2024/6/4 6
56’, None), (‘E039’, ‘瑞钢国际’, ‘MC14H2PA24-8C2’, None, ‘2024/6/4 14:32:25’, None), (‘E038’, ‘瑞钢国际’, ‘MC12H3P2-8C2’, None, ‘2024/6/4 16:00:51’, None), (‘D033’, ‘吉林建龙’, ‘AM82/8Z5-L10’, None, ‘2024/6/6 16:33:46’, None), (‘D023’, ‘北方冶金’, ‘MC16H2A5’, None, ‘2024/6/6 16:48:42’, None), (‘D023’, ‘北方冶金’, ‘MC15F5P2-43H5C6’, None, ‘2024/6/7 14:26:36’, None), (‘D033’, ‘吉林建龙’, ‘MAC60/20Y5-10’, None, ‘2024/6/13 17:56:39’, ‘TRL HMR LSKS’), (‘D059’, ‘吉林建龙’, ‘MAC55/25Y5-8’, None, ‘2024/6/13 10:38:08’, ‘SWC30H’), (‘E038’, ‘瑞钢国际’, ‘MC12H2P2-8C2’, None, ‘2024/6/8 19:10:57’, None), (‘E037’, ‘德富高’, ‘ASC62/10X4-12’, None, ‘2024/6/11 8
23’, ‘DF12X10’), (‘D038’, ‘德龙钢铁’, ‘MC10C1RBA235’, None, ‘2024/6/11 15:17:45’, ‘出钢口’), (‘E037’, ‘DUFERCO’, ‘ASC73/8B-10A2’, None, ‘2024/6/12 11:07:08’, ‘DF10K8’), (‘E041’, ‘香港泰科’, ‘MC10H2Pa22-5D3’, None, ‘2024/6/12 20:06:05’, ‘SWC30H’), (‘E000’, ‘LADLE’, ‘MC14H3Pa24-4C3’, None, ‘2024/6/13 15:00:17’, ‘TRL HMR LSKS’), (‘E042’, ‘东和欧洲’, ‘MC12H2PA24’, None, ‘2024/6/13 19:06:19’, ‘CMAG12H2A4’), (‘E042’, ‘东和欧洲’, ‘MC10C2P2’, None, ‘2024/6/13 22:03:29’, ‘CMAG 10C2A01’)]
print(a)
#sql_insert_all = “insert into plan_peifang_list (‘dingdanhao’, ‘kehu’, ‘zhilianghao’,’zhongliang’,’time’,’waibuzhilianghao’) values (%s,%s,%s,%s,%s,%s)”
sql = “INSERT INTO plan_peifang_list (dingdanhao, kehu, zhilianghao, zhongliang, time, waibuzhilianghao) VALUES (%s, %s, %s, %s, %s, %s)”
ConnPool.insert_all(sql, list1)
我传参用list1 会报错
not enough arguments for format string,但是我用变量a就会成功。 a和变量list1的值是一样的啊? 为什么list1会报错?
推荐文章: