Skip to content

Instantly share code, notes, and snippets.

@alexaleluia12
Created November 11, 2023 14:06
Show Gist options
  • Save alexaleluia12/450cb70a2ee5104991d35dcf9598e186 to your computer and use it in GitHub Desktop.
Save alexaleluia12/450cb70a2ee5104991d35dcf9598e186 to your computer and use it in GitHub Desktop.
exemplo sqlite com with em python, fecha recursos de forma automática
from contextlib import closing
import sqlite3
# db from - https://github.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/blob/main/app/src/main/assets/database/bus_schedule.db
# source - https://www.digitalocean.com/community/tutorials/how-to-use-the-sqlite3-module-in-python-3
with closing(sqlite3.connect("bus_schedule.db")) as connection:
with closing(connection.cursor()) as cursor:
rows = cursor.execute("SELECT * FROM Schedule").fetchall()
print(rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment