0
votes

I tried following python script on Apache2, but I failed. According to /var/log/apache2/error.log, "sqlite3.OperationalError: table card_data has 11 columns but 10 values were supplied".

I can't understand why card_data table has 11 columns. It should be 10 columns.

I also tried con.execute("PRAGMA table_info(card_data)") but card_data has 10 columns.

I would like to know why card_data has 11 columns and how to solve this problem. Thank you.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-

    import cgi
    import sqlite3

    f = cgi.FieldStorage()
    cardname = unicode(f.getfirst("cardname", "default string"), 'utf-8')
    cardtype = unicode(f.getfirst("cardtype", "default string"), 'utf-8')
    cost = unicode(f.getfirst("cost", "default string"), 'utf-8')
    color = unicode(f.getfirst("color", "default string"), 'utf-8')
    text = unicode(f.getfirst("text", "default string"), 'utf-8')
    igflag = unicode(f.getfirst("igflag", "default string"), 'utf-8')
    tribe = unicode(f.getfirst("tribe", "default string"), 'utf-8')
    power = unicode(f.getfirst("power", "default string"), 'utf-8')
    cardid = unicode(f.getfirst("cardid", "default string"), 'utf-8')
    dispname = unicode(f.getfirst("displayname", cardname), 'utf-8')

    conn = sqlite3.connect("carddata.db")

    sql = u"""create table if not exists card_data(
        NAME TEXT,
        TYPE TEXT,
        COST, INTEGER,
        COLOR TEXT,
        CRADTEXT TEXT,
        IGNITION NULL,
        TRIBE TEXT,
        POWER INTEGER,
        CARDID TEXT,
        DISPLAY TEXT);
    """
    conn.execute(sql)
    conn.commit()

    sql = u"insert into card_data values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
    conn.execute(sql, (cardname, cardtype, int(cost), color, text, igflag, tribe, int(power), cardid, dispname))
    conn.commit()
1

1 Answers

0
votes

This line

COST, INTEGER,

creates two columns.