0
I’m on a quest and I still can’t solve it. Here’s the thing:
def main():
chave = [valores_lidos]
while(chave!=-1):
vetor = valores_lidos
chave= int(input("Informe o numero de id da vaca para buscar a ultima ordenha: "))
posicao = busca_binaria(vetor, 0, len(vetor) - 1, chave)
if posicao <=0 :
print("a vaca %d nao foi encontrado." % chave)
break
else:
print(f"A vaca de nº %d foi encontrada e sua ultima ordenha foi em {data}" % chave)
print("Busca concluida! ")
break
main()
In the script
above, the variable CHAVE
receives a number and I need to use this number inserted in this variable to search in mysql. Below is the search script in mysql. I know I’m doing it wrong, but I don’t know what the right way is. Someone can help out here. It is an academic work and my deadline is at the end.
import mysql.connector
from mysql import connector
conexao = mysql.connector.connect(user = 'root', password = 'root',
host='localhost',
database = 'fazenda_bd')
comando_sql2 = 'select data_ordenha from leite where id = chave'
curs.execute(comando_sql2)
valores_lidos2 = curs.fetchall()
lista = (valores_lidos2)
nova =str(' '.join([str(_) for _ in lista]))
data = nova[1:30].replace(', ', '/')
print(data)
The first line after the import that is the search in mysql.
OBS:
I didn’t post the entire code. It’s a binary search. I guess there’s no need to post everything. If need be, tell me which post the rest