简体   繁体   English

如何获取数据库sqlite3中单词的rowid?

[英]How to get the rowid of a word in the database sqlite3?

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. 我正在尝试在sqlite3中获取用户名的rowid,我已经掌握了它的基础知识,但是每当我运行它时,我都会得到类似'sqlite3.Cursor object at 0x03885660'之类的东西,并且每次使用相同的用户名运行它时,它都会改变。 I know it is because i print rowid but i cant find an alternative way. 我知道这是因为我打印了rowid,但找不到其他方法。

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)

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. 您可以使用fetchone()fetchall()或许多其他方式来获取它。

if username in names:
    c.execute("SELECT rowid, * FROM stuffToPlot WHERE username = (username)")
    rowid = c.fetchone()
    print(rowid)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM