I work on a university project with python and sqlite. I created a db and it all seems to work fine until i have more than 9 rows in my db. I get this error when the id is 10 or higher which makes no sense. The rest of the rows which are less than 10 can be still displayed with no errors.
sqlite3.ProgrammingError
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.
Here is the db schema:
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)
Here is the code to insert to the 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'))
And here is the code to retrieve the data from 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)