【问题标题】:python querying mysql add results to drop down selection?python查询mysql添加结果到下拉选择?
【发布时间】:2014-01-29 11:54:36
【问题描述】:

尝试开发一些代码,以便在按下按钮时我可以返回 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

【问题讨论】:

  • 你能把调用fetchall()得到的错误信息贴出来吗?
  • 'Tkinter 回调 Traceback 中的异常(最近一次调用最后一次):文件“C:\Python33\lib\tkinter_init_.py”,第 1475 行,在 call return self.func(*args) File "S:\python\jon\wrt_toolkit_v5\wrt_toolkit_v6.py",第 97 行,在 mysqlConnect data = cursor.fetchall()
  • 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: execute( ) 首先'
  • 传统上人们会编辑问题并在那里添加堆栈跟踪

标签: mysql python-3.x fetchall


【解决方案1】:

在拨打fetch_all之前,您需要先拨打cursor.execute(query, args=None)

【讨论】:

    猜你喜欢
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多