Nella mia applicazione sto implementando ora una parte che ha bisogno di un database e sto avendo subito un problema.
Questa funzione viene eseguita correttamente, in clients c'è la lista dei nomi dei clienti
codice:
def getClientsNames(self, orderby='id', direction='ASC'):
"""Get all the clients."""
clients = []
query = QSqlQuery()
query.exec(f'SELECT nome FROM {self._tab_clients} ORDER BY {orderby} {direction}')
while query.next():
clients.append(query.value('nome'))
return clients
Di contro quest'altra, che dovrebbe fare la stessa cosa, mi restituisce una lista vuota
codice:
def getClientsNames(self, orderby='id', direction='ASC'):
"""Get all the clients."""
clients = []
query = QSqlQuery()
query.prepare('SELECT nome FROM :table ORDER BY :orderby :direction')
query.bindValue(":table", self._tab_clients)
query.bindValue(":orderby", orderby)
query.bindValue(":direction", direction)
query.exec()
while query.next():
clients.append(query.value('nome'))
return clients
Cosa sbaglio nell'uso del prepared statement?