From 21cea9e2548667b0671c4439c7117e8012cbca41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Sat, 15 Apr 2023 19:35:48 -0300 Subject: [PATCH] =?UTF-8?q?Trocando=20o=20cursor=20para=20retornar=20dicio?= =?UTF-8?q?n=C3=A1rios=20-=20pymysql.cursors.DictCursor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula206/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aula206/main.py b/aula206/main.py index 3769c14..ebe24fb 100644 --- a/aula206/main.py +++ b/aula206/main.py @@ -6,6 +6,7 @@ import os import dotenv import pymysql +import pymysql.cursors TABLE_NAME = 'customers' @@ -16,7 +17,8 @@ connection = pymysql.connect( user=os.environ['MYSQL_USER'], password=os.environ['MYSQL_PASSWORD'], database=os.environ['MYSQL_DATABASE'], - charset='utf8mb4' + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor, ) with connection: @@ -148,6 +150,10 @@ with connection: cursor.execute(sql, ('Eleonor', 102, 4)) # type: ignore cursor.execute(f'SELECT * FROM {TABLE_NAME} ') # type: ignore + # for row in cursor.fetchall(): # type: ignore + # _id, name, age = row + # print(_id, name, age) + for row in cursor.fetchall(): # type: ignore print(row) connection.commit()