Ejemplo n.º 1
0
    def display_table_detailed(self, conn):

        all_tables = display_tables(conn)
        for i in range(len(all_tables)):
            all_tables[i] = all_tables[i].upper()
            print(all_tables[i], end=" | ")
        chosen_table = input("What table to display: ")
        chosen_table = chosen_table.upper()

        if chosen_table in all_tables:
            all_columns = display_columns(conn, chosen_table)
            for i in range(len(all_columns)):
                all_columns[i] = all_columns[i].upper()
                print(all_columns[i], end=" | ")

            chosen_columns = input(
                "What columns to display(if u want more than one write next after comma): "
            )

            user_choice = input(
                "Do you want to add conditions to your query?(y/n)")
            where_condition = ""
            group_by = ""
            if user_choice == "y":
                where_condition = input("Insert condition(SQL format): ")
            if where_condition == "":
                where_condition = True
            user_choice = input(
                "Do you want to add grouping to your query?(y/n)")
            if user_choice == "y":
                while True:
                    condition_column = input(
                        "Choose column you want to group by: ")
                    if condition_column in all_columns:
                        group_by += condition_column
                    else:
                        break

                    continues_choice = input(
                        "Do you want to add another column for grouping?? (y/n)"
                    )
                    if continues_choice == "y":
                        group_by += ", "

                    else:
                        break
            if group_by == "":
                group_by = None

            #print(chosen_table)
            #print(chosen_columns)
            #print(where_condition)
            #print(group_by)
            result = display_sth(conn, chosen_table, chosen_columns,
                                 where_condition, group_by)

            self.display(result)

        else:
            print("Table does not exist")
Ejemplo n.º 2
0
    def insert_row(self, conn):
        all_tables = display_tables(conn)

        for i in range(len(all_tables)):
            all_tables[i] = all_tables[i].upper()
            print(all_tables[i], end=" | ")
        chosen_table = input(
            "\nIn which table you want to insert sth? Choose one: ")
        chosen_table = chosen_table.upper()

        if chosen_table in all_tables:
            all_columns = display_columns(conn, chosen_table)

            for i in range(len(all_columns)):
                all_columns[i] = all_columns[i].upper()
                print(all_columns[i], end=" | ")

            values = []
            print("\nInsert values to columns:")
            for i in range(len(all_columns)):
                value = input(f'{all_columns[i]}:')
                value = if_string_to_SQL(value)
                values.append(value)

            sql_values = ""
            for i in range(len(all_columns)):
                if i < (len(all_columns) - 1):
                    sql_values += values[i] + ", "
                else:
                    sql_values += values[i]

            insert_record(conn, chosen_table, sql_values)

        else:
            print("Table does not exist")
Ejemplo n.º 3
0
    def update_row(self, conn):
        all_tables = display_tables(conn)
        for i in range(len(all_tables)):
            all_tables[i] = all_tables[i].upper()
            print(all_tables[i], end=" | ")
        chosen_table = input("What table to display: ")
        chosen_table = chosen_table.upper()

        if chosen_table in all_tables:
            all_columns = display_columns(conn, chosen_table)
            for i in range(len(all_columns)):
                all_columns[i] = all_columns[i].upper()
                print(all_columns[i], end=" | ")
            chosen_column = input("Choose column you want to update: ").upper()
            if chosen_column in all_columns:
                value = input("Choose value you want to change to: ")
                value = if_string_to_SQL(value)

                where_condition = input("Insert condition(SQL format): ")
                if where_condition == "":
                    where_condition = True

                change = chosen_column + "=" + value

                update_sth(conn, chosen_table, change, where_condition)
            else:
                print("Column does not exist")
        else:
            print("Table does not exist")
Ejemplo n.º 4
0
    def delete_rows(self, conn):
        all_tables = display_tables(conn)

        for i in range(len(all_tables)):
            all_tables[i] = all_tables[i].upper()
            print(all_tables[i], end=" | ")

        chosen_table = input(
            "\nIn which table you want to delete a rows? Choose one: ")
        chosen_table = chosen_table.upper()

        if chosen_table in all_tables:
            where_condition = input("Insert where condition(SQL format):")

        delete_sth(conn, chosen_table, where_condition)
Ejemplo n.º 5
0
    def display_table_quick(self, conn):
        all_tables = display_tables(conn)
        for i in range(len(all_tables)):
            all_tables[i] = all_tables[i].upper()
            print(all_tables[i], end=" | ")
        chosen_table = input("What table to display: ")
        chosen_table = chosen_table.upper()

        if chosen_table in all_tables:
            all_columns = display_columns(conn, chosen_table)
            print()
            for i in range(len(all_columns)):
                all_columns[i] = all_columns[i].upper()
                print(all_columns[i], end=" | ")
            print()
            result = display_sth(conn, chosen_table)
            self.display(result)
        else:
            print("Table does not exist")
Ejemplo n.º 6
0
    def update_rows_detailed(self, conn):
        all_tables = display_tables(conn)
        for i in range(len(all_tables)):
            all_tables[i] = all_tables[i].upper()
            print(all_tables[i], end=" | ")
        chosen_table = input("What table to update: ")
        chosen_table = chosen_table.upper()

        if chosen_table in all_tables:
            all_columns = display_columns(conn, chosen_table)
            for i in range(len(all_columns)):
                all_columns[i] = all_columns[i].upper()
                print(all_columns[i], end=" | ")
            change = ""
            while True:
                chosen_column = input("Choose column you want to update: ")
                chosen_column = chosen_column.upper()

                if chosen_column in all_columns:
                    value = input("Choose value you want to change to: ")
                    value = if_string_to_SQL(value)

                    change += chosen_column + "=" + value
                    continue_choice = input(
                        "Do you want to add set another column? (y/n)")
                    if continue_choice == "y":
                        change += ", "
                    else:
                        break
                else:
                    print("Column does not exist")

            where_condition = input("Insert condition(SQL format): ")
            if where_condition == "":
                where_condition = True
            update_sth(conn, chosen_table, change, where_condition)
        else:
            print("Table does not exist")