mitsuzero blackout mitsuzero blackout - 2 months ago 7
MySQL Question

MysqlDb and Pyqt4 comparing variables

I have a database in mysql, and I'm working in a app in QT4, I'm using Mysqldb connector, I'm already successfully connected to the database, but when I'm querying the table

t_usuarios
I don't know how to eval it. Can you help me? Thanks in advance.

Part of my code:

def chequeouser(self):
passwdcheck = str(txt_password.text())
usuariover = str(txt_usuario.text())
# datosLogin = "SELECT * FROM t_usuarios WHERE id_usuario = 'usuario' AND pasword = 'password'
cursor = dbase.cursor()
cursor.execute("SELECT id_usuario, password FROM t_usuarios WHERE id_usuario = %s AND password = %s", (usuariover, passwdcheck))
checar = cursor.fetchone()


Thanks for the user who answer me ... I do it, but with some modification as follow ..

passwdcheck = str(txt_password.text())
usuariocheck = str(txt_usuario.text())
# datosLogin = "SELECT * FROM t_usuarios WHERE id_usuario = 'usuario' AND pasword = 'password'
cursor = dbase.cursor()
cursor.execute("SELECT id_usuario, password FROM t_usuarios WHERE id_usuario = %s AND password = %s", (usuariocheck, passwdcheck))
row = cursor.fetchone()
if row == None:
print "no data:"+ usuariocheck
return
if row[1] == passwdcheck:
print "user and password combination is correct" +usuariocheck
else :
print "your input is incorrect"


I'm thinking do this in answer but I not sure if this is correct or not.

Answer

fetchone() returns a row of data. The first item is row[0], 2nd item is row[1], etc.

Example:

def chequeouser(self):
    passwdcheck = str(txt_password.text())
    usuariover =  str(txt_usuario.text())
   # datosLogin = "SELECT * FROM t_usuarios WHERE id_usuario = 'usuario' AND pasword = 'password'
    cursor = dbase.cursor()
    cursor.execute("SELECT id_usuario, password FROM t_usuarios WHERE id_usuario = %s AND password = %s", (usuariover, passwdcheck))
    row = cursor.fetchone()
    if not row:
       print "no rows!"
       return
    if passwdcheck == row[1]:
       print 'MATCH for user', row[0]
    else:
       print 'uhoh'
Comments