Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement