user3628517
user3628517

Reputation: 93

SQLite ERROR no such column Python

I have a problem, i am trying to do a validation between a username to that username email by compairing the rowid in python and SQLite, here is the code:

username = self.txtUsername.GetValue()
email =  self.txtEmail.GetValue()
UsernameE  = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username="
  + username)
EmailU = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Email=" + email)

The error is:

> UsernameE  = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username="
      + username)
sqlite3.OperationalError: no such column: "what i inserted in the username"

Upvotes: 0

Views: 1528

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599450

Your SQL is malformed, because you don't close the quote after the username value. But you shouldn't be doing it that way anyway: you should be using a parameter:

self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username=? ", (username,))

Also note that execute doesn't return the value: you need to fetch it, eg with fetchone().

Upvotes: 1

DrHaze
DrHaze

Reputation: 1318

Try adding quotes to username:

UsernameE  = self.conn.execute("SELECT rowid,* FROM tblPlayers WHERE p_Username = '" + username + "'") 

Upvotes: 0

Related Questions