How to prepare data for entering in Sqlite3 database

Viewed 20
def insert(data):
    import sqlite3
    conn = sqlite3.connect("keywords.db")
    conn.text_factory = str
    c = conn.cursor()
    c.execute("INSERT into PROJECT values (?)", (data,))
    for row in c.execute("SELECT ROWID,* FROM PROJECT ORDER BY ROWID DESC LIMIT 1"):
        print ("\nPOST VERIFIED:\n",row[0],row[1])
    conn.commit()
    conn.close()
    return

ALL is a list of notebooks, line-numbers and lines that contain the search term: example: All=["The term mask exists in ./arrays-for-seamless-cloning-checkpoint.ipynb .\nLineNumber:', 426, ' "# Create a rough mask around the nose",\n')", "The term mask exists in ./cloning-checkpoint.ipynb .\nLineNumber:', 426, ' "# Create a rough mask around the eyes",\n')"]

for line in ALL:
    print(line)
    data = line
    insert(data)

I need to insert this result from my search into an sqlite3 database

data = '''('The term mask exists in ./save-image-and-array-for-seamless-cloning-checkpoint.ipynb .\nLineNumber:', 426, '    "# Create a rough mask around the nose",\n')'''

---------------------------------------------------------------------------
InterfaceError                            Traceback (most recent call last)
Input In [35], in <cell line: 31>()
     31 for line in ALL:
     32     print(line)
---> 33     insert(line,)

Input In [35], in insert(data)
      4 conn.text_factory = str
      5 c = conn.cursor()
----> 6 c.execute("INSERT into PROJECT values (?)", (data,))
      7 for row in c.execute("SELECT ROWID,* FROM PROJECT ORDER BY ROWID DESC LIMIT 1"):
      8     print ("\nPOST VERIFIED:\n",row[0],row[1])

InterfaceError: Error binding parameter 0 - probably unsupported type.

I want to search Jupyter Notebooks for terms and enter the results in and database. I have a hundreds of notebook with loads of snippets. It will be an easy search process.

1 Answers
Related