-
-
Save parzibyte/1dd27e1fb1c94452015932b1ee67b89f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
try: | |
#Conectar a la base de datos | |
bd = sqlite3.connect("libros.db") | |
cursor = bd.cursor() | |
#Listar los libros | |
sentencia = "SELECT *,rowid FROM libros;" | |
cursor.execute(sentencia) | |
libros = cursor.fetchall() | |
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+{:-<10}+".format("", "", "", "", "")) | |
print("|{:^20}|{:^20}|{:^10}|{:^50}|{:^10}|".format("Autor", "Género", "Precio", "Título", "Rowid")) | |
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+{:-<10}+".format("", "", "", "", "")) | |
for autor, genero, precio, titulo, rowid in libros: | |
print("|{:^20}|{:^20}|{:^10}|{:^50}|{:^10}|".format(autor, genero, precio, titulo, rowid)) | |
print("+{:-<20}+{:-<20}+{:-<10}+{:-<50}+{:-<10}+".format("", "", "", "", "")) | |
#Pedir id del libro a editar | |
id_libro = input("\nEscribe el id del libro que quieres eliminar: ") | |
if not id_libro: | |
print("No escribiste nada") | |
exit() | |
#Sentencia para eliminar | |
sentencia = "DELETE FROM libros WHERE rowid = ?;" | |
#Eliminar el libro | |
cursor.execute(sentencia, [id_libro]) | |
bd.commit() | |
print("Eliminado con éxito") | |
except sqlite3.OperationalError as error: | |
print("Error al abrir:", error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment