access database data from a specific colula

Asked

Viewed 29 times

1

I have a database with a list_students table, str(name) field and str(serie) field, someone can explain me why I can’t access the names that contain only the series I passed?

conn = sqlite3.connect('bd/obj.db')
c = conn.cursor()
c.execute('SELECT nome FROM lista_alunos WHERE serie = ?', botao.text,)
for i in c.fetchall():
    print(i[3])
conn.close() 

Botao.text is also a string.

  • Your query returns only one column and in the loop for you try to print a missing fourth column. Where is print(i[3]) do print(i[0]).

  • I had already tested, and I was able to access i[0] by buffering (botao.text). What I found very strange because when I try with other columns it accepts without buffer.

  • In the execute has an extra comma after botao.text.

  • Actually the comma is necessary because the second argument is a tuple, but even the way it is, when I access another column that is not serial it prints the values normally.

  • 1

    I managed to solve, I changed the way I write the data in the comic book, I took sqlite3.Inary() and it worked.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.