2

My update statement in MySQL doesn't appear to be working:

timeup = "UPDATE timeid set time=\"" + str(timeid) + "\""
c.execute(timeup)

I've tried everything I thought might be wrong with it, including changing the type of the variable (as you can see above, I have it as a string) and using and not using quotes.

I can even print out what the statement turns into:

UPDATE timeid set time="224215313716215808"

The only column and value that timeid has is time and 0, respectively.

Why isn't this updating? Am I doing something wrong?

3 Answers 3

2

You need to use:

c.commit();

since MySQLdb begins a transaction for update statements.

Sign up to request clarification or add additional context in comments.

Comments

1

Try:

timeup = "UPDATE `timeid` SET `time`='" + str(timeid) + "';"
c.execute(timeup)

Time might be a constant in SQL and therefore using the simple quotation marks (I don't know, how they are called) ensures that you refer to a field. And try to use ' for setting the value and consider adding a semicolon.

Did you select a database before?

4 Comments

Yes, database is selected. I've changed my query to this: timeup = "UPDATE timeid set timestamp='" + str(timeid) + "';"
I do not know python, but maybe there is a function, which can give you some more detailled information about a possible error being returned by the MySQL-database.
I can't find any, tragically. This problem seems unsolvable to me - everything I'm doing seems to be right.
Does the same query you have the output of (UPDATE timeid set time="224215313716215808") work using any other software, like phpMyAdmin?
-1

Try to add a semicolon (;) at the end of the query and tell me if it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.