Esempio n. 1
0
/**
 * @author Luka Rajcevic
 * @brief Function for inserting test data into the table (needed for python testing)
 * @param tbl_name - name of the table for which the header will be created
 * @param attr_name - array of attribute names
 * @param attr_value - values of attributes to be inserted
 * @param _num - number of attributes
 * @param _type - array of attribute types (eg. TYPE_INT, TYPE_VARCHAR, etc.)
 * @return EXIT_SUCCESS if ok, EXIT_ERROR otherwise
 */
int insert_data_test(char* tbl_name, char** attr_name, char** attr_value, int _num, int* _type){

    int i, ret;
    AK_PRO;
    struct list_node *row_root = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root);

    Ak_DeleteAll_L3(&row_root);
    for (i = 0; i < _num; i++){
        if (_type[i] == TYPE_VARCHAR)
            Ak_Insert_New_Element(_type[i], attr_value[i], tbl_name, attr_name[i], row_root);
        if (_type[i] == TYPE_INT){
            int val = atoi(attr_value[i]);
            Ak_Insert_New_Element(_type[i], &val, tbl_name, attr_name[i], row_root); 
        }
        if (_type[i] == TYPE_FLOAT){
            float val = atof(attr_value[i]);
            Ak_Insert_New_Element(_type[i], &val , tbl_name, attr_name[i], row_root);  
        }
    }
    ret = Ak_insert_row(row_root);
    AK_EPI;
    return ret;
}
Esempio n. 2
0
/**
  * @author Miroslav Policki
  * @brief Function for testing file search
  * @return No return value
  */
void Ak_filesearch_test() {
    int i;
    double f;
    AK_mem_block *mem_block, tmp;
    AK_header hBroj_int[4], *hTmp;
    struct list_node *row_root;
    AK_PRO;
    // create table and fill it for testing purposes
    hTmp = (AK_header *) AK_create_header("Number int", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    hBroj_int[0] = *hTmp;
    hTmp = (AK_header *) AK_create_header("Number float", TYPE_FLOAT, FREE_INT, FREE_CHAR, FREE_CHAR);
    hBroj_int[1] = *hTmp;
    hTmp = (AK_header *) AK_create_header("Varchar column", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    hBroj_int[2] = *hTmp;
    memset(&hBroj_int[3], 0, sizeof (AK_header));

    if (EXIT_ERROR == AK_initialize_new_segment("filesearch test table", SEGMENT_TYPE_TABLE, hBroj_int)) {
        printf("filesearch_test: ERROR. Unable to create \"filesearch test table \"\n");
        AK_EPI;
        exit(EXIT_ERROR);
    }

    row_root = AK_malloc(sizeof (struct list_node));
    if (row_root == NULL) {
        printf("filesearch_test: ERROR. Cannot allocate row_root.\n");
        AK_EPI;
        exit(EXIT_ERROR);
    }

    for (i = -10, f = -i; i < 10; i++, f = -i) {
        Ak_Init_L3(&row_root);
        Ak_Insert_New_Element(TYPE_INT, &i, "filesearch test table", "Number int", row_root);
        Ak_Insert_New_Element(TYPE_FLOAT, &f, "filesearch test table", "Number float", row_root);
        Ak_Insert_New_Element(TYPE_VARCHAR, "test text", "filesearch test table", "Varchar column", row_root);
        Ak_insert_row(row_root);
        Ak_DeleteAll_L3(&row_root);
    }

    AK_free(row_root);

    // filesearch usage example starts here
    {
        char *szTmp;
        search_params sp[3];
        search_result sr;
        int iLower, iUpper;
        double dTmp;

        sp[0].szAttribute = "Varchar column";
        sp[0].iSearchType = SEARCH_ALL;

        sp[1].szAttribute = "Number int";
        sp[1].iSearchType = SEARCH_RANGE;
        iLower = -5;
        iUpper = 5;
        sp[1].pData_lower = &iLower;
        sp[1].pData_upper = &iUpper;

        sp[2].szAttribute = "Number float";
        sp[2].iSearchType = SEARCH_PARTICULAR;
        dTmp = 2;
        sp[2].pData_lower = &dTmp;

        Ak_dbg_messg(LOW, FILE_MAN, "Calling AK_search_unsorted");
        sr = AK_search_unsorted("filesearch test table", sp, 3);

        for (i = 0; i < sr.iNum_tuple_addresses; i++) {
            //mem_block = AK_get_block (sr.aiBlocks[i]); // caching should be used when available
            mem_block = &tmp;
            mem_block->block = (AK_block *) AK_read_block(sr.aiBlocks[i]);

            printf("Found:%d\n", *((int *) (mem_block->block->data + mem_block->block->tuple_dict[sr.aiTuple_addresses[i] + 0].address)));
            printf("Found:%f\n", *((double *) (mem_block->block->data + mem_block->block->tuple_dict[sr.aiTuple_addresses[i] + 1].address)));

            szTmp = AK_malloc(mem_block->block->tuple_dict[sr.aiTuple_addresses[i] + 2].size + 1);
            memcpy(szTmp, mem_block->block->data + mem_block->block->tuple_dict[sr.aiTuple_addresses[i] + 2].address, mem_block->block->tuple_dict[sr.aiTuple_addresses[i] + 2].size);
            szTmp[mem_block->block->tuple_dict[sr.aiTuple_addresses[i] + 2].size] = '\0';
            printf("Found:%s\n", szTmp);
            AK_free(szTmp);
        }

        AK_deallocate_search_result(sr);
    }
    AK_EPI;
}
Esempio n. 3
0
/**
 * @author Unknown, updated by Tomislav Ilisevic
 * @brief  Function for testing commands
 *
 */
void AK_test_command(){
    AK_PRO;
    printf("***Test Command***\n");
    int brojkomandi = 4;
    command *komande = AK_malloc(sizeof(command)*(brojkomandi+1));


	// Test za komandu INSERT

    struct list_node *row_root = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root);
    
    char *tblName = "student";
   
    int mbr, year;
    float weight;
    mbr = 35917;
    year = 2012;
    weight = 82.00;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Mario", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Kolmacic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);

    komande[0].id_command = INSERT;
    komande[0].tblName = "student";
    komande[0].parameters = row_root;


	// Test za komandu UPDATE

    mbr = 35900;
    
    row_root = (struct list_node *) AK_malloc(sizeof (struct list_node ));
    Ak_Init_L3(&row_root);
    Ak_DeleteAll_L3(&row_root);

    Ak_Insert_New_Element_For_Update(TYPE_INT, &mbr, tblName, "mbr", row_root, 1);
    Ak_Insert_New_Element_For_Update(TYPE_VARCHAR, "FOI", tblName, "firstname", row_root, 0);

    komande[1].id_command = UPDATE;
    komande[1].tblName = "student";
    komande[1].parameters = row_root;


	// Test za komandu DELETE

    int id_prof;
    id_prof = 35893;
    
    row_root = (struct list_node *) AK_malloc(sizeof (struct list_node ));
    Ak_Init_L3(&row_root);
    Ak_DeleteAll_L3(&row_root);

    Ak_Insert_New_Element_For_Update(TYPE_INT, &id_prof, tblName, "id_prof", row_root, 1);
    Ak_Insert_New_Element_For_Update(TYPE_VARCHAR, "FOI", tblName, "firstname", row_root, 0);

    komande[2].id_command = DELETE;
    komande[2].tblName = "professor";
    komande[2].parameters = row_root;


	// Test za komandu SELECT

	row_root = (struct list_node *) AK_malloc(sizeof (struct list_node ));
	Ak_Init_L3(&row_root);
	Ak_DeleteAll_L3(&row_root);

//	printf("\nQUERY: SELECT * FROM student WHERE firstname = 'Robert';\n\n");

	Ak_InsertAtEnd_L3(TYPE_ATTRIBS, "firstname", sizeof ("firstname"), row_root);
	Ak_InsertAtEnd_L3(TYPE_VARCHAR, "Robert", sizeof ("Robert"), row_root);
	Ak_InsertAtEnd_L3(TYPE_OPERATOR, "=", sizeof ("="), row_root);

	komande[3].id_command = SELECT;
	komande[3].tblName = "student";
	komande[3].parameters = row_root;


	// Izvrsi komande
	AK_command(komande, brojkomandi);
	Ak_DeleteAll_L3(&row_root);

	AK_EPI;
}
Esempio n. 4
0
TestResult AK_test_Transaction() {
    AK_PRO;
    printf("***Test Transaction***\n");
    pthread_mutex_lock(&endTransationTestLockMutex);
    pthread_mutex_lock(&newTransactionLockMutex);
    AK_init_observable_transaction();

    // NOTE: This is the way on which we can broadcast notice to all observers
    // observable_transaction->observable->AK_notify_observers(observable_transaction->observable);
    
    memset(LockTable, 0, NUMBER_OF_KEYS * sizeof (struct transaction_list_head));

    /**************** INSERT AND UPDATE COMMAND TEST ******************/
    char *tblName = "student";
    struct list_node *row_root_insert = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root_insert);
    Ak_DeleteAll_L3(&row_root_insert);
    int mbr, year;
    float weight;
    mbr = 38262;
    year = 2012;
    weight = 82.00;
    Ak_DeleteAll_L3(&row_root_insert);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root_insert);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivan", tblName, "firstname", row_root_insert);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Pusic", tblName, "lastname", row_root_insert);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root_insert);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root_insert);

    struct list_node *row_root_update = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root_update);
    Ak_DeleteAll_L3(&row_root_update);
    Ak_Update_Existing_Element(TYPE_INT, &mbr, tblName, "mbr", row_root_update);
    Ak_Insert_New_Element(TYPE_VARCHAR, "pppppppppp", tblName, "lastname", row_root_update);

    command* commands_ins_up = AK_malloc(sizeof (command) * 2);
    commands_ins_up[0].tblName = "student";
    commands_ins_up[0].id_command = INSERT;
    commands_ins_up[0].parameters = row_root_insert;

    commands_ins_up[1].tblName = "student";
    commands_ins_up[1].id_command = UPDATE;
    commands_ins_up[1].parameters = row_root_update;

    int id_prof;
    id_prof = 35893;
    struct list_node *row_root_p_update = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root_p_update);
    Ak_DeleteAll_L3(&row_root_p_update);
    
    Ak_Update_Existing_Element(TYPE_INT, &id_prof, "professor", "id_prof", row_root_p_update);
    Ak_Insert_New_Element(TYPE_VARCHAR, "FOI", "professor", "firstname", row_root_p_update);


    /**************** DELETE COMMAND TEST ******************/
    command* commands_delete = AK_malloc(sizeof (command) * 1);
    commands_delete[0].tblName = "professor";
    commands_delete[0].id_command = DELETE;
    commands_delete[0].parameters = row_root_p_update;


    struct list_node *expr = (struct list_node *) AK_malloc(sizeof (struct list_node));
	Ak_Init_L3(&expr);
	int num = 2010;

	Ak_InsertAtEnd_L3(TYPE_ATTRIBS, "year", sizeof ("year"), expr);
	Ak_InsertAtEnd_L3(TYPE_INT, (char*)&num, sizeof (int), expr);
	Ak_InsertAtEnd_L3(TYPE_OPERATOR, "<", sizeof ("<"), expr);
	Ak_InsertAtEnd_L3(TYPE_ATTRIBS, "firstname", sizeof ("firstname"), expr);
	Ak_InsertAtEnd_L3(TYPE_VARCHAR, "Robert", sizeof ("Robert"), expr);
	Ak_InsertAtEnd_L3(TYPE_OPERATOR, "=", sizeof ("="), expr);
	Ak_InsertAtEnd_L3(TYPE_OPERATOR, "OR", sizeof ("OR"), expr);
    
    /**************** SELECT COMMAND TEST ******************/
    command* commands_select = AK_malloc(sizeof(command) * 1);
    commands_select[0].tblName = "student";
    commands_select[0].id_command = SELECT;
    commands_select[0].parameters = expr;

    /**************** EXECUTE TRANSACTIONS ******************/
    AK_transaction_manager(commands_ins_up, 2);
    AK_transaction_manager(commands_ins_up, 2);
    AK_transaction_manager(commands_delete, 1);
    AK_transaction_manager(commands_select, 1);
 
    pthread_mutex_lock(&endTransationTestLockMutex);

    AK_free(expr);
    AK_free(commands_delete);
    AK_free(commands_select);
    AK_free(commands_ins_up);
    AK_free(row_root_insert);
    AK_free(row_root_update);
    AK_free(row_root_p_update);
    AK_free(observable_transaction);

    pthread_mutex_unlock(&endTransationTestLockMutex);
    
    printf("***End test Transaction***\n");
    AK_EPI;

    return TEST_result(0,0);
}
Esempio n. 5
0
/**
 * @author Dino Laktašić
 * @brief  Function that produces a difference of the two tables. Table addresses are get through names of tables.
 *         Specially start addresses are taken from them. They are used to allocate blocks for them. It is checked whether
           the tables have same table schemas. If not, it returns EXIT_ERROR. New segment for result of difference operation is
           initialized. Function compares every block in extent of the first table with every block in extent of second table. If there 
	   is a difference between their rows, they are put in dstTable.
 * @param srcTable1 name of the first table
 * @param srcTable2 name of the second table
 * @param dstTable name of the new table
 * @return if success returns EXIT_SUCCESS, else returns EXIT_ERROR
 */
int AK_difference(char *srcTable1, char *srcTable2, char *dstTable) {
    AK_PRO;
    table_addresses *src_addr1 = (table_addresses*) AK_get_table_addresses(srcTable1);
    table_addresses *src_addr2 = (table_addresses*) AK_get_table_addresses(srcTable2);

    int startAddress1 = src_addr1->address_from[0];
    int startAddress2 = src_addr2->address_from[0];
	
    if ((startAddress1 != 0) && (startAddress2 != 0)) {
        register int i, j, k, l, m, n, o;
        i = j = k = l = 0;

        AK_mem_block *tbl1_temp_block = (AK_mem_block *) AK_get_block(startAddress1);
        AK_mem_block *tbl2_temp_block = (AK_mem_block *) AK_get_block(startAddress2);
		
		int num_att = AK_check_tables_scheme(tbl1_temp_block, tbl2_temp_block, "Difference");
		 
		if (num_att == EXIT_ERROR) {
			AK_EPI;
			return EXIT_ERROR;
		}

		int address, type, size;
		int different, num_rows, temp_int,summ;
		different = num_rows = temp_int = summ = 0;
		
		float temp_float = 0;
		
        char data1[MAX_VARCHAR_LENGTH];
	char data2[MAX_VARCHAR_LENGTH];
		
	//initialize new segment
        AK_header *header = (AK_header *) AK_malloc(num_att * sizeof (AK_header));
        memcpy(header, tbl1_temp_block->block->header, num_att * sizeof (AK_header));
        AK_initialize_new_segment(dstTable, SEGMENT_TYPE_TABLE, header);
        AK_free(header);

	struct list_node * row_root = (struct list_node *) AK_malloc(sizeof(struct list_node));
	
	for (i = 0; src_addr1->address_from[i] != 0; i++) {
            startAddress1 = src_addr1->address_from[i];

                //BLOCK: for each block in table1 extent
                for (j = startAddress1; j < src_addr1->address_to[i]; j++) {
                    tbl1_temp_block = (AK_mem_block *) AK_get_block(j); //read block from first table

                    //if there is data in the block
                    if (tbl1_temp_block->block->AK_free_space != 0) {
						
			//TABLE2: for each extent in table2
                        for (k = 0; k < (src_addr2->address_from[k] != 0); k++) {
                            startAddress2 = src_addr2->address_from[k];

                            if (startAddress2 != 0) {

                                //BLOCK: for each block in table2 extent
                                for (l = startAddress2; l < src_addr2->address_to[k]; l++) {
                                    tbl2_temp_block = (AK_mem_block *) AK_get_block(l);

                                    //if there is data in the block
                                    if (tbl2_temp_block->block->AK_free_space != 0) {
										
					//TUPLE_DICTS: for each tuple_dict in the block
                                        for (m = 0; m < DATA_BLOCK_SIZE; m += num_att) {
                                            if (tbl1_temp_block->block->tuple_dict[m + 1].type == FREE_INT)
                                                break;

					    //TUPLE_DICTS: for each tuple_dict in the block
                                            for (n = 0; n < DATA_BLOCK_SIZE; n += num_att) {
                                                if (tbl2_temp_block->block->tuple_dict[n + 1].type == FREE_INT)
                                                    break;
												
												//for each element in row
												for (o = 0; o < num_att; o++) {
													address = tbl1_temp_block->block->tuple_dict[m + o].address;
													size = tbl1_temp_block->block->tuple_dict[m + o].size;
													type = tbl1_temp_block->block->tuple_dict[m + o].type;
													
													switch (type) {
														case TYPE_INT: 
															memcpy(&temp_int, &(tbl1_temp_block->block->data[address]), size);
															sprintf(data1, "%d", temp_int);
															break;
														case TYPE_FLOAT:
															memcpy(&temp_float, &(tbl1_temp_block->block->data[address]), size);
															sprintf(data1, "%f", temp_float);
															break;
														case TYPE_VARCHAR:
														default:
															memset(data1, '\0', MAX_VARCHAR_LENGTH);
															memcpy(data1, &(tbl1_temp_block->block->data[address]), size);
													}
													
													address = tbl2_temp_block->block->tuple_dict[n + o].address;
													size = tbl2_temp_block->block->tuple_dict[n + o].size;
													type = tbl2_temp_block->block->tuple_dict[n + o].type;
													
													switch (type) {
														case TYPE_INT: 
															memcpy(&temp_int, &(tbl2_temp_block->block->data[address]), size);
															sprintf(data2, "%d", temp_int);
															break;
														case TYPE_FLOAT:
															memcpy(&temp_float, &(tbl2_temp_block->block->data[address]), size);
															sprintf(data2, "%f", temp_float);
															break;
														case TYPE_VARCHAR:
														default:
															memset(data2, '\0', MAX_VARCHAR_LENGTH);
															memcpy(data2, &(tbl2_temp_block->block->data[address]), size);
													}
													
													//if they are the same
												    if(strcmp(data1,data2)==0){
														different++;
														}
													if(different==(num_att-1)) summ=1;

												}
												//if same rows are found don't keep searching
												if(summ==1)break;
											}
											//if there is a difference between tuple_dicts
											if (summ == 0) {
												
												Ak_DeleteAll_L3(&row_root);	
												for (o = 0; o < num_att; o++) {
													address = tbl1_temp_block->block->tuple_dict[m + o].address;
													size = tbl1_temp_block->block->tuple_dict[m + o].size;
													type = tbl1_temp_block->block->tuple_dict[m + o].type;
													
													memset(data1, '\0', MAX_VARCHAR_LENGTH);
													memcpy(data1, tbl1_temp_block->block->data + address, size);

													Ak_Insert_New_Element(type, data1, dstTable, tbl1_temp_block->block->header[o].att_name, row_root);
												}

												Ak_insert_row(row_root);
											}
											num_rows = different = summ = 0;
										}
									}
								}
							} else break;
						}
					}
				}
		}
		
	AK_free(src_addr1);
        AK_free(src_addr2);
		Ak_DeleteAll_L3(&row_root);	
		AK_free(row_root);
		Ak_dbg_messg(LOW, REL_OP, "DIFFERENCE_TEST_SUCCESS\n\n");
		AK_EPI;
		return EXIT_SUCCESS;
	} else {
		Ak_dbg_messg(LOW, REL_OP, "\nAK_difference: Table/s doesn't exist!");
        AK_free(src_addr1);
        AK_free(src_addr2);
		AK_EPI;
		return EXIT_ERROR;
	}
	AK_EPI;
}
Esempio n. 6
0
/**
 * @author Lovro Predovan
 * @brief  Test funtion for index structures(list) and printing table
 * @return No return value
 */
void AK_index_test() {

    AK_PRO;
    int position;
    printf("\n********** INDEX TEST **********\n\n");

    list_ad *add_root;
    add_root = (list_ad *) AK_malloc(sizeof (list_ad));


    Ak_InitializelistAd(add_root);

    Ak_Insert_NewelementAd(1, 1, "Alen", add_root);
    element_ad some_element;

    some_element = Ak_Get_First_elementAd(add_root);
    Ak_Insert_NewelementAd(2, 2, "Markus", some_element);

    element_ad some_elementt = Ak_Get_Last_elementAd(add_root);
    Ak_Insert_NewelementAd(3, 3, "Mirko", some_elementt);

    element_ad some_elementtt = Ak_Get_Last_elementAd(add_root);
    Ak_Insert_NewelementAd(4, 4, "Sandra", some_elementtt);

    element_ad some_elementttt = Ak_Get_Last_elementAd(add_root);
    Ak_Insert_NewelementAd(5, 5, "Tonimir", some_elementttt);


    printf("\n********** Printing all values **********\n\n");
    element_ad ele = Ak_Get_First_elementAd(add_root);
    while (ele != 0)
    {
        printf("Value : %s\n", ele->attName);
        ele = Ak_Get_Next_elementAd(ele);
    }

    printf("\n********** Printing position values **********\n\n");
     element_ad last = Ak_Get_Last_elementAd(add_root);   
     printf("Last element in list: %s \n",last->attName);

     element_ad previous = Ak_Get_Previous_elementAd(last,add_root);
     printf("Previous element from list: %s \n",previous->attName);

     element_ad first = Ak_Get_First_elementAd(add_root);
     printf("First element in list: %s \n",first->attName);

     element_ad next = Ak_Get_Next_elementAd(first);
     printf("Next element in list after '%s' is : %s \n",first->attName,next->attName);

     printf("Position of element '%s' above is : %i \n",next->attName,Ak_Get_Position_Of_elementAd(next, add_root));

    printf("\n********** Deleting values **********\n\n");

    printf("Deleting element: %s \n",previous->attName);
    Ak_Delete_elementAd(previous, add_root) ;
    element_ad elem = Ak_Get_First_elementAd(add_root);

    printf("\n********** Printing values after delete**********\n\n");

        while (elem != 0)
        {
            printf("Value : %s\n", elem->attName);
            elem = Ak_Get_Next_elementAd(elem);
        }

    printf("\n********** Printing values after deleting all values**********\n\n");
    void Ak_Delete_All_elementsAd(add_root) ;
    element_ad eleme = Ak_Get_First_elementAd(add_root);
    while (elem != 0)
        {
            printf("Value : %s\n", eleme->attName);
            eleme = Ak_Get_Next_elementAd(eleme);

        }

    printf("\n********** Index test **********\n\n");
        //CREATING BITMAP INDEXES ON ATTRIBUTE FIRSTNAME AS REFERENCE

    char *tblName = "assistant";
    char *indexTblName = "assistantfirstname_bmapIndex";

    char *notExistingIndexName = "assistantincome_bmapIndex";

    struct list_node *att_root = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&att_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "firstname", tblName, "firstname", att_root);
 
    AK_create_Index_Table(tblName, att_root);

    AK_print_table(tblName);
    AK_print_table("AK_index");
    AK_print_index_table(indexTblName);

    printf("\n\nIndex table %s exists: %i\n\n",indexTblName,AK_index_table_exist(indexTblName));
    printf("Number of rows in index %s: %i\n\n",indexTblName,AK_get_index_num_records(indexTblName));
    printf("Number of attributes in index %s: %i\n\n",indexTblName,AK_num_index_attr(indexTblName));
    printf("Index table %s exists: %i\n\n\n",notExistingIndexName,AK_index_table_exist(notExistingIndexName));


    printf("\n********** Index test Passed**********\n\n");


    AK_EPI;
}
Esempio n. 7
0
/**
 * @author Nikola Bakoš, updated by Matija Šestak (function now uses caching), updated by Mislav Čakarić, updated by Dino Laktašić
 * @brief Function that extends the segment
 * @param table_name name of segment to extent
 * @param extent_type type of extent (can be one of:
        SEGMENT_TYPE_SYSTEM_TABLE,
        SEGMENT_TYPE_TABLE,
        SEGMENT_TYPE_INDEX,
        SEGMENT_TYPE_TRANSACTION,
        SEGMENT_TYPE_TEMP
  * @return address of new extent, otherwise EXIT_ERROR

 */
int AK_init_new_extent(char *table_name, int extent_type)
{
    char *sys_table;

    int old_size = 0;
    int new_size = 0;
    table_addresses *addresses = (table_addresses *) AK_get_segment_addresses(table_name);
    int block_address = addresses->address_from[0]; //before 1
    int block_written;

    AK_mem_block *mem_block = AK_get_block(block_address);
    int start_address = 0;
    float RESIZE_FACTOR = 0;
    int end_address;
    struct list_node *row_root;
    int obj_id = 0;
    //!!! to correct header BUG iterate through header from 0 to N-th block while there is
    //header attributes. Than create header and pass it to function for extent creation below.
    //Current implementation works only with tables with max MAX_ATTRIBUTES.
    int i = 0;
    AK_PRO;

    for (i = 0; i < MAX_EXTENTS_IN_SEGMENT; i++)
    {
        if (addresses->address_from[i] == 0)
            break;
        new_size = addresses->address_to[i] - addresses->address_from[i];
        if (new_size > old_size) //find largest extent
            old_size = new_size;
    }

    old_size++;

    if ((start_address = AK_new_extent(1, old_size, extent_type, mem_block->block->header)) == EXIT_ERROR)
    {
        printf("AK_init_new_extent: Could not allocate the new extent\n");
        AK_EPI;
        return EXIT_ERROR;
    }
    Ak_dbg_messg(HIGH, MEMO_MAN, "AK_init_new_extent: start_address=%i, old_size=%i, extent_type=%i\n", start_address, old_size, extent_type);

    switch (extent_type)
    {
    case SEGMENT_TYPE_TABLE:
        RESIZE_FACTOR = EXTENT_GROWTH_TABLE;
        sys_table = "AK_relation";
        break;
    case SEGMENT_TYPE_INDEX:
        RESIZE_FACTOR = EXTENT_GROWTH_INDEX;
        sys_table = "AK_index";
        break;
    case SEGMENT_TYPE_TRANSACTION:
        RESIZE_FACTOR = EXTENT_GROWTH_TRANSACTION;
        printf("Not implemented yet!\n");
        break;
    case SEGMENT_TYPE_TEMP:
        RESIZE_FACTOR = EXTENT_GROWTH_TEMP;
        printf("Not implemented yet!\n");
        break;
    }

    end_address = start_address + (old_size + old_size * RESIZE_FACTOR);
    //mem_block = (AK_mem_block *) AK_get_block(0);

    row_root = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root);
    //DeleteAllElements(row_root);
    Ak_Insert_New_Element(TYPE_INT, &obj_id, sys_table, "obj_id", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, table_name, sys_table, "name", row_root);
    Ak_Insert_New_Element(TYPE_INT, &start_address, sys_table, "start_address", row_root);
    Ak_Insert_New_Element(TYPE_INT, &end_address, sys_table, "end_address", row_root);
    Ak_insert_row(row_root);
    AK_EPI;
    return start_address;
}
Esempio n. 8
0
//int AK_selection(char *srcTable, char *dstTable, AK_list *expr) {
int AK_selection(char *srcTable, char *dstTable, struct list_node *expr) {
        AK_PRO;
	AK_header *t_header = (AK_header *) AK_get_header(srcTable);
	int num_attr = AK_num_attr(srcTable);

		int startAddress = AK_initialize_new_segment(dstTable, SEGMENT_TYPE_TABLE, t_header);
		if (startAddress == EXIT_ERROR) {
			AK_EPI;
			return EXIT_ERROR;
		}
		Ak_dbg_messg(LOW, REL_OP, "\nTABLE %s CREATED from %s!\n", dstTable, srcTable);
		table_addresses *src_addr = (table_addresses*) AK_get_table_addresses(srcTable);
		
		/*
		AK_list_elem row_root = (AK_list_elem) AK_malloc(sizeof (AK_list));
		Ak_Init_L3(&row_root);
		*/
		
		struct list_node * row_root = (struct list_node *) AK_malloc(sizeof(struct list_node));
		Ak_Init_L3(&row_root);
		
		int i, j, k, l, type, size, address;
		char data[MAX_VARCHAR_LENGTH];

		for (i = 0; src_addr->address_from[i] != 0; i++) {

			for (j = src_addr->address_from[i]; j < src_addr->address_to[i]; j++) {

				AK_mem_block *temp = (AK_mem_block *) AK_get_block(j);
				if (temp->block->last_tuple_dict_id == 0)
					break;
				for (k = 0; k < DATA_BLOCK_SIZE; k += num_attr) {

					if (temp->block->tuple_dict[k].type == FREE_INT)
						break;

					for (l = 0; l < num_attr; l++) {
						type = temp->block->tuple_dict[k + l].type;
						size = temp->block->tuple_dict[k + l].size;
						address = temp->block->tuple_dict[k + l].address;
						memcpy(data, &(temp->block->data[address]), size);
						data[size] = '\0';
						Ak_Insert_New_Element(type, data, dstTable, t_header[l].att_name, row_root);
					}

					if (AK_check_if_row_satisfies_expression(row_root, expr))
						Ak_insert_row(row_root);

					
					Ak_DeleteAll_L3(&row_root);
				}
			}
		}

		AK_free(src_addr);
		AK_free(t_header);
		AK_free(row_root);

		AK_print_table(dstTable);
	

	Ak_dbg_messg(LOW, REL_OP, "SELECTION_TEST_SUCCESS\n\n");
	AK_EPI;
	return EXIT_SUCCESS;
}
Esempio n. 9
0
/**
 * @author Dino Laktašić
 * @brief Function for creating test tables
 * @return No return value
 */
void AK_create_test_tables() {
    int mbr, year, id_prof, id_department;
    float weight;

    //---------------------------------------> CREATE TABLE 'STUDENT' <---------------------------------------
    //create header
    AK_header t_header[ MAX_ATTRIBUTES ];
    AK_header* temp;
    AK_PRO;
    temp = (AK_header*) AK_create_header("mbr", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("firstname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header + 1, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("lastname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header + 2, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("year", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header + 3, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("weight", TYPE_FLOAT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header + 4, temp, sizeof ( AK_header));
	AK_free(temp);
    memset(t_header + 5, 0, MAX_ATTRIBUTES - 5);

    //create table
    char *tblName = "student";
    int startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header);

    if (startAddress != EXIT_ERROR)
        printf("\nTABLE %s CREATED!\n", tblName);

    struct list_node *row_root = (struct list_node *) AK_malloc(sizeof (struct list_node));
    Ak_Init_L3(&row_root);

    mbr = 35890;
    year = 1999;
    weight = 80.00;

    //insert rows in table student
    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Dino", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Laktasic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Netko", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Netkic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Mislav", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Cakaric", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivan", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Horvat", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivo", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Marko", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Markovic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivan", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivanovic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Josip", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Josipovic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivan", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ankovic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Marina", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Marovic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Mario", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Maric", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Matija", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Matkovic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivana", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Ivic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "John", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Smith", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "William", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Brown", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "David", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Jones", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Robert", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "White", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "James", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Jones", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Jack", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Moore", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Joseph", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Harris", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Richard", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Thomas", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Daniel", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Jackson", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Martin", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Clark", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Joe", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Davis", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Paul", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Lee", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    mbr++;
    year++;
    weight += 0.75;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &mbr, tblName, "mbr", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Steve", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Parker", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, &year, tblName, "year", row_root);
    Ak_Insert_New_Element(TYPE_FLOAT, &weight, tblName, "weight", row_root);
    Ak_insert_row(row_root);

    AK_print_table(tblName);
	Ak_DeleteAll_L3(&row_root);

    //-------------------------------------------------------------------------------------------------------


    //--------------------------------------> CREATE TABLE 'PROFESSOR' <-------------------------------------
    //create header
    AK_header t_header2[ MAX_ATTRIBUTES ];

    temp = (AK_header*) AK_create_header("id_prof", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header2, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("firstname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header2 + 1, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("lastname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header2 + 2, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("tel", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header2 + 3, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("email", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header2 + 4, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("web_page", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header2 + 5, temp, sizeof ( AK_header));
	AK_free(temp);
    memset(t_header2 + 6, 0, MAX_ATTRIBUTES - 6);

    //create table
    tblName = "professor";
    startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header2);

    if (startAddress != EXIT_ERROR)
        printf("\nTABLE %s CREATED!\n", tblName);

    //row_root = (element) AK_malloc(sizeof (list));
    Ak_Init_L3(&row_root);

    id_prof = 35890;
    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Miroslav", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Baca", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042390873", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/baca.miroslav/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Igor", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Balaban", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "000000000", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/balaban.igor/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Antun", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Brumnic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/brumnic.antun/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Mirko", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Cubrilo", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/cubrilo.mirko/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Dragutin", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Kermek", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/kermek.dragutin/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Tonimir", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Kisasondi", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/kisasondi.tonimir/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Alen", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Lovrencic", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042390866", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/lovrencic.alen/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Markus", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Schatten", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042390892", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/schatten.markus/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Neven", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Vrcek", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042390892", tblName, "tel", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/vrcek.neven/", tblName, "web_page", row_root);
	Ak_insert_row(row_root);

    AK_print_table(tblName);
	
    //-------------------------------------------------------------------------------------------------------


	//--------------------------------------> CREATE TABLE 'PROFESSOR2' <-------------------------------------
	//create header
	
	temp = (AK_header*) AK_create_header("id_prof", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
	memcpy(t_header2, temp, sizeof ( AK_header));
	AK_free(temp);
	temp = (AK_header*) AK_create_header("firstname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
	memcpy(t_header2 + 1, temp, sizeof ( AK_header));
	AK_free(temp);
	temp = (AK_header*) AK_create_header("lastname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
	memcpy(t_header2 + 2, temp, sizeof ( AK_header));
	AK_free(temp);
	temp = (AK_header*) AK_create_header("tel", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
	memcpy(t_header2 + 3, temp, sizeof ( AK_header));
	AK_free(temp);
	memset(t_header2 + 4, 0, MAX_ATTRIBUTES - 4);

	//create table
	tblName = "professor2";
	startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header2);

	if (startAddress != EXIT_ERROR)
		printf("\nTABLE %s CREATED!\n", tblName);

	//row_root = (element) AK_malloc(sizeof (list));
	
	Ak_DeleteAll_L3(&row_root);
	Ak_Init_L3(&row_root);

	id_prof = 35890;
	id_prof++;
	//Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Miroslav", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Baca", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042390873", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Igor", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Balaban", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "000000000", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Antun", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Brumnic", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Mirko", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Cubrilo", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Dragutin", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Kermek", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Tonimir", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Kisasondi", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Alen", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Lovrencic", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042390866", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Markus", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Schatten", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042390892", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	id_prof++;
	Ak_DeleteAll_L3(&row_root);
	Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Neven", tblName, "firstname", row_root);
	Ak_Insert_New_Element(TYPE_VARCHAR, "Vrcek", tblName, "lastname", row_root);
	Ak_Insert_New_Element(TYPE_INT, "042390892", tblName, "tel", row_root);
	Ak_insert_row(row_root);

	AK_print_table(tblName);
	Ak_DeleteAll_L3(&row_root);
    //-------------------------------------------------------------------------------------------------------


    //--------------------------------------> CREATE TABLE 'ASSISTANT' <-------------------------------------
    //create table, same header as professor for intersect test
    AK_header t_header3[ MAX_ATTRIBUTES ];

    temp = (AK_header*) AK_create_header("id_prof", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header3, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("firstname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header3 + 1, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("lastname", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header3 + 2, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("tel", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header3 + 3, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("email", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header3 + 4, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("web_page", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header3 + 5, temp, sizeof ( AK_header));
	AK_free(temp);
    memset(t_header3 + 6, 0, MAX_ATTRIBUTES - 6);

    tblName = "assistant";
    startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header3);

    if (startAddress != EXIT_ERROR)
        printf("\nTABLE %s CREATED!\n", tblName);

	
    //row_root = (element) AK_malloc(sizeof (list));
    Ak_Init_L3(&row_root);

    id_prof = 35892;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Igor", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Balaban", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "000000000", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/balaban.igor/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof = 35896;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Tonimir", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Kisasondi", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042213777", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/kisasondi.tonimir/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    id_prof = 35898;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Markus", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Schatten", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042390892", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/schatten.markus/", tblName, "web_page", row_root);
    Ak_insert_row(row_root);
	
	id_prof = 35899;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Miran", tblName, "firstname", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Zlatović", tblName, "lastname", row_root);
    Ak_Insert_New_Element(TYPE_INT, "042390858", tblName, "tel", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "*****@*****.**", tblName, "email", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "www.foi.hr/nastavnici/zlatovic.miran/index.html", tblName, "web_page", row_root);
    Ak_insert_row(row_root);

    AK_print_table(tblName);
    //-------------------------------------------------------------------------------------------------------


    //--------------------------------------> CREATE TABLE 'EMPLOYEE' <--------------------------------------
    //create header
    AK_header t_header4[ MAX_ATTRIBUTES ];

    temp = (AK_header*) AK_create_header("id_prof", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header4, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("id_department", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header4 + 1, temp, sizeof ( AK_header));
	AK_free(temp);
    memset(t_header4 + 2, 0, MAX_ATTRIBUTES - 2);

    //create table
    tblName = "employee";
    startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header4);

    if (startAddress != EXIT_ERROR)
        printf("\nTABLE %s CREATED!\n", tblName);

    //row_root = (element) AK_malloc(sizeof (list));
	Ak_DeleteAll_L3(&row_root);
    Ak_Init_L3(&row_root);

    id_prof = 35890;
    id_department = 1;
    id_prof++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    id_prof++;
    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    //don't need id_prof++ here
    id_prof++;
    //id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_prof, tblName, "id_prof", row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_insert_row(row_root);

    AK_print_table(tblName);
	
    //-------------------------------------------------------------------------------------------------------


    //-------------------------------------> CREATE TABLE 'DEPARTMENT' <-------------------------------------
    //create header
    AK_header t_header5[ MAX_ATTRIBUTES ];

    temp = (AK_header*) AK_create_header("id_department", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header5, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("dep_name", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header5 + 1, temp, sizeof ( AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("manager", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header5 + 2, temp, sizeof ( AK_header));
	AK_free(temp);
    memset(t_header5 + 3, 0, MAX_ATTRIBUTES - 3);

    //create table
    tblName = "department";
    startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header5);

    if (startAddress != EXIT_ERROR)
        printf("\nTABLE %s CREATED!\n", tblName);

	/* not needed - row_root is still allocated 
		AK_free(row_root);
    	row_root = (struct list_node *) AK_malloc(sizeof (struct list_node));
	*/
	Ak_DeleteAll_L3(&row_root);
    Ak_Init_L3(&row_root);

    id_department = 1;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Department of Economics", tblName, "dep_name", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Redep", tblName, "manager", row_root);
    Ak_insert_row(row_root);

    //id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Department of Organization", tblName, "dep_name", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Zugaj", tblName, "manager", row_root);
    Ak_insert_row(row_root);

    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Department of Quantitative Methods", tblName, "dep_name", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Kero", tblName, "manager", row_root);
    Ak_insert_row(row_root);

    /* too long
    id_department++;
    DeleteAllElements(row_root);
    InsertNewElement(TYPE_INT, &id_department, tblName, "id_department", row_root);
    InsertNewElement(TYPE_VARCHAR, "Department of theoretical and applied foundations of Information Science", tblName, "dep_name", row_root);
    InsertNewElement(TYPE_VARCHAR, "", tblName, "manager", row_root);
    insert_row(row_root);*/

    //id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Department of Information Technology and Computing", tblName, "dep_name", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Hutinski", tblName, "manager", row_root);
    Ak_insert_row(row_root);

    id_department++;
    Ak_DeleteAll_L3(&row_root);
    Ak_Insert_New_Element(TYPE_INT, &id_department, tblName, "id_department", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Department of Information Systems Development", tblName, "dep_name", row_root);
    Ak_Insert_New_Element(TYPE_VARCHAR, "Vrcek", tblName, "manager", row_root);
    Ak_insert_row(row_root);

    /* too long
    id_department++;
    DeleteAllElements(row_root);
    InsertNewElement(TYPE_INT, &id_department, tblName, "id_department", row_root);
    InsertNewElement(TYPE_VARCHAR, "Department of foreign languages and general education discipline", tblName, "dep_name", row_root);
    InsertNewElement(TYPE_VARCHAR, "", tblName, "manager", row_root);
    insert_row(row_root);*/

    AK_print_table(tblName);
    //-------------------------------------------------------------------------------------------------------


    
    
    
    
    //---------------------------------------> CREATE TABLE 'COURSE' <---------------------------------------
    //create header
    AK_header t_header6[MAX_ATTRIBUTES];

    temp = (AK_header*) AK_create_header("id_course", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header6, temp, sizeof (AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("name", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header6 + 1, temp, sizeof (AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("category", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header6 + 2, temp, sizeof (AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("lecturer", TYPE_VARCHAR, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header6 + 3, temp, sizeof (AK_header));
	AK_free(temp);
    temp = (AK_header*) AK_create_header("active", TYPE_INT, FREE_INT, FREE_CHAR, FREE_CHAR);
    memcpy(t_header6 + 4, temp, sizeof (AK_header));
	AK_free(temp);
    memset(t_header6 + 5, '\0', MAX_ATTRIBUTES - 5);

    //create table
    tblName = "course";
    startAddress = AK_initialize_new_segment(tblName, SEGMENT_TYPE_TABLE, t_header6);

    if (startAddress != EXIT_ERROR)
        printf("\nTABLE %s CREATED!\n", tblName);

    Ak_DeleteAll_L3(&row_root);
    AK_free(row_root);

    AK_EPI;
}