def create_data_to_db(row_number): system('clear') print('\t INSERT DATA \t\n') try: conn = connector() db_cursor = conn.cursor() employee_name = str(input("Enter Employee Name : ")) employee_name_status = employee_name_validation(employee_name) if employee_name_status is not True: employee_age = int(input("Enter Employee Age : ")) employee_address = str(input("Enter Employee Address : ")) employee_salary = float(input("Enter Employee Salary : ")) employee_db_id = row_number + 1 db_cursor.execute(get_insert_data_statement(employee_db_id, employee_name, employee_age, employee_address, employee_salary)) conn.commit() print("OPERATION SUCCESSFULLY......") if employee_name_status is True: print('\n') print('\t EMPLOYEE IS AVAIBLE IN DATABASE \t') db_cursor.close() conn.close() except (Exception, psycopg2.DatabaseError) as error: print(error)
def select_from_db(): ''' ''' try: conn = connector() db_cursor = conn.cursor() db_cursor.execute(get_sql_statement('get_row_number')) print("The number of row = ", db_cursor.rowcount, "\n") row = db_cursor.fetchall() for data in enumerate(row, start=1): print(data[0], ".", data[1]) db_cursor.close() conn.close() except (Exception, psycopg2.DatabaseError) as error: print(error)
def select_id_by_name(employee_name): conn = connector() db_cursor = conn.cursor() sql_statement = get_sql_statement('get_id_from_name', None, None, employee_name) # print(sql_statement) db_cursor.execute(sql_statement) sql_query = db_cursor.fetchone() if sql_query is not None: return (str(sql_query[0])) else: return None db_cursor.close() conn.close()
def select_specific_by_data(choice): ''' ''' sql_connection = connector() employee_name = get_name() if employee_name is not None: db_cursor = sql_connection.cursor() db_cursor.execute(get_specific_select(choice, employee_name)) results = db_cursor.fetchone() print(results) print('Name \t= ', str(results[0]).capitalize()) string_result = '{choice} = ' + str(results[1]) string_results = string_result.format(choice=str(choice)) print(string_results) db_cursor.close() sql_connection.close()
def select_by_name(employee_name): try: conn = connector() db_cursor = conn.cursor() db_cursor.execute( get_sql_statement('get_data_by_name', employee_name=employee_name)) row_data = db_cursor.fetchone() print('Employee Name = ', str(row_data[0]).title()) print('Employee Address = ', str(row_data[1]).title()) print('Employee Age = ', row_data[2]) print('Employee Salary = ', row_data[3]) db_cursor.close() conn.close() return row_data except (Exception, psycopg2.DatabaseError) as error: print(error)
def employeeNameValidation(employee_name, select_specific=False): try: conn = connector() db_cursor = conn.cursor() sql_statement = get_sql_statement('get_one_employee_name', None, None, employee_name) db_cursor.execute(sql_statement) check_name = db_cursor.fetchone() if check_name is not None: print('Employee is in Database !!!\n') if select_specific is False: select_by_name(employee_name) return True print('Employee Name Is Not Avaible In Database !!!') return False db_cursor.close() conn.close() except (psycopg2.DatabaseError) as error: print(error)
def select_by_name(employee_name): conn = connector() db_cursor = conn.cursor() db_cursor.execute(get_sql_statement('get_data_by_name', None, None, employee_name)) row_data = db_cursor.fetchone() return row_data