指定要插入数据的字段(连续)

时间:2016-04-05 13:28:31

标签: python sqlite conditional overwrite

我正在开发一个Python测验项目,用户可以回答一系列10个数学问题。他们的得分/ 10连同他们的名字一起存储在SQLite数据库中。

我想这样做,以便名称上的行可以存储特定用户最后5个分数,而不是1分。

我已经在表中显示了score1 - score5列,但我不确定如何指定应该将数据添加到哪个字段。

我怀疑可能会用某种if语句来完成:

If name is in RESULTS_TABLE;
    If score2 IS NULL
        Insert score into score2
    Elif score3 IS NULL
        Insert score into score3
    Elif score4 IS NULL
        Insert score into score4
    Elif score5 IS NULL
        Insert score into score5
    Else
        Overwrite score into score1
Else
    Insert into RESULTS_TABLE, name, class, score1

显然,这个伪代码并不正确,因为SQLite没有#if语句'。我如何将其编码到我的Python程序中,以便最后5个分数可以存储在我的SQLite数据库中?

0 个答案:

没有答案