<commit_before># @Author: <NAME>
# @Date:   2016-11-04 19:35:56
# @Last Modified by:   <NAME>
# @Last Modified time: 2016-11-26 17:03:23

module Database

  class DBStudent < DBBasic

    # initialization
    # @param [String] db_path the file path to the database
    def initialize(db_path)
      open_database(db_path)
    end

    # method to insert a {Student} into the database
    # @param [Integer] id the id that was generated by the number generator
    #   for person entities
    # @param [String] name the name of the student
    # @param [Integer] mat_nr the matriculation number
    def insert_student(id, name, mat_nr)
      insert_person(id, name)
      stmt = @db.prepare("INSERT INTO Students(P_Id, Mat_Nr) VALUES (?, ?)")
      stmt.execute(id, mat_nr)
      nil
    end

    # method to query a student by id
    # @param [Integer] id the requested id
    # @return [Array] an array with the results
    def query_student_by_id(id)
      stmt = @db.prepare("SELECT p.Id, p.Name, s.Mat_Nr FROM " \
                            "Students s LEFT JOIN Persons p on p.id=s.p_id " \
                            "WHERE p.id = ?")
      stmt.execute(id)
    end

    # method to query a student by id
    # @param [String] name the requested name
    # @return [Array] an array with the results
    def query_student_by_name(name)
      stmt = @db.prepare("SELECT p.Id, p.Name, s.Mat_Nr FROM " \
                            "Students s LEFT JOIN Persons p on p.id=s.p_id " \
                            "WHERE p.name = ?")
      stmt.execute(name)
    end

    # method to query a student by matriculation number
    # @param [Integer] mat_nr the requested matriculation number
    # @return [Array] an array with the results
    def query_student_by_matnr(mat_nr)
      stmt = @db.prepare("SELECT p.Id, p.Name, s.Mat_Nr FROM " \
                            "Students s LEFT JOIN Persons p on p.id=s.p_id " \
                            "WHERE s.Mat_Nr = ?")
      stmt.execute(id)
    end

    private

    # overwritten method from the parent class to specify the creation of
    # additional required tables
    def generate_additional_tables
      @db.execute("CREATE TABLE IF NOT EXISTS
                      Students(Id INTEGER PRIMARY KEY,
                      P_Id INTEGER, Mat_Nr INTEGER,
                      FOREIGN KEY(P_Id) REFERENCES Persons(Id))")
    end

  end

end<commit_msg>adjusted queries and documentation in db_student<commit_after># @Author: <NAME>
# @Date:   2016-11-04 19:35:56
# @Last Modified by:   <NAME>
# @Last Modified time: 2016-11-28 19:30:17

module Database

  class DBStudent < DBBasic

    # initialization
    # @param [String] db_path the file path to the database
    def initialize(db_path)
      open_database(db_path)
    end

    # method to insert a {Person::Student} into the database
    # @param [Integer] id the id that was generated by the number generator
    #   for person entities
    # @param [String] name the name of the student
    # @param [Integer] mat_nr the matriculation number
    def insert_student(id, name, mat_nr)
      insert_person(id, name)
      stmt = @db.prepare("INSERT OR REPLACE INTO Students(P_Id, Mat_Nr)
                          VALUES (?, ?)")
      stmt.execute(id, mat_nr)
      nil
    end

    # method to query a {Person::Student} by id
    # @param [Integer] id the requested id
    # @return [Array] an array with the results
    def query_student_by_id(id)
      stmt = @db.prepare("SELECT p.Id, p.Name, s.Mat_Nr FROM
                          Students s LEFT JOIN Persons p on p.id=s.p_id
                          WHERE p.id = ?")
      stmt.execute(id)
    end

    # method to query a {Person::Student} by id
    # @param [String] name the requested name
    # @return [Array] an array with the results
    def query_student_by_name(name)
      stmt = @db.prepare("SELECT p.Id, p.Name, s.Mat_Nr FROM
                          Students s LEFT JOIN Persons p on p.id=s.p_id
                          WHERE p.name = ?")
      stmt.execute(name)
    end

    # method to query a {Person::Student} by matriculation number
    # @param [Integer] mat_nr the requested matriculation number
    # @return [Array] an array with the results
    def query_student_by_matnr(mat_nr)
      stmt = @db.prepare("SELECT p.Id, p.Name, s.Mat_Nr FROM
                          Students s LEFT JOIN Persons p on p.id=s.p_id
                          WHERE s.Mat_Nr = ?")
      stmt.execute(id)
    end

    private

    # overwritten method from the parent class to specify the creation of
    # additional required tables
    def generate_additional_tables
      @db.execute("CREATE TABLE IF NOT EXISTS
                   Students(Id INTEGER PRIMARY KEY,
                   P_Id INTEGER, Mat_Nr INTEGER,
                   FOREIGN KEY(P_Id) REFERENCES Persons(Id))")
    end

  end

end
{'fraction_non_alphanumeric': 0.08533333333333333, 'fraction_numerical': 0.011487179487179488, 'mean_word_length': 2.139729555698648, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '493607', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1461, 'n_words': 498}