ich hole mir aus einer MySQL Datenbank eine Liste mit 1-n IDs:
Code: Alles auswählen
cursor.execute ("""SELECT DocType_ID FROM DocType WHERE DocType_Token = %s""", (TypeShort))
TypeIDs = cursor.fetchall()
Code: Alles auswählen
TypeIDs = ((1L,), (3L,))
Code: Alles auswählen
TypeID = [ ]
for id in TypeIDs:
TypeIDList.extend(id)
cursor.execute ("""SELECT COUNT(Key_Count) FROM Document WHERE Type IN (%s)""" , (TypeIDList))
da der Befehl umgewandelt wird zu(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[1L, 3L])' at line 1")
SELECT COUNT(Key_Count) FROM Document WHERE Type IN ([1L, 3L])
Wie muß ich es richtig machen?
Und: Geht es nicht auch ohne, daß ich die Rückgabe des ersten SELECTS nochmal über eine For-Schleife umkoche (sicher gehts
