0

I'm not that familiar with Flask/SQLite but I'm trying to insert several items into a DB in one go.

g.db.execute('insert into images(fileName, fileTitle, file_height, file_width, file_size) values (?,?,?,?,?)', filename, request.form['title'], fileMetaData['height'], fileMetaData['width'], fileMetaData['fileSize'])

running that gives me a

TypeError: function takes at most 2 arguments (6 given)

What's the best way go go about doing this? I understand the error but I don't understand how I'm supposed to do it.

1 Answer 1

2

I believe the arguments must be a tuple:

g.db.execute('insert into images(fileName, fileTitle, file_height, file_width, file_size) values (?,?,?,?,?)', (filename, request.form['title'], fileMetaData['height'], fileMetaData['width'], fileMetaData['fileSize'])) 
Sign up to request clarification or add additional context in comments.

2 Comments

It seem to run fine and didn't throw an error at me. Just have to check. It worked, thank you. I was just going by what I read in their Flaskr tutorial.
It's pedantic, I know, but it's a tuple, rather than a list. If you ever want to pass just one item, you would need to create a singleton tuple like so: g.db.execute("SELECT name FROM users WHERE user_id=?", (user_id,)) (note the trailing comma ,)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.