2014-01-29 59 views
0

试图开发一些代码,以便在按下按钮时,我可以返回information_Schema的内容,并允许我自己从生成的列表中选择一个数据库,创建按钮并请求登录不是问题,并且工作,返回结果却是失败的,我到目前为止创建的代码是这样的:python查询mysql添加结果下拉选择?

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

你可以调用'使用fetchall()'后您收到错误消息之前调用cursor.execute(query, args=None)? –

+0

'Tkinter回调中的异常 回溯(最近调用最后一次): __call__中的第1475行文件“C:\ Python33 \ lib \ tkinter \ __ init__.py”返回self.func(* args) File“S :\ python \ jon \ wrt_toolkit_v5 \ wrt_toolkit_v6.py“,第97行,在mysqlConnect中 data = cursor.fetchall() – jon141

+0

cont ...文件”C:\ Python33 \ lib \ site-packages \ pymysql3-0.4-py3。 3.egg \ pymysql \ cursors.py“,第194行,在fetchall中 self._check_executed() 文件”C:\ Python33 \ lib \ site-packages \ pymysql3-0.4-py3.3.egg \ pymysql \ cursors“。 py“,第64行,在_check_executed self.errorhandler(self,ProgrammingError,”execute()first“) 文件”C:\ Python33 \ lib \ site-packages \ pymysql3-0.4-py3.3.egg \ pymysql \ connections.py“,行184,在defaulterrorhandler 提高errorclass(errorvalue) pymysql.err.ProgrammingError:执行()第一” – jon141

回答

0

你需要调用fetch_all

+0

好东西,修改代码,创建的元组。谢谢。 – jon141