From e616b27e2f920be68c6634f6ccd5bd49b10f9351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Sat, 1 Apr 2023 14:58:22 -0300 Subject: [PATCH] =?UTF-8?q?execute=20e=20executemany=20com=20dicion=C3=A1r?= =?UTF-8?q?ios=20e=20lista=20de=20dicion=C3=A1rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula205/main.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/aula205/main.py b/aula205/main.py index 02524a0..5bccf19 100644 --- a/aula205/main.py +++ b/aula205/main.py @@ -34,15 +34,22 @@ sql = ( f'INSERT INTO {TABLE_NAME} ' '(name, weight) ' 'VALUES ' - '(?, ?)' + '(:nome, :peso)' ) # cursor.execute(sql, ['Joana', 4]) -cursor.executemany( - sql, - ( - ('Joana', 4), ('Luiz', 5) - ) -) +# cursor.executemany( +# sql, +# ( +# ('Joana', 4), ('Luiz', 5) +# ) +# ) +cursor.execute(sql, {'nome': 'Sem nome', 'peso': 3}) +cursor.executemany(sql, ( + {'nome': 'Joãozinho', 'peso': 3}, + {'nome': 'Maria', 'peso': 2}, + {'nome': 'Helena', 'peso': 4}, + {'nome': 'Joana', 'peso': 5}, +)) connection.commit() print(sql)