0

trying to develop some code so that on the press of a button i can return the contents of the information_Schema and allow myself to select one database from the generated list, creating the button and requesting a logon is not an issue and works, returning the results is however failing, the code i have created so far is this:

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)

the line data = conn.fetchall() seems to give an error relating to the brackets () as in the code must process this first but i don't understand why, all the examples I have seen have this syntax ? I guess I need the rows from the schema_name to go into a tuple so I can use that information as a 'drop down' selection box? Has anyone done something similar at all? I can't create the dropdown until I can return the rows, at the moment all I can return is the number of rows as the fetchall() command fails.

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
Matti Lyra
  • 12,828
  • 8
  • 49
  • 67
jon141
  • 45
  • 2
  • 11
  • can you post the error message you get from calling `fetchall()`? – Matti Lyra Jan 29 '14 at 12:38
  • '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() – jon141 Jan 29 '14 at 12:49
  • cont... 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' – jon141 Jan 29 '14 at 12:49
  • traditionally people would edit the question and add the stacktrace there – Matti Lyra Jan 29 '14 at 13:27

1 Answers1

0

You need to call cursor.execute(query, args=None) before calling fetch_all

Matti Lyra
  • 12,828
  • 8
  • 49
  • 67