我在Python中使用SQLite3,当我使用RANDOM()和LIMIT时,一切都有效。我到处搜索过,我很确定我使用了正确的语法,我没有得到任何错误。每次我运行它,无论我指定什么LIMIT(或者它是固定的还是输入的)它只显示1个结果。 这是代码:
def RandomPlaylist():
conn = sqlite3.connect("Playlist.db")
c=conn.cursor()
RandomPlaylistLimit = input("How many songs do you want in your playlist [1-100]?")
RandomPlaylistLimitInt = int(RandomPlaylistLimit)
print(RandomPlaylistLimitInt)
if RandomPlaylistLimitInt < 101:
c.execute("SELECT * FROM Songs ORDER BY RANDOM() LIMIT {0}".format(RandomPlaylistLimit))
for row in c.fetchall():
print("""
Song Name: {0}.
Artist: {1}.
Album: {2}.
Length: {3}.
Year: {4}.
""".format(row[1], row[2], row[3], row[5], row[6]))