SELECT do SQL com fetch no SQLite3 do Python
This commit is contained in:
@@ -51,7 +51,9 @@ cursor.executemany(sql, (
|
||||
{'nome': 'Joana', 'peso': 5},
|
||||
))
|
||||
connection.commit()
|
||||
print(sql)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(sql)
|
||||
|
||||
28
aula205/select.py
Normal file
28
aula205/select.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import sqlite3
|
||||
|
||||
from main import DB_FILE, TABLE_NAME
|
||||
|
||||
connection = sqlite3.connect(DB_FILE)
|
||||
cursor = connection.cursor()
|
||||
|
||||
cursor.execute(
|
||||
f'SELECT * FROM {TABLE_NAME}'
|
||||
)
|
||||
|
||||
for row in cursor.fetchall():
|
||||
_id, name, weight = row
|
||||
print(_id, name, weight)
|
||||
|
||||
|
||||
print()
|
||||
|
||||
cursor.execute(
|
||||
f'SELECT * FROM {TABLE_NAME} '
|
||||
'WHERE id = "3"'
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
_id, name, weight = row
|
||||
print(_id, name, weight)
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user