[Tutor] Source of MySQL Command Interpreter
Alan Gauld
alan.gauld at btinternet.com
Tue Jan 19 11:26:37 EST 2016
On 16/01/16 23:27, Ricardo Martínez wrote:
> Hi, i wrote a small APP to execute MySQL commands and retrieve to a Treeview
I finally got round to looking at this.
Here are a couple of comments.
I don't understand what the else part is supposed to do here:
if self.cursor.description is not None:
self.resultset = self.cursor.fetchall()
else:
print("DES: ",self.cursor.description,"\n")
Surely it only executes if description is None, in
which case what do you expect to print?
Also, why is this a second if/else when it's the same test?
if self.cursor.description is not None:
columns = [x[0] for x in self.cursor.description]
else:
columns = []
Why not just set the columns in the branches of the first test?
Also at the top of that function:
def executeSQL(self, sqlstr, grdResult):
if sqlstr is not None:
self.txtCommand.clipboard_clear()
self.txtCommand.clipboard_append(sqlstr)
print("QUERY: ",sqlstr,"\n")
if self.cursor is not None:
try:
self.cursor.execute(sqlstr)
If sqlstr is None you still try to execute it? Is that correct?
Finally you use the \ line continuation in a few places where
it is not needed because you are inside parens.
You can use as many newlines as you like inside parens:
eg.
def foo(bar, # a watering hole
baz, # an English Barry
bash, # a shell
bob): # Blackadder's new servant
pass
Sorry, not much time but those were just some quick observations.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list