尝试开发一些代码,以便在按下按钮时我可以返回information_Schema的内容并允许自己从生成的列表中选择一个数据库,创建按钮并请求登录不是问题而且有效,然而,返回结果是失败的,我到目前为止创建的代码是:
def mysqlConnect():
import pymysql
import subprocess
sqlUsr = MysqlUsr.get()
sqlpwd = Mysqlpwd.get()
conn = pymysql.connect(host='192.168.0.27', user= sqlUsr, passwd=sqlpwd, db='information_schema')
cursor = conn.cursor()
conn.query("SELECT SCHEMA_NAME FROM SCHEMATA")
data = cursor.fetchall()
print (data)
行data = conn.fetchall()
似乎给出了与括号()
相关的错误,因为代码必须首先处理它,但我不明白为什么,我看到的所有示例都有这种语法?我想我需要schema_name
中的行进入元组,所以我可以将这些信息用作“下拉”选择框?有没有人做过类似的事情?在我可以返回行之前,我无法创建下拉列表,此时我可以返回的是fetchall()
命令失败时的行数。
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Python33\lib\tkinter_init_.py", line 1475, in
call return self.func(*args)
File "S:\python\jon\wrt_toolkit_v5\wrt_toolkit_v6.py", line 97, in
mysqlConnect data = cursor.fetchall()
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\cursors.py", line 194,
in fetchall self._check_executed()
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\cursors.py", line 64,
in _check_executed self.errorhandler(self, ProgrammingError, "execute() first")
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\connections.py", line 184,
in defaulterrorhandler raise errorclass(errorvalue)
pymysql.err.ProgrammingError: execute() first
答案 0 :(得分:0)
您需要在致电cursor.execute(query, args=None)
fetch_all