-
-
Save parzibyte/456e08c550f21f648b4182ac8321ce08 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
""" | |
Conexión a SQLServer con Python | |
Ejemplo de CRUD evitando inyecciones SQL | |
@author parzibyte | |
Más tutoriales en: | |
parzibyte.me/blog | |
""" | |
from bd import conexion | |
try: | |
with conexion.cursor() as cursor: | |
consulta = "SELECT id, titulo, anio FROM peliculas WHERE titulo like ?;" | |
# Para Avengers Endgame | |
busqueda = "endg" | |
cursor.execute(consulta, ("%" + busqueda + "%")) | |
# Con fetchall traemos todas las filas | |
peliculas = cursor.fetchall() | |
# Recorrer e imprimir | |
for pelicula in peliculas: | |
print(pelicula) | |
except Exception as e: | |
print("Ocurrió un error al consultar con where: ", e) | |
finally: | |
conexion.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment