From 09203e4d0bd203a3547c61a6bae31d37c7c90635 Mon Sep 17 00:00:00 2001 From: HeBatalha Date: Tue, 28 Nov 2023 19:07:53 -0300 Subject: [PATCH] =?UTF-8?q?#23:=20Adiciona=20contem=20e=20opera=C3=A7?= =?UTF-8?q?=C3=B5es=20do=20banco?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/Banco/Missao.py | 14 +++-------- game/Banco/contem.py | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 game/Banco/contem.py diff --git a/game/Banco/Missao.py b/game/Banco/Missao.py index 322ee52..0a002d7 100644 --- a/game/Banco/Missao.py +++ b/game/Banco/Missao.py @@ -1,5 +1,5 @@ import psycopg2 -from .Database import Database +from Database import Database class Missao: def __init__(self): @@ -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') """ \ No newline at end of file + cursor.close() \ No newline at end of file diff --git a/game/Banco/contem.py b/game/Banco/contem.py new file mode 100644 index 0000000..aa32ffe --- /dev/null +++ b/game/Banco/contem.py @@ -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() \ No newline at end of file