为什么我不能使用 QtSql (PyQT) 执行 SHOW PROCESSLIST?
我是Python和QT新手。我正在尝试使用 PyQT4 做一个小应用程序,以便监督我的家庭 MySQL 服务器,所以我的第一个想法是执行经典的 SHOW PROCESSLIST
,解析它,并在漂亮的 UI 中显示。没什么大不了的,真的。
但由于某种原因,QtSql 模块在执行此查询时不会返回任何内容,尽管它可以与其他查询(如 SHOW TABLES
等)一起使用,
我在邮件列表中发现了一条旧的(2002)消息谈论this[1],以及MythTV代码中的参考文献[2],但都没有解释清楚。
这是一些代码:
db = QSqlDatabase.addDatabase('QMYSQL3') # tried with QMYSQL too
db.setHostName(host)
db.setDatabaseName(dbname)
db.setUserName(user)
db.setPassword(password)
db.open()
q = QSqlQuery(db)
q.exec_("SHOW PROCESSLIST")
print q.size() # returns -1!
正如我所说,它与其他查询(SELECT 等)配合得很好。
我做错了什么吗?谢谢你!
[1]:lists.trolltech.com/qt-interest/2002-09/thread00104-0.html
[2]:www.google.com/codesearch/p?hl=es&sa=N&cd=1&ct=rc#-zNo3rQOo4A/mythtv/libs/libmyth/dbutil.cpp&l=657
I am a Python and QT newbie. I am trying to do a little app with PyQT4 in order to supervise a home MySQL server of mine, so my first idea was to do the classic SHOW PROCESSLIST
, parse it, and show in a pretty UI. Nothing big, really.
But for some reason, the QtSql module doesn't return anything when doing this query, although it works with other queries like SHOW TABLES
, etc
I found an old (2002) message in a mailing list talking about this[1], and a reference in the MythTV code[2], but none of them explains it clearly.
Here is some code:
db = QSqlDatabase.addDatabase('QMYSQL3') # tried with QMYSQL too
db.setHostName(host)
db.setDatabaseName(dbname)
db.setUserName(user)
db.setPassword(password)
db.open()
q = QSqlQuery(db)
q.exec_("SHOW PROCESSLIST")
print q.size() # returns -1!
As I said, it works fine with other queries (SELECT, etc).
Am I doing something wrong? Thank you!
[1]: lists.trolltech.com/qt-interest/2002-09/thread00104-0.html
[2]: www.google.com/codesearch/p?hl=es&sa=N&cd=1&ct=rc#-zNo3rQOo4A/mythtv/libs/libmyth/dbutil.cpp&l=657
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道出了什么问题,但在最新版本的 MySQL 中,您可以使用 information_schema.processlist:
I don't know what is wrong, but in recent versions of MySQL you can work it around using information_schema.processlist:
我不知道你是否已经尝试过这个,但是添加一个“;”怎么样?
我从未使用过 QtSQL,但一些 MySQL API 确实有相当奇怪的行为,我以前遇到过这个问题。
(抱歉碰到了一个老问题,当我搜索类似问题时出现了)
I don't know if you already tried this, but what about adding an ';'?
I have never worked with QtSQL but some MySQL API's do have quite strange behavior and I've run into that problem before.
(sry for bumping an old question, it came up when I was searching for a similar issue)