Exemplo n.º 1
0
 def listar(self):
     try:
         con = ConDAO().connect()
         cur = con.cursor()
         cur.execute('select *from "Projeto" order by id')
         con.commit()
         lista = []
         for linha in cur.fetchall():
             proj = Projeto(linha[0])
             proj.id = linha[1]
             proj.dataPrevista = linha[2]
             lista.append(proj)
         con.close()
         return lista
     except ValueError as e:
         return "Erro, valor inválido: {} ".format(e)
     except SyntaxError as e:
         return "Erro de sintaxe: {}".format(e)
     except BaseException as e:
         return "Erro ao buscar: {} ".format(e)
Exemplo n.º 2
0
    def buscar(self, cod):
        try:

            con = ConDAO().connect()
            cur = con.cursor()
            cod = int(cod)
            cur.execute('select *from "Projeto" where id = (%s)', [cod])
            con.commit()
            linha = cur.fetchone()
            con.close()
            proj = Projeto(linha[0])
            proj.id = linha[1]
            proj.dataPrevista = linha[2]
            return proj

        except ValueError as e:
            return "Erro, valor inválido: {} ".format(e)
        except SyntaxError as e:
            return "Erro de sintaxe: {}".format(e)
        except BaseException as e:
            return "Erro ao buscar: {} ".format(e)