Skip to content

Commit

Permalink
#23: Adiciona contem e operações do banco
Browse files Browse the repository at this point in the history
  • Loading branch information
HeBatalha committed Nov 28, 2023
1 parent f27e97e commit 09203e4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
14 changes: 4 additions & 10 deletions game/Banco/Missao.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import psycopg2
from .Database import Database
from Database import Database

class Missao:
def __init__(self):
Expand Down Expand Up @@ -50,15 +50,9 @@ def consultarMissaoNome(self, nome:str):
cursor.execute(f"""SELECT * FROM Missao WHERE NOME = '{nome}';""")
conexao.commit()
resultado=cursor.fetchall()
print(resultado[0])
if resultado:
print(resultado[0])
except psycopg2.Error as e:
print("Erro ao consultar Missão", e)
finally:
cursor.close()

""" Data = Database()
m = Missao()
m.inserirMissao('Salvar pessoas', True, 'Salve pessoas', 100)
m.deletarMissao('Salvar pessoas')
m.consultarMissao()
m.consultarMissaoNome('Salvar pessoas') """
cursor.close()
58 changes: 58 additions & 0 deletions game/Banco/contem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import psycopg2
from Database import Database

class Contem:
def __init__(self):
self.db=Database()

def inserirContem(self, local:int, missao:str, status:bool):
try:
conexao=self.db.conexao
cursor=conexao.cursor()
cursor.execute(f"""INSERT INTO Contem VALUES({local}, '{missao}', {status});""")
conexao.commit()
return print("Contem Inserido")
except psycopg2.Error as e:
print("Erro ao inserir Contem", e)
finally:
cursor.close()

def consultarContem(self):
try:
conexao=self.db.conexao
cursor=conexao.cursor()
cursor.execute(f"""SELECT * FROM Contem;""")
conexao.commit()
resultado=cursor.fetchall()
for i in resultado:
print(i)
except psycopg2.Error as e:
print("Erro ao consultar Contem", e)
finally:
cursor.close()

def deletarContem(self, local:int, missao:str):
try:
conexao=self.db.conexao
cursor=conexao.cursor()
cursor.execute(f"""DELETE FROM Contem WHERE LOCAL = '{local}' AND MISSAO = '{missao}';""")
conexao.commit()
return print("Contem Deletada")
except psycopg2.Error as e:
print("Erro ao deletar Contem", e)
finally:
cursor.close()

def consultarContemEspecifico(self, local:int, missao:str):
try:
conexao=self.db.conexao
cursor=conexao.cursor()
cursor.execute(f"""SELECT * FROM Contem WHERE LOCAL = '{local}' AND MISSAO = '{missao}';""")
conexao.commit()
resultado=cursor.fetchall()
if resultado:
print(resultado[0])
except psycopg2.Error as e:
print("Erro ao consultar Contem", e)
finally:
cursor.close()

0 comments on commit 09203e4

Please sign in to comment.