def insert_student():
    # Ask the user for the required details
    student_name = input('Enter new student name: ')
    student_age = int(input('Enter new student age: '))

    # Create a tuple with the values to insert
    new_student = (student_name, student_age)
    execute_sql(SQL_INSERT_STUDENT, new_student)
示例#2
0
def insert_text(fn, options, **kwargs):
    with io.open(fn, encoding='utf-8') as f:
        text = f.read()
    id_ = filename_to_id(fn)
    sql = '''
INSERT INTO documents (id, text)
VALUES (%s, %s)'''
    execute_sql(sql, (id_, text), **kwargs)
示例#3
0
def insert_subject():
    # Ask the user for the required details
    subject_name = input('Enter new subject name: ')
    subject_teacher = input(f'Enter teacher of {subject_name}: ')

    # Create a tuple with the values to insert
    new_subject = (subject_name, subject_teacher)
    execute_sql(SQL_INSERT_SUBJECT, new_subject)
def update_student():
  # Ask the user for the required details
  the_id = request_id('student')
  the_name = input('Enter new name: ')
  the_age = int(input('Enter new age: '))

  # Create a tuple with the values to insert
  updates = (the_name, the_age, the_id)
  execute_sql(SQL_UPDATE, updates)
def insert_studies():
    # Ask the user for the required details
    student_id = request_id('student')
    subject_id = request_id('subject')
    target_grade = input('Enter target grade: ')

    # Create a tuple with the values to insert
    new_study = (student_id, subject_id, target_grade)
    execute_sql(SQL_INSERT_STUDY, new_study)
示例#6
0
def delete_student():
  student_id = request_id('student')
  d = (student_id,)

  # Clean up 'studies' first
  execute_sql(SQL_DELETE_STUDIES, d)

  # Now we can safely delete the student
  execute_sql(SQL_DELETE_STUDENT, d)
示例#7
0
def delete_subject():
    subject_id = request_id('subject')
    d = (subject_id, )

    # Clean up 'studies' first
    execute_sql(SQL_DELETE_STUDIES, d)

    # Now we can safely delete the student
    execute_sql(SQL_DELETE_SUBJECT, d)
def update_subject():
    # Ask the user for the required details
    the_id = request_id('subject')
    the_name = input('Enter new name: ')
    the_teacher = input('Enter new teacher: ')

    # Create a tuple with the values to insert
    updates = (the_name, the_teacher, the_id)
    execute_sql(SQL_UPDATE, updates)
示例#9
0
try:
    sql_file = open(SQL_FILENAME, 'r')
    sql_lines = sql_file.readlines()

    sql_commands = []

    sql_command = []
    for sql_line in [s.strip() for s in sql_lines if len(s) > 0]:
        sql_command.append(sql_line)
        if (sql_line.endswith(SQL_COMMAND_TERMINATOR)):
            sql_commands.append(sql_command)
            sql_command = []

    for sql_command in sql_commands:
        single_line_command = " ".join(sql_command).strip()
        print(single_line_command)

        if (single_line_command.upper().startswith('SELECT')):
            data = select_data(single_line_command)
            for d in data:
                print(d)
        else:
            lastrowid = execute_sql(single_line_command)
            print(f"Amended Row with ID {lastrowid}")
except Exception as e:
    print(e)
finally:
    print('Removing Database')
    os.remove(DB_FILENAME)

print('Complete')