コード例 #1
0
def no_index_eq(db):
    with open(db, "rb") as fd:
        # read db root
        page_size, usable_size, free_list_page, num_free_list_page = util.read_db_header(
            fd)
        fd.seek(100)
        _, cell_pointer, _ = util.read_page_header(fd)
        # read sqlite_master
        # assume sqlite_master does not util.overflow
        util.master_move_fd_to_record(fd, cell_pointer[0])
        # 21 is size of 'TableEmployeeEmployee' NOTE: hardcode for now
        fd.seek(21, 1)
        table_root_page = util.read_to_int(fd, 1)
        global header_page_read
        header_page_read += 1

        # equality search
        print('Equality employee id 181162')
        employee = search_table_child(fd, page_size, table_root_page,
                                      usable_size, 'EMP_ID', 181162)
        if employee:
            print('Name: {} {} {}'.format(employee['First_Name'],
                                          employee['Middle_Name'],
                                          employee['Last_Name']))
        else:
            print('employee id 181162 not exist')
コード例 #2
0
def no_index_range(db):
    with open(db, "rb") as fd:
        # read db root
        page_size, usable_size, free_list_page, num_free_list_page = util.read_db_header(
            fd)
        fd.seek(100)
        _, cell_pointer, _ = util.read_page_header(fd)
        # read sqlite_master
        # assume sqlite_master does not util.overflow
        util.master_move_fd_to_record(fd, cell_pointer[0])
        # 21 is size of 'TableEmployeeEmployee' NOTE: hardcode for now
        fd.seek(21, 1)
        table_root_page = util.read_to_int(fd, 1)
        global header_page_read
        header_page_read += 1

        # range search
        print('Range seach eid between 171800 and 171899')
        for i in range(100):
            eid = 171800 + i
            employee = search_table_child(fd, page_size, table_root_page,
                                          usable_size, 'EMP_ID', eid)
            if employee:
                print('EMP_ID: {}, Name: {} {} {}'.format(employee['EMP_ID'], \
                 employee['First_Name'], employee['Middle_Name'], employee['Last_Name']))
            else:
                print('employee id {} not exist'.format(eid))
コード例 #3
0
def no_index_scan(db):
    with open(db, "rb") as fd:
        # read db root
        page_size, usable_size, free_list_page, num_free_list_page = util.read_db_header(
            fd)
        fd.seek(100)
        _, cell_pointer, _ = util.read_page_header(fd)
        # read sqlite_master
        # assume sqlite_master does not util.overflow
        util.master_move_fd_to_record(fd, cell_pointer[0])
        # 21 is size of 'TableEmployeeEmployee' NOTE: hardcode for now
        fd.seek(21, 1)
        table_root_page = util.read_to_int(fd, 1)
        global header_page_read
        header_page_read += 1

        # scan
        print('Scan Last name Rowe')
        employee = search_table_child(fd, page_size, table_root_page,
                                      usable_size, 'Last_Name', 'Rowe')
        if employee:
            print('EMP_ID: {}, Name: {} {} {}'.format(employee['EMP_ID'], \
             employee['First_Name'], employee['Middle_Name'], employee['Last_Name']))
        else:
            print('No one has last name Rowe')
コード例 #4
0
def with_index_with_rowid_range(db):
    with open(db, "rb") as fd:
        # read db root
        page_size, usable_size, free_list_page, num_free_list_page = util.read_db_header(
            fd)
        fd.seek(100)
        _, cell_pointer, _ = util.read_page_header(fd)
        # read sqlite_master
        # assume sqlite_master does not util.overflow
        util.master_move_fd_to_record(fd, cell_pointer[0])
        # 21 is size of 'TableEmployeeEmployee' NOTE: hardcode for now
        fd.seek(21, 1)
        table_root_page = util.read_to_int(fd, 1)
        util.master_move_fd_to_record(fd, cell_pointer[1])
        # 40 is size of 'indexsqlite_autoindex_Employee_1Employee' NOTE: hardcode for now
        fd.seek(40, 1)
        index_root_page = util.read_to_int(fd, 1)
        global header_page_read
        header_page_read += 1

        # range search
        print('Range seach eid between 171800 and 171899')
        row_ids = search_range_index(fd, page_size, index_root_page, 171800,
                                     171899)
        for row_id in row_ids:
            employee = search_equality_index(fd, page_size, table_root_page,
                                             row_id)
            print('EMP_ID: {}, Name: {} {} {}'.format(employee['EMP_ID'], \
             employee['First_Name'], employee['Middle_Name'], employee['Last_Name']))