Esempio n. 1
0
 def salvar(a):
     con = Conectar.entrar()
     cur = con.cursor()
     cur.execute("""SELECT COUNT(*) FROM "Autor" WHERE cod=%s""", [a.cod])
     test = cur.fetchone()
     if (test[0] > 0):
         try:
             with con.cursor() as cur:
                 cur.execute(
                     """UPDATE "Autor" SET nome = %s , email = %s WHERE cod = %s""",
                     [a.nome, a.email, a.cod])
                 con.commit()
                 cur.close()
         except:
             print("Deu Ruim")
     elif (test[0] == 0):
         try:
             with con.cursor() as cur:
                 a.cod = cur.execute(
                     """INSERT INTO "Autor" (nome, email) VALUES (%s, %s) RETURNING cod""",
                     [a.nome, a.email])
                 con.commit()
                 cur.close()
                 con.close()
         except:
             print("Deu Ruim")
Esempio n. 2
0
 def buscar(cod):
     con = Conectar.entrar()
     try:
         with con.cursor() as cur:
             cur.execute("""SELECT * FROM "Autor" WHERE cod=%s""", [cod])
             r = cur.fetchone()
             a = Autor(r[1], r[2])
             a.cod = r[0]
             cur.close()
             return a
     except:
         print("Deu Ruim")
Esempio n. 3
0
 def buscar(cod):
     con = Conectar.entrar()
     try:
         with con.cursor() as cur:
             cur.execute("""SELECT * FROM "Trabalho" WHERE cod=%s""", [cod])
             r = cur.fetchone()
             t = Trabalho(r[1], r[2], r[3], r[4])
             t.cod = r[0]
             t.dataHoraAtualizacao = r[5]
             cur.close()
             return t
     except:
         print("Deu Ruim")
Esempio n. 4
0
 def deletar(cod):
     con = Conectar.entrar()
     cur = con.cursor()
     try:
         with con.cursor() as cur:
             cur.execute("""DELETE FROM "Trabalho" WHERE cod=%s""", [cod])
             cur.execute(
                 """DELETE FROM "TrabalhoAutor" WHERE "codTrabalho"=%s""",
                 [cod])
             con.commit()
             cur.close()
             con.close()
     except:
         print("Deu Ruim")
Esempio n. 5
0
 def salvar(t, codAutor):
     con = Conectar.entrar()
     cur = con.cursor()
     cur.execute("""SELECT COUNT(*) FROM "Trabalho" WHERE cod=%s""",
                 [t.cod])
     test = cur.fetchone()
     try:
         cur.execute("""SELECT COUNT(*) FROM "Autor" WHERE cod=%s""",
                     [codAutor])
         test1 = cur.fetchone()
         if (test1[0] == 0):
             raise NameError
     except:
         print("Autor Não existe")
     if (test[0] > 0):
         try:
             with con.cursor() as cur:
                 cur.execute(
                     """UPDATE "Trabalho" SET conteudo = %s , nota = %s, "dataEntrega" = %s, titulo = %s, "dataHoraAtualizacao" = %s WHERE cod = %s""",
                     [
                         t.conteudo, t.nota, t.dataEntrega, t.titulo,
                         t.dataHoraAtualizacao, t.cod
                     ])
                 cur.execute(
                     """UPDATE "TrabalhoAutor" SET "codAutor" = %s WHERE "codTrabalho" = %s""",
                     (codAutor, t.cod))
                 con.commit()
                 cur.close()
         except:
             print("Deu Ruim")
     elif (test[0] == 0):
         try:
             with con.cursor() as cur:
                 cur.execute(
                     """INSERT INTO "Trabalho" (conteudo, nota, "dataEntrega", titulo, "dataHoraAtualizacao") VALUES (%s, %s, %s, %s, %s) RETURNING cod""",
                     [
                         t.conteudo, t.nota, t.dataEntrega, t.titulo,
                         t.dataHoraAtualizacao
                     ])
                 con.commit()
                 t.cod = cur.fetchone()
                 cur.execute(
                     """INSERT INTO "TrabalhoAutor" ("codAutor", "codTrabalho") VALUES (%s, %s)""",
                     (codAutor, t.cod[0]))
                 con.commit()
                 cur.close()
                 con.close()
         except:
             print("Deu Ruim")
Esempio n. 6
0
 def listar():
     con = Conectar.entrar()
     try:
         with con.cursor() as cur:
             cur.execute('SELECT * FROM "Autor" ORDER BY cod')
             r = cur.fetchall()
             lista = []
             for i in range(0, len(r)):
                 a = Autor(r[i][1], r[i][2])
                 a.cod = r[i][0]
                 lista.append(a)
             cur.close()
             return lista
     except:
         print("Deu Ruim")
Esempio n. 7
0
 def listar():
     con = Conectar.entrar()
     try:
         with con.cursor() as cur:
             cur.execute('SELECT * FROM "Trabalho" ORDER BY cod')
             r = cur.fetchall()
             lista = []
             for i in range(0, len(r)):
                 t = Trabalho(r[i][1], r[i][2], r[i][3], r[i][4])
                 t.cod = r[i][0]
                 t.dataHoraAtualizacao = r[i][5]
                 lista.append(t)
             cur.close()
             return lista
     except:
         print("Deu Ruim")
Esempio n. 8
0
 def deletar(cod):
     con = Conectar.entrar()
     try:
         with con.cursor() as cur:
             cur.execute("""DELETE FROM "Autor" WHERE cod=%s""", [cod])
             con.commit()
             cur.execute(
                 """SELECT COUNT(*) FROM "TrabalhoAutor" WHERE cod=%s""",
                 [cod])
             test = cur.fetchone()
             if (test[0] > 0):
                 try:
                     with con.cursor() as cur:
                         cur.execute(
                             """UPDATE "TrabalhoAutor" SET codAutor='' WHERE codAutor=%s""",
                             [cod])
                         con.commit()
                 except:
                     print("Deu Ruim")
             cur.close()
             con.close()
     except:
         print("Deu Ruim")