0
votes

I am trying to insert data from Kivy's textinput fields to sqlite3 database but arrive at the following issue. Code snippet

def save(self):

    conn = Database.db_connect()
    cursor = conn.cursor()

    # kivy textinput widgets are assigned variable no, name
    no = self.empid_text_input
    name = self.empname_text_input.text

    try:
        save_index_sql="INSERT INTO EmpInfo (EmpID , EmpName) VALUES (?,?)"
        conn.execute(save_index_sql, (no, name)) # Causes Error
        conn.commit()
        conn.close()
    except sqlite3.IntegrityError as e:
        print("Error: ",e)

# THROWS ERROR----> sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Database file Emp.db contains the follwing tables & structure : EmpInfo & EmpImage

  1. EmpInfo CREATE TABLE EmpInfo(EmpID integer PRIMARY KEY, EmpName text NOT NULL)

  2. EmpImage CREATE TABLE EmpImage(EmpID integer PRIMARY KEY, EmpPhoto BLOB NOT NULL)

Casting gives the following results:

        # conn.execute(save_index_sql,(int(no), str(name))) # RETURNS----> TypeError: int() argument must be a string, a bytes-like object or a number, not 'TextInput'
        # conn.execute(save_index_sql, (str(no), str(name))) # RETURNS----> Error:  datatype mismatch
1

1 Answers

1
votes

You are attempting to insert the TextInput object. You want to insert the text value of the TextInput.

This must also be converted to integer

Change:

no = self.empid_text_input

To:

no = int(self.empid_text_input.text)