void set_catalog_constraints() { AK_PRO; int retValue; //Set PRIMARY KEY constraint on all tables of system catalog when it' s implemented //NOT NULL constraints on table AK_constraints_not_null retValue = AK_set_constraint_not_null("AK_constraints_not_null", "tableName", "tableNameNotNull"); retValue = AK_set_constraint_not_null("AK_constraints_not_null", "constraintName", "constraintNameNotNull"); retValue = AK_set_constraint_not_null("AK_constraints_not_null", "attributeName", "attributeNameNotNull"); //NOT NULL constraints on table AK_constraints_unique retValue = AK_set_constraint_not_null("AK_constraints_unique", "tableName", "tableName2NotNull"); retValue = AK_set_constraint_not_null("AK_constraints_unique", "constraintName", "constraintName2NotNull"); retValue = AK_set_constraint_not_null("AK_constraints_unique", "attributeName", "attributeName2NotNull"); //NOT NULL constraints on table AK_sequence retValue = AK_set_constraint_not_null("AK_sequence", "name", "nameNotNull"); retValue = AK_set_constraint_not_null("AK_sequence", "current_value", "current_valueNotNull"); retValue = AK_set_constraint_not_null("AK_sequence", "increment", "incrementNotNull"); //SET NOT NULL CONSTRAINT ON THE REST OF TABLES IN SYSTEM CATALOG!!! char attributeName[MAX_VARCHAR_LENGTH]=""; char constraintName[MAX_VARCHAR_LENGTH]=""; //UNIQUE constraints on table AK_constraints_not_null strcat(attributeName, "tableName"); strcat(attributeName, SEPARATOR); strcat(attributeName, "attributeName"); strcat(constraintName, "tableName"); strcat(constraintName, SEPARATOR); strcat(constraintName, "attributeName"); strcat(constraintName, "Unique"); retValue = Ak_set_constraint_unique("AK_constraints_not_null", attributeName, constraintName); //UNIQUE constraints on table AK_constraints_unique memset(constraintName, 0, MAX_VARCHAR_LENGTH); strcat(constraintName, "tableName"); strcat(constraintName, SEPARATOR); strcat(constraintName, "attributeName2"); strcat(constraintName, "Unique"); retValue = Ak_set_constraint_unique("AK_constraints_unique", attributeName, constraintName); //UNIQUE constraints on table AK_sequence retValue = Ak_set_constraint_unique("AK_sequence", "name", "nameUnique"); //SET UNIQUE CONSTRAINT ON THE REST OF TABLES IN SYSTEM CATALOG!!! AK_EPI; }
/** * @author unknown, Jurica Hlevnjak - added all tests except drop table test, updated by Tomislav Ilisevic, Maja Vračan * @brief Function for testing all DROP functions */ TestResult AK_drop_test() { AK_PRO; printf("=========================================================\n"); printf("========================DROP_TEST========================\n"); int results[114]; AK_drop_arguments *drop_arguments = (AK_drop_arguments *)AK_malloc(sizeof (AK_drop_arguments)); drop_arguments->next = (AK_drop_arguments *)AK_malloc(sizeof (AK_drop_arguments)); drop_arguments->value=(char*)"\0"; drop_arguments->next->next = (AK_drop_arguments *)AK_malloc(sizeof (AK_drop_arguments)); drop_arguments->next->value=(char*)"\0"; drop_arguments->next->next->next = (AK_drop_arguments *)AK_malloc(sizeof (AK_drop_arguments)); drop_arguments->next->next->value=(char*)"\0"; drop_arguments->next->next->next->next =NULL; printf("\n-----DROP TABLE-----\n"); AK_print_table("AK_relation"); drop_arguments->value = "department"; results[1] = AK_drop(DROP_TABLE, drop_arguments); AK_print_table("AK_relation"); printf("\n-----DROP CATALOG TABLE-----\n"); drop_arguments->value = "AK_attribute"; results[2] = AK_drop(DROP_TABLE, drop_arguments); AK_print_table("AK_attribute"); AK_print_table("AK_relation"); printf("\n-----DROP VIEW-----\n"); AK_print_table("AK_view"); drop_arguments->value = "view300"; results[3] = AK_drop(DROP_VIEW, drop_arguments); AK_print_table("AK_view"); printf("\n-----DROP HASH INDEX-----\n"); drop_arguments->value = "student_hash_index"; AK_print_table("AK_index"); results[4] = AK_drop(DROP_INDEX, drop_arguments); printf("\n-----DROP BITMAP INDEX-----\n"); drop_arguments->value = "assistantfirstname_bmapIndex"; AK_print_table("AK_index"); results[5] = AK_drop(DROP_INDEX, drop_arguments); AK_print_table("AK_index"); printf("\n-----DROP SEQUENCE-----\n"); drop_arguments->value = "sekvenca5"; AK_print_table("AK_sequence"); results[6] = AK_drop(DROP_SEQUENCE, drop_arguments); AK_print_table("AK_sequence"); printf("\n-----DROP TRIGGER-----\n"); AK_print_table("AK_trigger"); AK_print_table("AK_trigger_conditions"); drop_arguments->value = "trigg4"; drop_arguments->next->value = "AK_reference"; results[7] = AK_drop(DROP_TRIGGER, drop_arguments); AK_print_table("AK_trigger"); AK_print_table("AK_trigger_conditions"); printf("\n-----DROP FUNCTION-----\n"); AK_print_table("AK_function"); AK_print_table("AK_function_arguments"); drop_arguments->value = "test_funkcija"; drop_arguments->next->value = "date"; drop_arguments->next->next->value = "number"; drop_arguments->next->next->next->value = "int"; drop_arguments->next->next->next->next = NULL; results[8] = AK_drop(DROP_FUNCTION, drop_arguments); AK_print_table("AK_function"); AK_print_table("AK_function_arguments"); printf("\n-----DROP USER-----\n"); drop_arguments->value = "kritakac"; drop_arguments->next->value = "CASCADE"; AK_print_table("AK_user"); AK_print_table("AK_user_group"); AK_print_table("AK_user_right"); results[9] = AK_drop(DROP_USER, drop_arguments); AK_print_table("AK_user"); AK_print_table("AK_user_group"); AK_print_table("AK_user_right"); // to avoid problems with transfering the previous value for the drop group drop_arguments->next->value = "asdfghj"; // so that cascade doesn't stay printf("\n-----DROP GROUP-----\n"); drop_arguments->value = "grupa1"; AK_print_table("AK_group"); AK_print_table("AK_user_group"); AK_print_table("AK_group_right"); results[10] = AK_drop(DROP_GROUP, drop_arguments); AK_print_table("AK_group"); AK_print_table("AK_user_group"); AK_print_table("AK_group_right"); printf("\n-----DROP CONSTRAINT-----\n"); printf("\n-----UNIQUE-----\n"); char* tableName_1 = "student"; char* attName_1 = "year"; char* constraintName_1 = "yearUnique"; Ak_set_constraint_unique(tableName_1, attName_1, constraintName_1); AK_print_table("AK_constraints_unique"); drop_arguments->value = tableName_1; drop_arguments->next->value = attName_1; drop_arguments->next->next->value = constraintName_1; results[11] = AK_drop(DROP_CONSTRAINT, drop_arguments); AK_print_table("AK_constraints_unique"); printf("\n-----NOT NULL-----\n"); char* tableName_2 = "student"; char* attName_2 = "firstname"; char* constraintName_2 = "firstnameNotNull"; AK_set_constraint_not_null(tableName_2, attName_2, constraintName_2); AK_print_table("AK_constraints_not_null"); drop_arguments->value = tableName_2; drop_arguments->next->value = attName_2; drop_arguments->next->next->value = constraintName_2; results[12] = AK_drop(DROP_CONSTRAINT, drop_arguments); AK_print_table("AK_constraints_not_null"); printf("\n-----BETWEEN-----\n"); char* tableName_3 = "department"; char* attName_3 = "manager"; char* constraintName_3 = "manager_between"; char* newValue_3 = "Kero"; char* startValue_3 = "Hutinski"; char* endValue_3 = "Redep"; AK_set_constraint_between(tableName_3, constraintName_3, attName_3, startValue_3, endValue_3); AK_print_constraints(tableName_3); drop_arguments->value = tableName_3; drop_arguments->next->value = attName_3; drop_arguments->next->next->value = constraintName_3; drop_arguments->next->next->next->value = newValue_3; results[13] = AK_drop(DROP_CONSTRAINT, drop_arguments); AK_print_constraints(tableName_3); printf("======================END_DROP_TEST======================\n"); printf("Test results: \n"); int x=1; for (x; x<14; x++){ if(results[x]== EXIT_SUCCESS){ printf("Test %d: EXIT_SUCCESS \n", x); } else{ printf("Test %d: EXIT_ERROR \n", x); } } AK_EPI; return TEST_result(0,0); }