1
print(index)
split = index.split(',')
split = split[0].split(' ')
print(split)
print(split[1])
if split[1] == '': ####It's working
    c.execute("SELECT * FROM registros WHERE ID = ?", split[2])
    for row in c.fetchall():
        c.execute("UPDATE registros SET datasaida = ?,valor = ? WHERE ID = ?", (dateout, valor, split[2]))
else:             ####It's not working
    a = split[1]
    c.execute("SELECT * FROM registros WHERE ID = ?", str(split[1]))
    for row in c.fetchall():
        c.execute("UPDATE registros SET datasaida = ?,valor = ? WHERE ID = ?", (dateout, valor, split[1]))

10, qwerwe 30/11/2017 13:45

['', '10']

10

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ThomasCaio\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/PycharmProjects/Project/Program.py", line 399, in <lambda>
but1 = ttk.Button(pop,text='Encerrar serviço',command=lambda:self.Saida())
File "C:/PycharmProjects/Project/Program.py", line 422, in Saida
c.execute("SELECT * FROM registros WHERE ID = ?", str(split[1]))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.

The if is working well but the else, that has the same code, doesn't working What happenned?

Thomas Caio
  • 83
  • 1
  • 1
  • 11
  • 1
    You are passing in a string of length 2 here: `c.execute("SELECT * FROM registros WHERE ID = ?", str(split[1]))`. You need to put your parameters *in a tuple or other sequence*, not pass them in as a single value: `c.execute("SELECT * FROM registros WHERE ID = ?", (split[1],))` would work, for example. – Martijn Pieters Nov 30 '17 at 22:02
  • I wasted 1 hour trying to do something it that, thank you, mate! But why I need to put it into a tuple? – Thomas Caio Nov 30 '17 at 22:08
  • 1
    Because that second argument is *always* a sequence, the first element will be used for the first `?` placeholder, the second for the second `?`, etc. A string is a sequence to (of single characters), and if the number of elements in the sequence don't match the number of `?` placeholders, then that's an error. So you need to make sure the second argument is a sequence *containing* a string as the only element. You can also make it a list, so `[split[1]]` as the second argument. – Martijn Pieters Nov 30 '17 at 22:10

0 Answers0