开发者

Writing a single table value in sqlite3

开发者 https://www.devze.com 2023-03-18 07:16 出处:网络
I have a Python 2.7 project, and I\'m using (and learning) sqlite3. How开发者_如何学C do I save a variable from python to a single existing column and row in an sqlite3 database?Say you have a table

I have a Python 2.7 project, and I'm using (and learning) sqlite3.

How开发者_如何学C do I save a variable from python to a single existing column and row in an sqlite3 database?


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". You would use this SQL query:

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. I am a big fan of Storm. You can find it here:

https://storm.canonical.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消