python - 为什么这个sql脚本不执行?

标签 python sql

嗨,我有以下 python:

c = conn.cursor()

#get the account id for the specific user

actidSQL = "select id from accounts where user_id = (select id from auth_user where username = '%s');" % user
c.execute(actidSQL)
actid = c.fetchone()[0]
print actid

#fill the latencies table - currently not firing, not sure why?
latencies_sql = "insert into latencies(account, replier, sender, replyemail, origemail, replydate, origdate) select m1.account, c1.id as replier, c2.id as sender, m1.id as replyemail, m2.id as origemail, m1.date as replydate, m2.date as origdate from contacts c1, contacts c2, emails m1, emails m2 where m1.id > m2.id and m1.reply = m2.mid and m1.reply is not null and c1.id = m1.fr and c2.id = m2.fr and m1.account = %s and m1.account = m2.account;" % (actid)
print latencies_sql
c.execute(latencies_sql)

第一个 sql 执行,但第二个 sql 不执行。有什么原因吗?

最佳答案

“第一个 sql 执行但第二个 sql 不执行。”是什么意思?你得到一个错误吗?或者数据库中没有数据?我假设数据库中没有数据并且您使用的是MySQL。这是因为您没有提交更改。脚本末尾的 conn.commit() 应该会有所帮助。

关于python - 为什么这个sql脚本不执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7357995/

相关文章:

python - Python 3000 上有没有像 RoR 这样的框架?

python - 如何从 StringIO、BytesIO 等中删除字节

sql - 尝试访问 SQL Server EXEC 语句的结果/结果集

Python:动画 3D 散点图变慢

python feedparser ImportError : No module named feedparser

mysql - 根据另一个表中的记录在一个表中插入记录的 SQL 过程

php - 如果可能,当与任何引用都不匹配时,将外键设置为 null

mysql - 删除不适用于连接的查询

mysql 从工作 "prepare"语句创建 View

python - Python中的变量是如何分配内存的?