我试图使用两个列名'id‘和'easy_high_score’将信息解析到SELECT语句中,这样我就可以在我的程序中操作这两个列的值,但是当尝试获取列‘easy_high_score’的值时,它返回一个字符串('easy_high_score',)。
即使表中没有提到('easy_high_score‘),它仍然会打印出来。在该表中,id 1具有我正在尝试获取的正确的值和信息,但无济于事。我对SQLite3还是个新手。
if mode == "Easy":
mode = 'easy_high_score'
if mode == "Normal":
mode = "normal_high_score"
if mode == 'Hard':
mode == "hard_high_score"
incrementor = 1 ##This is used in a for loop but not necessary for this post
c.execute("SELECT ? FROM players WHERE id=?", (mode, incrementor))
allPlayers = c.fetchall()
print(allPlayers) #This is printing [('easy_high_score',)], when it should be printing an integer.
预期结果: 20 (或一个整数,表示easy模式的高分)
实际结果:('easy_high_score',)
发布于 2019-07-01 21:32:55
不能使用参数指定列名,它应该在查询中按原样显示。修改执行查询的行,如下所示:
c.execute("SELECT %s FROM players WHERE id=?" % mode, (incrementor,))
https://stackoverflow.com/questions/56842657
复制相似问题