0

I need to pass a python dict to a database with SQL.

one of my dicts is:

print(student[1])

{'first': 'Adrian', 'house': 'Slytherin', 'birth': '1977', 'middle': 'NULL', 'last': 'Pucey'}

I want to fill the database with this code:

db = SQL("sqlite:///students.db")   #grant acces to data base in SQL


db.executemany("""
    INSERT INTO
        students
        (first, house, birth, middle, last)
    VALUES
        (%(first)s, %(house)s, %(birth)s, %(middle)s, %(last)s)
""", student[1])

The return I got is: AttributeError: 'SQL' object has no attribute 'executemany'

What I've done wrong?

What to do in order to inject a python dict with SQL?

Thanks in advance,

1 Answer 1

1

executemany is included in the python sqlite3 library, but not in the cs50 SQL library. One option would be to iterate over the dict and insert one row at a time.

1
  • Thanks. I think iterative methode could load more the DB, but no choice. I'll stick with this methode.
    – saquiel
    Commented Jan 30, 2020 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .