0

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?

2
  • What have you tried? Have you looked at the actual query string you are composing? (Hint: it's not correct.) Commented Jul 13, 2012 at 23:19
  • 1
    Also, please don't do things this way. You open yourself to SQL injection problems. Use prepared statements instead. Commented Jul 13, 2012 at 23:29

3 Answers 3

3

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

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

Comments

2

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.

Comments

2
// **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);

2 Comments

I think you are barking up the wrong tree. String literals must be enclosed in single quotes within SQL.
@dbenham I have based on mysql, Why you just edit the answer to fix then?

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.