Created
July 31, 2018 02:19
-
-
Save Fhernd/b9bf8df10f45b3713273a5f082889eca to your computer and use it in GitHub Desktop.
Operaciones sobre bases de datos usando Python y SQLite3. OrtizOL.
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 | |
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