From 87b081fd09db5e03d4e65383cbaf1e44c931b85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Sat, 15 Apr 2023 12:28:18 -0300 Subject: [PATCH] =?UTF-8?q?Inserindo=20valores=20usando=20dicion=C3=A1rios?= =?UTF-8?q?=20ao=20inv=C3=A9s=20de=20iter=C3=A1veis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula206/main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/aula206/main.py b/aula206/main.py index 9c645a2..2330cc3 100644 --- a/aula206/main.py +++ b/aula206/main.py @@ -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()