Declare self.cursor

D

Dani Valverde

Hello!
I am working on a GUI to connect to a MySQL database using MySQLdb (code
in attached file). I define the cursor in lines 55-66 in the OnLogin
function within the LoginDlg class.

/db= MySQLdb.connect(host='localhost', user=Username , passwd=pwd,
db='Ornithobase')
self.cursor = db.cursor()/

When I try to use the cursor on another part of the code (EditUser
class, line 176)

/sql = 'select substring_index(CURRENT_USER(),"@",1)'
login.cursor.execute(sql)/

I get this error:

/AttributeError: 'LoginDlg' object has no attribute 'cursor'/

You can check the code for details, I think is better.
Cheers!

Dani

--
Daniel Valverde Saubí
c/Joan Maragall 37 4 2
17002 Girona
Spain
Telèfon mòbil: +34651987662
e-mail: (e-mail address removed)
http://www.acrocephalus.net
http://natupics.blogspot.com

Si no és del tot necessari, no imprimeixis aquest missatge. Si ho fas utilitza paper 100% reciclat i blanquejat sense clor. D'aquesta manera ajudaràs a estalviar aigua, energia i recursos forestals. GRÀCIES!

Do not print this message unless it is absolutely necessary. If you must print it, please use 100% recycled paper whitened without chlorine. By doing so, you will save water, energy and forest resources. THANK YOU!
 
M

Mel

Dani said:
Hello!
I am working on a GUI to connect to a MySQL database using MySQLdb (code
in attached file). I define the cursor in lines 55-66 in the OnLogin
function within the LoginDlg class.

/db= MySQLdb.connect(host='localhost', user=Username , passwd=pwd,
db='Ornithobase')
self.cursor = db.cursor()/

When I try to use the cursor on another part of the code (EditUser
class, line 176)

/sql = 'select substring_index(CURRENT_USER(),"@",1)'
login.cursor.execute(sql)/

I get this error:

/AttributeError: 'LoginDlg' object has no attribute 'cursor'/

You can check the code for details, I think is better.

Did you actually click the loginBtn?

Mel.
 
J

John Nagle

Hello!
I am working on a GUI to connect to a MySQL database using MySQLdb (code
in attached file). I define the cursor in lines 55-66 in the OnLogin
function within the LoginDlg class.

/db= MySQLdb.connect(host='localhost', user=Username , passwd=pwd,
db='Ornithobase')
self.cursor = db.cursor()/

When I try to use the cursor on another part of the code (EditUser
class, line 176)

/sql = 'select substring_index(CURRENT_USER(),"@",1)'
login.cursor.execute(sql)/

I get this error:

/AttributeError: 'LoginDlg' object has no attribute 'cursor'/

You can check the code for details, I think is better.
Cheers!

Dani


self.cursor = db.cursor()
....
self.Destroy() # probably clears the object


Also, it's generally better to hold on to the database handle and
get a cursor from it as a local variable when needed. You
need the database handle for "db.commit()", at least. Getting
a cursor is fast. (Actually, in MySQL, there is only one cursor.)


I realize it's a desktop application, but still:

db= MySQLdb.connect(host='localhost', user='root' , passwd='acrsci00',
db='Ornithobase')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Auto size wx.StaticText 2
Hello 3

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top