Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 14, 2019 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/2d6c309825c129d63c7e62eb7fe13f24 to your computer and use it in GitHub Desktop.
Save parzibyte/2d6c309825c129d63c7e62eb7fe13f24 to your computer and use it in GitHub Desktop.
"""
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 = "UPDATE peliculas SET titulo = ? WHERE id = ?;"
nuevo_titulo = "Ready Player One: comienza el juego"
id_editar = 2
cursor.execute(consulta, (nuevo_titulo, id_editar))
# No olvidemos hacer commit cuando hacemos un cambio a la BD
conexion.commit()
except Exception as e:
print("Ocurrió un error al editar: ", e)
finally:
conexion.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment