简体   繁体   English

如何在SQLITE3中获取列值而不是列名(我的列是日期)

[英]How do I fetch column values and not column names in SQLITE3 (my columns are dates)

I'm trying to make an attendance-taking program with Python, SQLite and TKinter. 我正在尝试使用Python,SQLite和TKinter制作出勤计划。 My columns are dates (class meeting dates) and the contents are time stamps. 我的专栏是日期(课堂会议日期),内容是时间戳。 I am now attempting to get the list of students who attended on a particular date to show up in my listbox. 我现在试图获取在特定日期参加的学生列表,以显示在我的列表框中。

self.date = time.strftime("%d %b %Y")
...
self.cur.execute("SELECT name FROM table WHERE '{column_name}' IS NOT NULL".format(column_name = self.date))
names = self.cur.fetchall()

When I tried printing the names, I got tuples with the name and the column_name, but I was expecting column values and not the latter. 当我尝试打印名称时,我得到了带有名称和column_name的元组,但是我期望的是列值,而不是后者。 How do I do that? 我怎么做?

You should not use string formatting to set the column name: that's where the problem seems to lie. 您不应该使用字符串格式设置列名称:这似乎是问题所在。 I tried running similar code on a database on my machine, and I did not get the tuple logic error when I removed the string formatting. 我尝试在计算机上的数据库上运行类似的代码,但删除字符串格式时没有收到元组逻辑错误。 Simply enter the column name manually (that shouldn't be a problem). 只需手动输入列名(这不成问题)。

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

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