rowcount, rownumber e lastrowid para detalhes de consultas executadas
This commit is contained in:
@@ -10,7 +10,7 @@ import pymysql
|
|||||||
import pymysql.cursors
|
import pymysql.cursors
|
||||||
|
|
||||||
TABLE_NAME = 'customers'
|
TABLE_NAME = 'customers'
|
||||||
CURRENT_CURSOR = pymysql.cursors.SSDictCursor
|
CURRENT_CURSOR = pymysql.cursors.DictCursor
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
@@ -152,18 +152,26 @@ with connection:
|
|||||||
'WHERE id=%s'
|
'WHERE id=%s'
|
||||||
)
|
)
|
||||||
cursor.execute(sql, ('Eleonor', 102, 4))
|
cursor.execute(sql, ('Eleonor', 102, 4))
|
||||||
cursor.execute(f'SELECT * FROM {TABLE_NAME} ')
|
|
||||||
|
|
||||||
print('For 1: ')
|
cursor.execute(
|
||||||
for row in cursor.fetchall_unbuffered():
|
f'SELECT id from {TABLE_NAME} ORDER BY id DESC LIMIT 1'
|
||||||
|
)
|
||||||
|
lastIdFromSelect = cursor.fetchone()
|
||||||
|
|
||||||
|
resultFromSelect = cursor.execute(f'SELECT * FROM {TABLE_NAME} ')
|
||||||
|
|
||||||
|
data6 = cursor.fetchall()
|
||||||
|
|
||||||
|
for row in data6:
|
||||||
print(row)
|
print(row)
|
||||||
|
|
||||||
if row['id'] >= 5:
|
print('resultFromSelect', resultFromSelect)
|
||||||
break
|
print('len(data6)', len(data6))
|
||||||
|
print('rowcount', cursor.rowcount)
|
||||||
|
print('lastrowid', cursor.lastrowid)
|
||||||
|
print('lastrowid na mão', lastIdFromSelect)
|
||||||
|
|
||||||
|
cursor.scroll(0, 'absolute')
|
||||||
|
print('rownumber', cursor.rownumber)
|
||||||
|
|
||||||
print()
|
|
||||||
print('For 2: ')
|
|
||||||
# cursor.scroll(-1)
|
|
||||||
for row in cursor.fetchall_unbuffered():
|
|
||||||
print(row)
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user