python sqlite3 update not updating

2024/9/29 21:30:17

Question: Why is this sqlite3 statement not updating the record?


Info:

cur.execute('UPDATE workunits SET Completed=1 AND Returns=(?) WHERE PID=(?) AND Args=(?)',(pickle.dumps(Ret),PID,Args))

I'm using python and sqlite3. this statement does not throw an error, it just seems like it is out right ignored. for testing reasons I included below it:

cur.execute('SELECT * FROM workunits WHERE PID=(?) AND Args=(?)',(PID,Args))

Which returns a record just fine. but the record doesn't up date with the new value of the pickled ret. it remains u''. I can't figure out why. my where statement seems to work. my syntax seems to be correct because there is no error being thrown. I'm clueless as to why exactly it doesn't work.

Answer

If the problem persists after you fixed your syntax. Please make sure you're using:

conn.commit()

After cur.execute, UPDATES and INSERTS require COMMIT.

https://en.xdnf.cn/q/71164.html

Related Q&A

Unable to reinstall PyTables for Python 2.7

I am installing Python 2.7 in addition to 2.7. When installing PyTables again for 2.7, I get this error -Found numpy 1.5.1 package installed. .. ERROR:: Could not find a local HDF5 installation. You ma…

How can I invoke a thread multiple times in Python?

Im sorry if it is a stupid question. I am trying to use a number of classes of multi-threading to finish different jobs, which involves invoking these multi-threadings at different times for many times…

Matplotlib interactive graph embedded in PyQt

Ive created a simple python script that when run should display an embedded matplotlib graph inside a PyQT window. Ive used this tutorial for embedding and running the graph. Aside from some difference…

How to pass path names to Python script by dropping files/folders over script icon

I am working in Mac OS X and have been writing simple file/folder copy scripts in Python. Is there a way to drag and drop a folder on top of a Python script icon and pass the file or folders path as an…

Why wouldnt I want to add Python.exe to my System Path at install time?

Im reinstalling Python, on Windows 7, and one of the first dialog boxes is the Customize Python screen.The default setting for "Add Python.exe to Path" is "Entire feature will be unavail…

How to install python-gtk2, python-webkit and python-jswebkit on OSX

Ive read through many of the related questions but am still unclear how to do this as there are many software combinations available and many solutions seem outdated.What is the best way to install the…

Forking python, defunct child

I have some troubles with Python child processes so I wrote a very simple script:import os import sys import timepid = os.fork() if pid:#parenttime.sleep(30) else:#child#os._exit(0)sys.exit()While pare…

is there a way to know the length of a bytearray variable in python?

I have this code:variable = "FFFF" message = bytearray( variable.decode("hex") )after this, I want to perform something like this:message.len()but it seems that bytearray does not h…

Matplotlib: Check for empty plot

I have a loop which loads and plots some data, something like this:import os import numpy as np import matplotlib.pyplot as pltfor filename in filenames:plt.figure()if os.path.exists(filename):x, y = n…

Hyperlink in Streamlit dataframe

I am attempting to display a clickable hyperlink inside a dataframe containing filtered results on Streamlit. This is my code so far: import pandas as pd import streamlit as st import openpyxl import n…