Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 31, 2018 02:19
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 Fhernd/b9bf8df10f45b3713273a5f082889eca to your computer and use it in GitHub Desktop.
Save Fhernd/b9bf8df10f45b3713273a5f082889eca to your computer and use it in GitHub Desktop.
Operaciones sobre bases de datos usando Python y SQLite3. OrtizOL.
import sqlite3
lenguajes = [
('Python', 3.7),
('Java', 11),
('C#', 7),
('PHP', 7.0)
]
bd = sqlite3.connect('lenguajes.db')
# Creación de la tabla Lenguajes:
cursor = bd.cursor()
cursor.execute('CREATE TABLE Lenguajes(nombre TEXT, version REAL)')
bd.commit()
# Inserción de datos:
cursor.executemany('INSERT INTO Lenguajes VALUES (?, ?)', lenguajes)
bd.commit()
# Lectura de datos:
for fila in bd.execute('SELECT * FROM Lenguajes'):
print(fila)
# Recuperación de valores a partir de una consulta:
print()
version = 5
for fila in bd.execute('SELECT * FROM Lenguajes WHERE version <= ?', (version, )):
print(fila)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment