我运行循环将一些数据插入表中,我可以看到查询看起来正确但是当我运行另一个脚本向我显示表中的行时它的emtpy
创建查询并执行查询的脚本
objPolicyData = getUserData()
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
for UserItem in objPolicyData['users']:
pdID = UserItem['id']
pdJobTitle = UserItem['job_title']
pdPolicy = ''
if pdJobTitle == 'Network Engineer':
pdPolicy = 'Network Team'
elif pdJobTitle == 'System Administrator':
pdPolicy = 'Sysadmin Team'
elif pdJobTitle == 'Infrastructure Engineer':
pdPolicy = 'Infrastructure Team'
elif pdJobTitle == 'Database Administrator' and 'oracle' in UserItem['description'].lower():
pdPolicy = 'Oracle DBA Team'
elif pdJobTitle == 'Database Administrator' and 'mysql' in UserItem['description'].lower():
pdPolicy = 'MySQL DBA Team'
query = "INSERT INTO oncall_pduser (Name,Mobile,PagerDutyID,PagerDutyPolicy) VALUES ('%s','%s','%s','%s');" % (UserItem['name'],getUserMobile(pdID),pdID,pdPolicy)
print query
c.execute(query)
检查表格的脚本
import sqlite3
conn = sqlite3.connect('db.sqlite3')
c = conn.cursor()
c.execute("SELECT * from oncall_pduser")
for row in c.fetchall():
print(row)
从脚本打印的查询样本
INSERT INTO oncall_pduser (Name,Mobile,PagerDutyID,PagerDutyPolicy) VALUES ('John Smith','0123 12 4596','159842','Network Team');
拉桌子的样本
[root@network-tools infternal]# python test.py
(1, u'test', u'1235466', u'555', u'BOB')
只有我使用django管理页面添加的一个测试用户
由于
答案 0 :(得分:1)
我需要提交更改!
conn.commit()