简体   繁体   English

在 sqlite3 中写入单个表值

[英]Writing a single table value in sqlite3

I have a Python 2.7 project, and I'm using (and learning) sqlite3.我有一个 Python 2.7 项目,我正在使用(和学习)sqlite3。

How do I save a variable from python to a single existing column and row in an sqlite3 database?如何将变量从 python 保存到 sqlite3 数据库中的单个现有列和行?

Say you have a table named "records" with the column "X", and each entry has a different "X" value, and let's say you want to change the value of column "Y".假设您有一个名为“records”的表,其中列“X”,每个条目都有不同的“X”值,假设您要更改列“Y”的值。 You would use this SQL query:您将使用此 SQL 查询:

cursor.execute("update records set y = ? where x = ?", (y, x))

If you are not familiar with SQL, you could try using an ORM, which maps DB tables to python classes and objects.如果您不熟悉 SQL,您可以尝试使用 ORM,它将 DB 表映射到 python 类和对象。 I am a big fan of Storm.我是风暴的忠实粉丝。 You can find it here:你可以在这里找到它:

https://storm.canonical.com/ https://storm.canonical.com/

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

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