Your supposed to get 20. Your database has 20 columns, so you should be getting 20 values. I'm curious what the set_name column is for though. If it's not being used for anything, remove it, and remove it in the tuple. Then try reexecuting the statement again.
Another way to debug this is to open sqlite3's console and execute the statements one at a time. It's slower, for sure, but it will allow you to see what goes wrong where. So, back-up the current code you have, then change your python code to something like:
import sqlite3 from mtgsdk import Card
def main(): dbFile = "cards.db" connection = createConnection(dbFile) cards = Card.where(name="The Great Aurora").all() cardProperties = getCardProperties(cards) insertCard(connection, cardProperties) def getCardProperties(card): names = joinList(card.names) colors = joinList(card.colors) color_identity = joinList(card.color_identity) supertypes = joinList(card.supertypes) subtypes = joinList(card.subtypes) legalities = formatLegalities(card.legalities) return (1, card.name, card.multiverse_id, names, card.mana_cost, card.cmc, colors, color_identity, card.type, supertypes, subtypes, card.rarity, card.text, card.flavor, card.power, card.toughness,card.loyalty, card.rulings, legalities,card.set_name) def joinList(cardProperty): if cardProperty != None: return "|".join(cardProperty) return cardProperty def formatLegalities(legalities): if legalities == None: return legalities legalitiesStr = "" legalitiesLength = len(legalities) for index in range(0, legalitiesLength): legalitiesStr += legalities[index]["format"] + ": " legalitiesStr += legalities[index]["legality"] if (index + 1) != legalitiesLength: legalitiesStr += "|" return legalitiesStr def createConnection(dbFile): try: connection = sqlite3.connect(dbFile) return connection except Error as e: print(e) return None def insertCard(connection, cardProperties): sql = "INSERT INTO Cards VALUES(" cur = connection.cursor() cardPropertiesLength = len(cardProperties) for index in range(cardPropertiesLength): if cardProperties[index] == None: sql += "NULL" else: sql += "?" if (index + 1) != cardPropertiesLength: sql += "," sql += ");" temp = filter(None, cardProperties) temp = tuple(temp) # cur.execute(sql, temp) print (temp) main()
That will give you the SQL statement generated. execute that in sqlite3 and see if it successfully executes. Then delete the data and fix the problem after that. (Alternatively, create a new database file as a temporary DB, set the DB file to the temp DB and execute the statement on that DB. Then delete the DB and fix the error then.)
_______________________________________________ Audiogames-reflector mailing list Audiogamesfirstname.lastname@example.org https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector