Reputation: 241
I'm posting this, and getting this error:
c.execute("""update resulttest set category=""" + key + ", value=""" + str(value))
OperationalError: (1054, "Unknown column 'composed' in 'field list'")
I am trying to update the columns category and field, composed is simply a value in category.
Why is this error coming up?
Upvotes: 0
Views: 99
Reputation: 365
// **mysql based**
string cmd = "UPDATE resulttest SET category=\"" + key + "\", value=\"" + str(value) + "\"";
// **sql based**
string cmd = "UPDATE resulttest SET category='" + key + "', value='" + str(value) + "'";
// make sure you command output a escaped format
// UPDATE resulttest SET category='test', value='test'
// UPDATE resulttest SET category="test", value="test"
c.execute(cmd);
Upvotes: 2
Reputation: 55942
You can use interpolation and parameterized queries for easier to read syntax, no escaping quotes or anything.
c.execute("""update resulttest set category=?, value=?""", (key, value))
https://stackoverflow.com/a/775399/594589
Upvotes: 3
Reputation: 5635
You might see something interesting if you generate the query string and then print it out before you try to execute it. Have you tried that?
I think your quotation marks are probably not done correctly. That is, perhaps you want the query to look like this:
update resulttest set category='somekey', value='composed'
I don't think that is what you'll get for the query string you are composing.
Upvotes: 2