1

I am simply trying to increment field value by 1. It spit the error that had to do something with long value of object sequence_id

db.execute('SELECT id FROM sstudio_queues_sequence')
        sequence_id = db.fetchone()[0]
        sequence_id = sequence_id + 1
        db.execute("UPDATE sstudio_queues_sequence SET id=%s", (sequence_id))
vitalii maximov
  • 89
  • 1
  • 11

1 Answers1

0

The second argument to db.execute should be a sequence (or mapping), not a scalar value:

db.execute("UPDATE sstudio_queues_sequence SET id=%s", 
           [sequence_id])

You could use a tuple, (e.g. (sequence_id,)), or a list (e.g. [sequence_id], as shown above).

With paretheses only, (sequence_id) is evaluated to the same thing as sequence_id. It is the comma after sequence_id which makes (sequence_id,) a tuple.

Community
  • 1
  • 1
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Thank you, I am gonna try it. – vitalii maximov Jan 13 '15 at 18:43
  • wait is there a reason why you dropped the second part of the argument to the next line and indent it ? – vitalii maximov Jan 13 '15 at 18:45
  • I put `[sequence_id]` on the second line only so that the important part of the solution (as formatted by StackOverflow) shows up clearly, not requiring viewers to use the scrollbar to find the answer. (See also ["implied line continuation" in the PEP8 style guide](https://www.python.org/dev/peps/pep-0008/).) – unutbu Jan 13 '15 at 18:46