def create_table_curso(self): try: conn = Connection('curso') query = ''' CREATE TABLE IF NOT EXISTS curso( id SERIAL PRIMARY KEY NOT NULL, curso VARCHAR(50) NOT NULL ); ''' conn.execute_query(query) conn.commit() except Exception as e: print(e)
def create_table_seccion(self): try: conn = Connection('seccion') query = ''' CREATE TABLE IF NOT EXISTS seccion( id SERIAL PRIMARY KEY NOT NULL, grado VARCHAR (50) NOT NULL, seccion VARCHAR (10) NOT NULL ); ''' conn.execute_query(query) conn.commit() except Exception as e: conn.rollback() print(e)
def create_table_prof(self): try: conn = Connection('Profesor') query = ''' CREATE TABLE IF NOT EXISTS profesor( id SERIAL PRIMARY KEY NOT NULL, nombre VARCHAR(50) NOT NULL, apellido VARCHAR(50) NOT NULL, DNI INTEGER NOT NULL, Correo VARCHAR (50) NOT NULL, Telefono INTEGER NOT NULL ); ''' conn.execute_query(query) conn.commit() except Exception as e: conn.rollback() print(e)
def create_table_nota(self): try: conn = Connection('nota') query = ''' CREATE TABLE IF NOT EXISTS nota( id SERIAL PRIMARY KEY NOT NULL, alumno_id integer NOT NULL, curso_id integer NOT NULL, Nota_1 real NOT NULL, Nota_2 real NOT NULL, Nota_3 real NOT NULL, Nota_4 real NOT NULL ); ''' conn.execute_query(query) conn.commit() except Exception as e: conn.rollback() print(e)
def create_table(self): try: conn = Connection('alumno') query = ''' CREATE TABLE IF NOT EXISTS public.alumno ( id integer NOT NULL, documento character varying(20) NOT NULL, nombre character varying(100) NOT NULL, fecha_de_nacimiento date NOT NULL, correo character varying(50) NOT NULL, estado boolean NOT NULL, genero character varying(1) NOT NULL, PRIMARY KEY (id) ); ''' conn.execute_query(query) conn.commit() except Exception as e: conn.rollback() print(e)
def create_table_alumno(self): try: conn = Connection('alumnos') query = ''' CREATE TABLE IF NOT EXISTS alumnos( id SERIAL PRIMARY KEY NOT NULL, Nombre VARCHAR (50) NOT NULL, Apellido VARCHAR (50) NOT NULL, Edad INTEGER NOT NULL, DNI INTEGER NOT NULL, grado VARCHAR (20), Seccion INTEGER ); ''' conn.execute_query(query) conn.commit() except Exception as e: conn.rollback() print(e)
def all_registro(self): try: conn = Connection('nota') query = ''' SELECT a."id",a."nombre" as "Nombre del alumno" , a."apellido" as "Apellido", a."edad" as "Edad", a."dni" as "DNI", s."grado" as "Grado", s."seccion" as "Seccion", c."curso" as "Curso", n."nota_1" as "Nota 1", n."nota_2" as "Nota 2", n."nota_3" as "Nota 3", n."nota_4" as "Nota 4" FROM "alumnos" a, "curso" c , "nota" n, "seccion" s WHERE a."id" = n."id" and c."id" = n."id" ''' cursor = conn.execute_query(query) nota = cursor.fetchall() for notas in nota: print('---------------------------') print(f'\nID: {notas[0]}') print(f'Nombres del alumno: {notas[1]} {notas[2]}') print(f'Edad: {notas[3]}') print(f'DNI: {notas[4]}') print(f'Grado: {notas[5]}') print(f'Seccion: {notas[6]}') print(f'Curso: {notas[7]}') print(f'Nota 1: {notas[8]}') print(f'Nota 2: {notas[9]}') print(f'Nota 3: {notas[10]}') print(f'Nota 4: {notas[11]}\n') print('----------------------------------') except Exception as e: print(e)