Ejemplo n.º 1
0
def main_update_from_db(choice, id_name):
    print('\n')
    if choice is '1':
        sql_query = get_sql_statement('name', id_name)
    elif choice is '2':
        sql_query = get_sql_statement('age', id_name)
    elif choice is '3':
        sql_query = get_sql_statement('address', id_name)
    elif choice is '4':
        sql_query = get_sql_statement('salary', id_name)
    else:
        print("you entered wrong choice boss :v...")

    if choice in ('1', '2', '3', '4'):
        try:
            conn = connect()
            db_cursor = conn.cursor()
            db_cursor.execute(sql_query)

            conn.commit()
            db_cursor.close()
        except (Exception, psycopg2.Error) as error:
            print("OPERATION FAILED ..........")
            print(error)
        except (Exception, psycopg2.DatabaseError) as error:
            print("OPERATION FAILED ..........")
            print(error)
        except (Exception, psycopg2.DataError) as error:
            print("OPERATION FAILED ..........")
            print(error)
    else:
        print('\nPlease Enter Valid Choice(1/2/3/4) !!!!')
Ejemplo n.º 2
0
def get_total_row_number():
    """
    "
    "   Get sum of row number in table
    "   return integer()
    "
    """
    connector = conn()
    db_cursor = connector.cursor()
    db_cursor.execute(get_sql_statement('get_row_number'))
    return int(db_cursor.rowcount)
Ejemplo n.º 3
0
def get_min_salary():
    system('clear')
    print('\t GET MIN SALARY \t\n')
    connector = conn()
    db_cursor = connector.cursor()

    db_cursor.execute(get_sql_statement('min'))

    min_salary_data = db_cursor.fetchall()
    print('\nName   : ', min_salary_data[0][0])
    print('Salary : ', min_salary_data[0][1])
    db_cursor.close()
    connector.close()
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
    def run_sort_data(self):
        if self.sort_method in ('asc', 'desc'):

            db_connector = self.open_db()
            db_cursor = db_connector.cursor()

            sort_choice = 'get_sort_' + self.sort_choice

            db_cursor.execute(
                get_sql_statement(sort_choice, None, self.sort_method))
            row_data = db_cursor.fetchall()
            if self.sort_choice == 'salary':
                self.print_data(row_data, showSalaryData=True)
            else:
                self.print_data(row_data)

            self.close_to_db(db_connector, db_cursor)
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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