Can someone help me with the following code? I have more than 130 records, and using fetchall()
gives me all of them which makes the data impossible to read. Instead I would prefer to fetch 10 records at a time (using the Enter key for instance).
This is my code:
def getAllPerguntasDB(self):
query = "SELECT p.id_pergunta,t.tema,d.grau,p.pergunta,p.op1,p.op2,p.op3,p.op4,p.correto FROM perguntas AS p INNER JOIN temas AS t ON (p.id_tema = t.id_tema) INNER JOIN dificuldade AS d ON (p.id_grau = d.id_grau) ORDER BY t.tema, d.grau ASC;"
self.cur.execute(query)
self.result = self.cur.fetchall()
for row in self.result:
id_pergunta = row[0]
tema = row[1]
grau = row[2]
pergunta = row[3]
op1 = row[4]
op2 = row[5]
op3 = row[6]
op4 = row[7]
correto= row[8]
print('---------------------------------------------------------------------------------------')
print("id: ", id_pergunta)
print("Tema:",tema,"\tGrau:",grau)
print("Pergunta: ", pergunta)
print("Opção 1: ", op1, "\tOpção 2: ", op2, "\tOpção 3: ", op3, "\tOpção 4: ", op4)
print("Resposta Correta: ", correto)
print('---------------------------------------------------------------------------------------')