0

I have several pieces of data collected from a form I want to enter into my database. However, one of those data pieces is a list created from how many checkboxes a user has pressed. When I try and insert this into a list I get the error "sqlite3.InterfaceError: Error binding parameter 4 - probably unsupported type.". My code stops working at "cur.execute(sql, listing).

I've tried changing the type of data piece it is, but I need the tuple to stay as it is. I have tried to use cur.executemany but it didn't work.

title = request.form['item_name']

platform = request.form.getlist('platform_list[]')

con = create_connection(DATABASE_NAME)

listing = (title, platform)

sql = """INSERT INTO items(id, title, platform) VALUES (NULL,?,?);"""

cur = con.cursor()

cur.execute(sql, listing)

con.commit()

con.close()

0

1 Answer 1

1

Sqlite does not have a "list" datatype. Here are two options that may solve the problem:

  • Transform the list to a string as with str = ",".join(platform)
  • Transform the list to a JSON string as with json.dumps(platform)

It would depend on how the data will be used when it is SELECTed back.

If you want one row in the database per platform, you would use executemany. You would have to construct listing differently so that each array element contains all the insert parameters. Something like listing = [(title,x) for x in platform] for instance.

Sign up to request clarification or add additional context in comments.

Comments

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.