Search code examples
pythonsqlitepyqt4

Inserting QlineEdit.text() into Sqlite3 table give an error sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type


I am using python 2.7 with pyqt4.10 and sqlite3 Db, trying to get the user input from QlineEdit to insert into sqlite3 table that is already created

Table structure

CREATE TABLE `categories` (
    `id`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
    `category_name` TEXT NOT NULL UNIQUE
);

And am trying to refresh the list in a Qlistwidget with the new data after adding the input Here is my full code :

    def proc():
    input_user = self.lineEdit.text()
    conn = sqlite3.connect('storage/container.db')
    conn.row_factory = lambda c, row: row[0]
    c = conn.cursor()
    c.execute("INSERT INTO categories (category_name) VALUES (?)", (input_user, ))
    conn.commit()
    conn = sqlite3.connect('storage/container.db')
    conn.row_factory = lambda c, row: row[0]
    c = conn.cursor()
    c.execute("SELECT category_name FROM categories")
    category_all = c.fetchall()
    for items in category_all:
        self.listWidget.addItem(items)
    conn.close()

As you see i used input_user = self.lineEdit.text() to get the user input from the QlineEdit

The error is :

Traceback (most recent call last):
  File "C:\python\townoftechwarehouse\add_category.py", line 63, in proc
    c.execute("INSERT INTO categories (category_name) VALUES (?)", (input_user, ))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Solution

  • Found out that the problem was that am using Arabic characters which is not readable for qslite3 so I have to use unicode, here is the edit:

    Changed :

    input_user = self.lineEdit.text()
    

    To :

       input_user1 = self.lineEdit.text()
       input_user = unicode(input_user1)