Lendo valores com WHERE (mais uma vez, explico cuidados com SQL Injection)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user