Skip to content

Instantly share code, notes, and snippets.

@ceelsoin
Created May 24, 2020 18:27
Show Gist options
  • Save ceelsoin/7e9c0906da5be95e7035aa0471356e94 to your computer and use it in GitHub Desktop.
Save ceelsoin/7e9c0906da5be95e7035aa0471356e94 to your computer and use it in GitHub Desktop.
Mentoria hackingrio
import sqlite3
conn = sqlite3.connect('estudantes.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS students(
UserID VARCHAR(20) NOT NULL,
username VARCHAR(60) NOT NULL,
firstname VARCHAR(60) NOT NULL,
email VARCHAR(60) NOT NULL,
password VARCHAR(80) NOT NULL);
''')
#gravando no bd
conn.commit()
#solicitando dados
p_1 = input('UserID: ')
p_2 = input('username: ')
p_3 = input('firstname: ')
p_4 = input('email: ')
p_5 = input('password: ')
#inserindo informações
cursor.execute('''
INSERT INTO students(UserID, username, firstname, password, email)
VALUES(?,?,?,?, ?)
''', (p_1, p_2, p_3, p_4, p_5))
print('Dados inseridos com sucesso!!!')
#gravando no bd
conn.commit()
#verificando inversão
#lendo os dados
cursor.execute("""
SELECT*FROM students;
""")
print('lendo dados inseridos')
for linha in cursor.fetchall():
print(linha)
cursor.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment