Maverick
Maverick

Reputation: 177

Matching user's input with query from sqlite3 db in python

I'm writing a script where by a user registers his/her username, but a function checks whether this username is already in the db or not. But I'm stuck on how to match my query with the input. Here is the code:

def checker(self, insane):                                                  
        t = (insane,)                                                           
    cmd = "SELECT admin_user FROM admin_db where admin_user = \"%s\";" %t
    self.cursor.execute(cmd)
    namer = self.cursor.fetchone()
    print namer
    if namer == insane:                                                     
        print("Username is already chosen!")
        exit(1)
    else:
        pass

Since

namer
returns as
(u'maverick',)
It doesn't match with the input. How should I go about implementing that?

Upvotes: 0

Views: 1407

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600059

The DB fetch models return a tuple for each row. Since you've only selected a single field, you can simply access namer[0] to get the actual value.

Upvotes: 1

Related Questions