Home > database >  SQLite AUTO_INCREMENT id field is upside down on the program
SQLite AUTO_INCREMENT id field is upside down on the program

Time:09-16

here a pic to a better understand [1]: https://i.stack.imgur.com/S6tpl.png

def consult(self):
    book = self.cuadro_blanco_cliente.get_children()
    for elementos in book:
        self.cuadro_blanco_cliente.delete(elementos)
    query = "SELECT Nro, codigo, nombre, nfc, telefono, celular,direccion FROM clientes"#
    rows = self.run_query(query)#query
    for row in rows:
        self.cuadro_blanco_cliente.insert('',0, text=row[1],values=row)

CodePudding user response:

The problem isn't on the id field, is in the way you are using to add the rows on the display. You are traversing the array from id 1 to n, but adding the rows always to the beginning, making it look like the ids go from n to 1.

Try adding this at the end of your query clause:

"... ORDER BY id DESC"

This way, you will insert first, the last element, and then insert the other rows before the last, and so on, securing the fetched rows are ordered by id.

CodePudding user response:

I added some lines to the code, and fixed the problem, begin from 1 now

for row in rows:
        id = row[0]
        self.cuadro_blanco_cliente.insert("",END, id, text=id, values=row)
  • Related