简体   繁体   中英

How do I Insert unknown amounts of data into a sqlite3 database

I have built some presentation software using python3 and flask where users can select photos to purchase and be placed into a cart. The URLs for these photos get placed into a database.

At the moment I have built a database that can input up to six photos but these are explicit and doesn't seem like an elegant solution.

Is there a way that I can add an unknown amount of photos to the database to make it more efficient? This code does work but I want it to be more efficient and manageable.

 def insert(self, name, img1, img1Size, img2, img2Size, img3, img3Size, img4, img4Size, img5, img5Size, img6, img6Size, price, completed):
        with sql.connect(DATABASE) as con:
            cur = con.cursor()
            cur.execute("INSERT INTO orders (name, img1, img1Size, img2, img2Size, img3, img3Size, img4, img4Size, img5, img5Size, img6, img6Size, price, completed) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (name, img1, img1Size, img2, img2Size, img3, img3Size, img4, img4Size, img5, img5Size, img6, img6Size, price, completed))
            con.commit()
            print("Success")

您需要一个表来存储您的列表,并且该表中的一个字段与订单相关。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM