1

I am trying to get the rowid of a username in sqlite3, i have got the basics of it but when ever i run it i get somthing like 'sqlite3.Cursor object at 0x03885660' and it changes every time i run it with the same username. I know it is because i print rowid but i cant find an alternative way.

here is my code:

def sign_in():
    username = input("What is your username?")
    password = input("What is your password?")
    c.execute("SELECT username FROM stuffToPlot")
    names = {name[0] for name in c.fetchall()} 
    if username in names:
        rowid = c.execute("SELECT rowid, * FROM stuffToPlot WHERE username = (username)")
        print(rowid)
Samboy T
  • 43
  • 3
  • 8
  • Why do you want the ROWID? That isn't s permanent identifier. It's just an identifier for the current execution of the query and could be completely different the next time you query the same data. – Chris Johnson Oct 30 '17 at 01:50
  • A rowid is assigned to a row upon insert and is inmutable (never changing) unless the row is deleted and re-inserted (meaning it is another row, not the same row!) – Saelyth Oct 30 '17 at 04:17

1 Answers1

0

You got to the point where your cursor executes that query, but then you need to tell it what to return from it. Return the first match with that query? return every record? Fetch the data depending on what you need. You can use fetchone(), fetchall() or many other ways to get it.

if username in names:
    c.execute("SELECT rowid, * FROM stuffToPlot WHERE username = (username)")
    rowid = c.fetchone()
    print(rowid)
Saelyth
  • 1,694
  • 2
  • 25
  • 42