From 8b555fb64079455c0c7a05905e650295dee3ebad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Sat, 15 Apr 2023 12:45:54 -0300 Subject: [PATCH] =?UTF-8?q?Inserindo=20v=C3=A1rios=20valores=20com=20uma?= =?UTF-8?q?=20consulta=20s=C3=B3=20usando=20iter=C3=A1veis=20ou=20dicion?= =?UTF-8?q?=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula206/main.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/aula206/main.py b/aula206/main.py index 2330cc3..4bab0eb 100644 --- a/aula206/main.py +++ b/aula206/main.py @@ -60,7 +60,42 @@ with connection: "name": "Le", } result = cursor.execute(sql, data2) # type: ignore + # print(sql) + # print(data2) + # print(result) + connection.commit() + + with connection.cursor() as cursor: + sql = ( + f'INSERT INTO {TABLE_NAME} ' + '(nome, idade) ' + 'VALUES ' + '(%(name)s, %(age)s) ' + ) + data3 = ( + {"name": "Sah", "age": 33, }, + {"name": "JĂșlia", "age": 74, }, + {"name": "Rose", "age": 53, }, + ) + result = cursor.executemany(sql, data3) # type: ignore + # print(sql) + # print(data3) + # print(result) + connection.commit() + + with connection.cursor() as cursor: + sql = ( + f'INSERT INTO {TABLE_NAME} ' + '(nome, idade) ' + 'VALUES ' + '(%s, %s) ' + ) + data4 = ( + ("Siri", 22, ), + ("Helena", 15, ), + ) + result = cursor.executemany(sql, data4) # type: ignore print(sql) - print(data2) + print(data4) print(result) connection.commit()