Lendo valores com WHERE (mais uma vez, explico cuidados com SQL Injection)

This commit is contained in:
Luiz Otávio
2023-04-15 15:52:39 -03:00
parent 20f85e42c4
commit c0c3e77853

View File

@@ -97,6 +97,7 @@ with connection:
data4 = (
("Siri", 22, ),
("Helena", 15, ),
("Luiz", 18, ),
)
result = cursor.executemany(sql, data4) # type: ignore
# print(sql)
@@ -106,10 +107,16 @@ with connection:
# Lendo os valores com SELECT
with connection.cursor() as cursor:
menor_id = int(input('Digite o menor id: '))
maior_id = int(input('Digite o maior id: '))
sql = (
f'SELECT * FROM {TABLE_NAME} '
'WHERE id BETWEEN %s AND %s '
)
cursor.execute(sql) # type: ignore
cursor.execute(sql, (menor_id, maior_id)) # type: ignore
print(cursor.mogrify(sql, (menor_id, maior_id))) # type: ignore
data5 = cursor.fetchall() # type: ignore
for row in data5: