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?

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

3 Answers3

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

Community
  • 1
  • 1
dm03514
  • 54,664
  • 18
  • 108
  • 145
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);
GTSouza
  • 365
  • 4
  • 16
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.

jbindel
  • 5,535
  • 2
  • 25
  • 38