当ID高于9时,我得到一个sqlite3.ProgrammingError

时间:2016-10-26 10:39:29

标签: python-3.x sqlite

我使用python和sqlite开展大学项目。我创建了一个数据库,它似乎工作正常,直到我的数据库中有超过9行。 当id为10或更高时,我得到此错误,这是没有意义的。其余小于10的行仍然可以显示没有错误。

sqlite3.ProgrammingError
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.

这是db架构:

CREATE TABLE mixes(ID INTEGER PRIMARY KEY AUTOINCREMENT, artist TEXT, favourite INT, lenght VARCHAR(255),genre TEXT, rel_date DATE, alb_img VARCHAR(255), mix_name VARCHAR(255), mp3_name VARCHAR(255), desc TEXT)

以下是要插入db的代码:

@app.route('/uploader', methods=['GET', 'POST'])
def uploader():
    if not session.get('admin'):
        abort(401)
    else:
        if request.method == 'POST':
            img = request.files['img']
            mp3 = request.files['mp3']          
            img.save('static/img/album/'+img.filename)
            mp3.save('static/mp3/'+mp3.filename)
            sql = ('INSERT INTO mixes (artist, favourite, lenght, genre, rel_date, alb_img,mix_name, mp3_name, desc) VALUES (?,?,?,?,?,?,?,?,?)')       
            connection = sqlite3.connect(app.config['db_location'])
            connection.row_factory = sqlite3.Row            
            connection.cursor().execute(sql, (request.form['artist'], request.form['favourite'], request.form['lenght'],request.form['genre'], request.form['rel_date'], img.filename, request.form['mix_name'], mp3.filename, request.form['description']))
            connection.commit()                     
            return redirect(url_for('admin'))

以下是从db:

检索数据的代码
@app.route('/track', methods=['GET'])
@app.route('/track/<id>', methods=['GET'])
def track(id):  
    sql = ('SELECT * FROM mixes WHERE id = ?')
    connection = sqlite3.connect(app.config['db_location'])
    connection.row_factory = sqlite3.Row            
    rows = connection.cursor().execute(sql, id).fetchall()
    connection.close()  
    return render_template('track.html', rows = rows) 

0 个答案:

没有答案