Inserindo valores usando dicionários ao invés de iteráveis
This commit is contained in:
@@ -44,6 +44,23 @@ with connection:
|
||||
)
|
||||
data = ('Luiz', 18)
|
||||
result = cursor.execute(sql, data) # type: ignore
|
||||
print(sql, data)
|
||||
# print(sql, data)
|
||||
# print(result)
|
||||
connection.commit()
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
sql = (
|
||||
f'INSERT INTO {TABLE_NAME} '
|
||||
'(nome, idade) '
|
||||
'VALUES '
|
||||
'(%(name)s, %(age)s) '
|
||||
)
|
||||
data2 = {
|
||||
"age": 37,
|
||||
"name": "Le",
|
||||
}
|
||||
result = cursor.execute(sql, data2) # type: ignore
|
||||
print(sql)
|
||||
print(data2)
|
||||
print(result)
|
||||
connection.commit()
|
||||
|
||||
Reference in New Issue
Block a user