[Python-de] Re: sqlite3-datenbank

Hartmut Goebel <[email protected]> Fri, 9 Feb 2024 09:59:21 +0100
Newsgroups gmane.comp.python.general.german
Organization Goebel Consult
Message-ID <[email protected]>
Am 08.02.24 um 19:31 schrieb Detlef Heiler:

> sqlite3.OperationalError: table Geburtstage has 1 columns but 3 values were
> supplied

Das steht recht klar, dass die Tabelle nur eine Spalte hat, Du aber drei 
einfügen möchtest. sind die "Zeilen" in "data" unten bei Dir ganz sicher 
Tupel oder Listen? Tupel mit nur einem Element brauchen am Ende, noch 
innerhalb der Klammern ein Komma, um ein Tupel zu bilden:

data = [
    ("zzzz"),    # kein Tupel!
    ("aaaa",),     # <-- Komma in der Klammer
    ["bbb"],      # Listen werden an den eckigen Klammern erkannt, daher 
kein Komma nötig
]

> Tja, wie kriege ich die verschachtelte Liste
> in die Datenbank? Bin sehr gespannt.

Wenn Du Deinen Code gepostet hättest, könnten wir genauer sagen, was 
falsch ist. So kann ich nur mit dem Code-Schnipsel aus dem 
Python-Handbuch antworten. Im Prinzip muss es so aussehen:

data  =  [
     ("Monty Python Live at the Hollywood Bowl",  1982,  7.9),
     ("Monty Python's The Meaning of Life",  1983,  7.5),
     ("Monty Python's Life of Brian",  1979,  8.0),
]
cur.executemany("INSERT INTO movie VALUES(?, ?, ?)",  data)
con.commit()   # Remember to commit the transaction after executing INSERT.

-- 
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software 
Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog: https://www.goebel-consult.de/blog/2019/blockchain-bringts-nicht/
Kolumne: 
https://www.goebel-consult.de/blog/cissp-gefluester/2011-08-horrorszenario-bring-your-own-device/ 

_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]