简体   繁体   English

如何将未知数量的数据插入到 sqlite3 数据库中

[英]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.我使用python3和flask构建了一些演示软件,用户可以在其中选择要购买的照片并将其放入购物车。 The URLs for these photos get placed into a database.这些照片的 URL 被放入数据库中。

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")

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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