Python Psycopg2 |在数据库中计数加上
我得到了带有自旋框和一个按钮的Pyqt5 GUI。我已经写了一篇文字,当我单击按钮时,这就是数据库中的Spinbox中的数字。 可悲的是,它代替了我的旧价值。在我的数据库中,我得到了一个名为“小时”的值。 假设该值现在为12。如果我现在单击我的按钮,它应该从GUI中输入的Spinbox中添加我的号码到12。
def test():
conn = None
try:
conn = psycopg2.connect("dbname=ueberstunden user=postgres password=admin")
value = self.box_test.value()
cur = conn.cursor()
cur.execute("UPDATE ueberstunden SET stunden = %s WHERE name ='test'", value)
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
I got a PyQt5 GUI with a spinbox and a button. I already wrote a statement that writes the number, thats in the spinbox in the database, when I click my button.
Sadly it substitutes my old value. In my database I got a value named "hours".
Let's say the value right now is 12. And if I click my button now it should add my number from the spinbox I typed in the GUI to the 12.
def test():
conn = None
try:
conn = psycopg2.connect("dbname=ueberstunden user=postgres password=admin")
value = self.box_test.value()
cur = conn.cursor()
cur.execute("UPDATE ueberstunden SET stunden = %s WHERE name ='test'", value)
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在作业右侧使用表达式。在这里,您需要用当前值分配
studen
,即,studen
加上新值:You can use expressions on the right side of an assignment. Here, you'd want to assign
studen
with the current value, i.e.,studen
plus the new value: