Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Aline/atualizar_livro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sqlite3

conn = sqlite3.connect('livraria.db')
cursor = conn.cursor()

cursor.execute("UPDATE livros SET preco = ? WHERE id = ?", (99.9, 1))

conn.commit()
cursor.close()
conn.close()
5 changes: 5 additions & 0 deletions Aline/consultar_livros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import csv
with open('livros.csv', newline='', encoding='utf-8') as csvfile:
leitor = csv.reader(csvfile)
for linha in leitor:
print(linha)
18 changes: 18 additions & 0 deletions Aline/criar_banco.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sqlite3

conn = sqlite3.connect('livraria.db')
cursor = conn.cursor()

cursor.execute("""
CREATE TABLE IF NOT EXISTS livros(
id INTEGER PRIMARY KEY AUTOINCREMENT,
titulo TEXT NOT NULL,
autor TEXT NOT NULL,
ano INTEGER NOT NULL,
preco REAL NOT NULL
)
""")

conn.commit()
cursor.close()
conn.close()
6 changes: 6 additions & 0 deletions Aline/exportando_livros.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,titulo,autor,ano,preco
1,One Piece,Eiichiro Oda,1997,99.9
2,Naruto,Masashi Kishimoto,2002,29.9
4,Death Note,Tsugumi Ohba,2003,24.9
5,My Hero Academia,Kohei Horikoshi,2014,49.9
6,Demon Slayer: Kimetsu no Yaiba,Koyoharu Gotouge,2016,44.9
16 changes: 16 additions & 0 deletions Aline/exportar_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sqlite3
import csv

conn = sqlite3.connect('livraria.db')
cursor = conn.cursor()

cursor.execute("SELECT * FROM livros")
items = cursor.fetchall()

with open('exportando_livros.csv', 'w', newline='', encoding='utf-8') as csvfile:
escritor = csv.writer(csvfile)
escritor.writerow(['id', 'titulo', 'autor', 'ano', 'preco'])
escritor.writerows(items)

cursor.close()
conn.close()
29 changes: 29 additions & 0 deletions Aline/importar_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sqlite3
import csv

livros = [
[1, 'One Piece', 'Eiichiro Oda', 1997, 34.90],
[2, 'Naruto', 'Masashi Kishimoto', 2002, 29.90],
[3, 'Attack on Titan', 'Hajime Isayama', 2009, 39.90],
[4, 'Death Note', 'Tsugumi Ohba', 2003, 24.90],
[5, 'My Hero Academia', 'Kohei Horikoshi', 2014, 49.90],
[6, 'Demon Slayer: Kimetsu no Yaiba', 'Koyoharu Gotouge', 2016, 44.90]
]

with open('livros.csv', 'w', newline='', encoding='utf-8') as csvfile:
escritor = csv.writer(csvfile)
escritor.writerow(['id', 'titulo', 'autor', 'ano', 'preço'])
escritor.writerows(livros)


conn = sqlite3.connect('livraria.db')
cursor = conn.cursor()
with open('livros.csv', newline='', encoding='utf-8') as csvfile:
leitor = csv.reader(csvfile)
next(leitor)
for item in leitor:
cursor.execute("INSERT INTO livros (titulo, autor, ano, preco) VALUES (?, ?, ?, ?)", (item[1], item[2], item [3], item [4]))

conn.commit()
cursor.close()
conn.close()
Binary file added Aline/livraria.db
Binary file not shown.
7 changes: 7 additions & 0 deletions Aline/livros.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id,titulo,autor,ano,preço
1,One Piece,Eiichiro Oda,1997,34.9
2,Naruto,Masashi Kishimoto,2002,29.9
3,Attack on Titan,Hajime Isayama,2009,39.9
4,Death Note,Tsugumi Ohba,2003,24.9
5,My Hero Academia,Kohei Horikoshi,2014,49.9
6,Demon Slayer: Kimetsu no Yaiba,Koyoharu Gotouge,2016,44.9
10 changes: 10 additions & 0 deletions Aline/remover_livro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sqlite3

conn = sqlite3.connect('livraria.db')
cursor = conn.cursor()

cursor.execute("DELETE FROM livros WHERE id = ?", (3, ))

conn.commit()
cursor.close()
conn.close()
88 changes: 0 additions & 88 deletions exercicios/para-casa/README.md

This file was deleted.

Binary file added exercicios/para-sala/resolucoes/empresa.db
Binary file not shown.
Binary file added exercicios/para-sala/resolucoes/escola.db
Binary file not shown.
16 changes: 16 additions & 0 deletions exercicios/para-sala/resolucoes/ex1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sqlite3

conn = sqlite3.connect('escola.db')
cursor = conn.cursor()

cursor.execute("""
CREATE TABLE IF NOT EXISTS estudantes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nome TEXT NOT NULL,
idade INTEGER NOT NULL
)
""")

conn.commit()
cursor.close()
conn.close()
16 changes: 16 additions & 0 deletions exercicios/para-sala/resolucoes/ex10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import csv
import sqlite3

conn = sqlite3.connect('empresa.db')
cursor = conn.cursor()

cursor.execute("SELECT * FROM clientes")
dados = cursor.fetchall()

with open('exportados_clientes.csv', 'w', newline='', encoding='utf-8') as csvfile:
escritor = csv.writer(csvfile)
escritor.writerow(['id', 'nome', 'email'])
escritor.writerows(dados)

cursor.close()
conn.close()
16 changes: 16 additions & 0 deletions exercicios/para-sala/resolucoes/ex2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sqlite3

conn = sqlite3.connect('escola.db')
cursor = conn.cursor()

estudantes = [
('Alice', 21),
('Bob', 22),
('Charlie', 23)
]

cursor.executemany("INSERT INTO estudantes (nome, idade) VALUES (?, ?)", estudantes)

conn.commit()
cursor.close()
conn.close()
13 changes: 13 additions & 0 deletions exercicios/para-sala/resolucoes/ex3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sqlite3

conn = sqlite3.connect('escola.db')
cursor = conn.cursor()

cursor.execute("SELECT * FROM estudantes")
registros = cursor.fetchall()

for registro in registros:
print(registro)

cursor.close()
conn.close()
11 changes: 11 additions & 0 deletions exercicios/para-sala/resolucoes/ex4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sqlite3
conn = sqlite3.connect('escola.db')
cursor = conn.cursor()
estudantes = [
(27, 'Alice'),
(29, 'Bob'),
]
cursor.executemany("UPDATE estudantes SET idade = ? WHERE nome = ?", estudantes)
conn.commit()
cursor.close()
conn.close()
10 changes: 10 additions & 0 deletions exercicios/para-sala/resolucoes/ex5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sqlite3

conn = sqlite3.connect('escola.db')
cursor = conn.cursor()

cursor.execute("DELETE FROM estudantes WHERE id = ?", ('Charlie',))

conn.commit()
cursor.close()
conn.close()
13 changes: 13 additions & 0 deletions exercicios/para-sala/resolucoes/ex6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sqlite3

conn = sqlite3.connect('escola.db')
cursor = conn.cursor()

cursor.execute("SELECT * FROM estudantes WHERE idade > 21")
registros = cursor.fetchall()

for registro in registros:
print(registro)

cursor.close()
conn.close()
6 changes: 6 additions & 0 deletions exercicios/para-sala/resolucoes/ex7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import csv

with open('produtos.csv', newline='', encoding='utf-8') as csvfile:
leitor = csv.reader(csvfile)
for linha in leitor:
print(linha)
12 changes: 12 additions & 0 deletions exercicios/para-sala/resolucoes/ex8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import csv

funcionarios = [
[1, 'Ana', 'Financeiro'],
[2, 'Carlos', 'TI'],
[3, 'Beatriz', 'RH']
]

with open('funcionarios.csv', 'w', newline='', encoding='utf-8') as csvfile:
escritor = csv.writer(csvfile)
escritor.writerow(['id', 'nome', 'departamento'])
escritor.writerows(funcionarios)
23 changes: 23 additions & 0 deletions exercicios/para-sala/resolucoes/ex9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sqlite3
import csv

conn = sqlite3.connect('empresa.db')
cursor = conn.cursor()

cursor.execute("""
CREATE TABLE IF NOT EXISTS clientes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nome TEXT NOT NULL,
email TEXT NOT NULL
)
""")

with open('../clientes.csv', newline='', encoding='utf-8') as csvfile:
leitor = csv.reader(csvfile)
next(leitor) # Pular o cabeçalho
for linha in leitor:
cursor.execute("INSERT INTO clientes (nome, email) VALUES (?, ?)", (linha[1], linha[2]))

conn.commit()
cursor.close()
conn.close()
6 changes: 6 additions & 0 deletions exercicios/para-sala/resolucoes/exportados_clientes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,nome,email
1,João,joao@example.com
2,Maria,maria@example.com
3,Pedro,pedro@example.com
4,Luiza,luiza@example.com
5,Fernando,fernando@example.com
4 changes: 4 additions & 0 deletions exercicios/para-sala/resolucoes/funcionarios.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,nome,departamento
1,Ana,Financeiro
2,Carlos,TI
3,Beatriz,RH
Binary file added material/escola.db
Binary file not shown.