Evite SQL Injection ao usar placeholders para enviar valores para consulta SQL
This commit is contained in:
@@ -36,17 +36,14 @@ with connection:
|
|||||||
# Começo a manipular dados a partir daqui
|
# Começo a manipular dados a partir daqui
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute( # type: ignore
|
sql = (
|
||||||
f'INSERT INTO {TABLE_NAME} '
|
f'INSERT INTO {TABLE_NAME} '
|
||||||
'(nome, idade) VALUES ("Luiz", 25) '
|
'(nome, idade) '
|
||||||
)
|
'VALUES '
|
||||||
cursor.execute( # type: ignore
|
'(%s, %s) '
|
||||||
f'INSERT INTO {TABLE_NAME} '
|
|
||||||
'(nome, idade) VALUES ("Luiz", 25) '
|
|
||||||
)
|
|
||||||
result = cursor.execute( # type: ignore
|
|
||||||
f'INSERT INTO {TABLE_NAME} '
|
|
||||||
'(nome, idade) VALUES ("Luiz", 25) '
|
|
||||||
)
|
)
|
||||||
|
data = ('Luiz', 18)
|
||||||
|
result = cursor.execute(sql, data) # type: ignore
|
||||||
|
print(sql, data)
|
||||||
print(result)
|
print(result)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user