0

new to python and sqlite, so I'm trying to update my sqlite database.

I have x amount of columns on the rows filled in, the rest are null. I then wish to come back to these rows and update the columns i have yet to fill in that are null.

How do I update a row by adding in new data that has yet to be enterd?

I will show below that I've tried to find the correct row to update using WHERE and i use SET to set these new values.

The setup:

    c.execute('CREATE TABLE IF NOT EXISTS PowerSysInfo(time REAL, NumOfNodes INT, NumOfBuses INT, BusLocation TEXT, PhaseNumber INT, v1 REAL, a1 REAL, phase1 INT, v2 REAL, a2 REAL, phase2 INT, v3 REAL, a3 REAL, phase3 INT)')

Enter my rows:

                    c.execute("INSERT INTO PowerSysInfo(time, NumOfNodes, NumOfBuses, BusLocation, PhaseNumber, v1, a1, phase1) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ",
                              (mins, numNode, Numbus, bus, numNode, busVoltages[i], busVoltages[i+1], node))
                    conn.commit()

Now when i try to update the above row with:

                   c.execute("UPDATE PowerSysInfo SET v2 = ?, a2 = ?, phase2 = ? WHERE time = ?, BusLocation = ?", [busVoltages[i], busVoltages[i+1], node, mins, bus]) 
                   conn.commit()

I get OperationalError: near ",": syntax error

I've been looking at update statements, can't find one for exactly updating null with a variable. But why will this not work?

Thanks in advance for the help.

1
  • Since this is getting ignored, I will add context. I tried the first line of code on this solution which is causing me this error stackoverflow.com/questions/16322031/… Commented Nov 22, 2016 at 5:29

1 Answer 1

0

In the list of columns to be updated, the entries are separated by commas.

In the WHERE clause, you must specify a single expression, so using commas does not make sense. To combine two boolean conditions into a larger one, use AND.

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

2 Comments

Thank you very much
So a where condition met is viewed as a boolean in SQLite?

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.