Sunday, 12 April 2020

parameters are of unsupported type sqlite python

Details:

This is one of the common error a beginner will be facing when he is working on Python and SQLite bridging. Below is a scenario provided for better understanding with example.

Error:

insert_data = "INSERT INTO users VALUES (?, ?, ?)"
    user = [
        {1, "Ram", "abc@123"},
        {2, "Rahim", "wel@123"},
        {3, "Raju", "pass@123"}
    ]
    cursor.executemany(insert_data, user)

When you run the above code you will get the error:
(venv) D:\python\Course_sample\source_database>python dataBase.py
parameters are of unsupported type

This is because when ever we try to insert into database from python, they data has to be a tuple.
In the above code you can see list of set which we try to insert.

Fixed:

#insert data query
    insert_data = "INSERT INTO users VALUES (?, ?, ?)"
    user = [
        (1, "Ram", "abc@123"),
        (2, "Rahim", "wel@123"),
        (3, "Raju", "pass@123")
    ]
    cursor.executemany(insert_data, user)

The above code will get executed and the data will get inserted into the database properly.

No comments:

Post a Comment

Expense Handler Application with advance technologies

Budget Planner  One of the application developed with Ionic 4 and Python-Flask.  Ionic 4 code:  https://github.com/logeshbuiltin/Expense...