def projection(self, table1, table_res, attributes): att = ak47.list_node() for attribute in attributes: ak47.AK_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, attribute, len(attribute), att) return ak47.AK_projection(table1, table_res, att, None)
def nat_Join(self, table1, table2, table_res, attributes): att = ak47.list_node() ak47.Ak_Init_L3(att) ak47.Ak_DeleteAll_L3(att) for attribute in attributes: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, attribute, len(attribute), att) return ak47.AK_join(table1, table2, table_res, att)
def get_value(self, row, col, table): element = ak47.list_node() ak47.Ak_Init_L3(&element) ak47.Ak_DeleteAll_L3(&element) element = ak47.AK_get_tuple(row, col, table) return ak47.AK_tuple_to_string(element)
def projection(self, table1, table_res, attributes): att = ak47.list_node() ak47.Ak_Init_L3(&att) ak47.Ak_DeleteAll_L3(&att) for attribute in attributes: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, attribute, len(attribute), att) return ak47.AK_projection(table1, table_res, att)
def nat_Join(self, table1, table2, table_res, attributes): att = ak47.list_node() ak47.AK_Init_L3(att) ak47.AK_DeleteAll_L3(att) for attribute in attributes: ak47.AK_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, attribute, len(attribute), att) return ak47.AK_join(table1, table2, table_res, att)
def delete_Row(self, table, column1, key): element = ak47.list_node() if type(key) == int: ak47.Ak_Update_Existing_Element(ak47.TYPE_INT, key, table, column1, element) elif type(key) == float: ak47.Ak_Update_Existing_Element(ak47.TYPE_FLOAT, key, table, column1, element) elif type(key) == str: ak47.Ak_Update_Existing_Element(ak47.TYPE_VARCHAR, key, table, column1, element) return ak47.Ak_delete_row(element)
def delete_Row(self, table, column1, key): element = ak47.list_node() ak47.Ak_Init_L3(&element) ak47.Ak_DeleteAll_L3(&element) if type(key) == int: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_INT, key, table, column1, element, 1) elif type(key) == float: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_FLOAT, key, table, column1, element, 1) elif type(key) == str: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_VARCHAR, key, table, column1, element, 1) return ak47.Ak_delete_row(element)
def delete_Row(self, table, column1, key): element = ak47.list_node() if type(key) == int: ak47.AK_Update_Existing_Element(ak47.TYPE_INT, key, table, column1, element) elif type(key) == float: ak47.AK_Update_Existing_Element(ak47.TYPE_FLOAT, key, table, column1, element) elif type(key) == str: ak47.AK_Update_Existing_Element(ak47.TYPE_VARCHAR, key, table, column1, element) return ak47.AK_delete_row(element)
def theta_join(self, table1, table2, table_res, expr): table1_attributes = [] table2_attributes = [] c = 0 while 1: attribute = ak47.AK_get_attr_name(table1, c) if attribute != None: table1_attributes.append(attribute) c += 1 else: break c = 0 while 1: attribute = ak47.AK_get_attr_name(table2, c) if attribute != None: table2_attributes.append(attribute) c += 1 else: break element = ak47.list_node() ak47.AK_Init_L3(element) ak47.AK_DeleteAll_L3(element) operatori = ["<", ">", "=", "AND", "OR", "+", "-", "*"] c = 0 for el in expr: if operatori.count(el) == 1: ak47.AK_InsertAtEnd_L3(ak47.TYPE_OPERATOR, el, len(el), element) c = 0 elif table1_attributes.count(el) == 1 or table2_attributes.count( el) == 1: ak47.AK_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, el, len(el), element) c = 1 else: if type(el) == int: ak47.AK_InsertAtEnd_L3(ak47.TYPE_INT, el, 4, element) elif type(el) == float: ak47.AK_InsertAtEnd_L3(ak47.TYPE_FLOAT, el, 4, element) elif type(el) == str: ak47.AK_InsertAtEnd_L3(ak47.TYPE_VARCHAR, el, len(el), element) c = 0 ak47.AK_theta_join(table1, table2, table_res, element)
def theta_join(self, table1, table2, table_res, expr): table1_attributes = [] table2_attributes = [] c = 0 while 1: attribute = ak47.AK_get_attr_name(table1, c) if attribute != None: table1_attributes.append(attribute) c += 1 else: break c = 0 while 1: attribute = ak47.AK_get_attr_name(table2, c) if attribute != None: table2_attributes.append(attribute) c += 1 else: break element = ak47.list_node() ak47.Ak_Init_L3(element) ak47.Ak_DeleteAll_L3(element) operatori = ["<", ">", "=", "AND", "OR", "+", "-", "*"] c = 0 for el in expr: if operatori.count(el) == 1: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_OPERATOR, el, len(el), element) c = 0 elif table1_attributes.count(el) == 1 or table2_attributes.count(el) == 1: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, el, len(el), element) c = 1 else: if type(el) == int: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_INT, el, 4, element) elif type(el) == float: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_FLOAT, el, 4, element) elif type(el) == str: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_VARCHAR, el, len(el), element) c = 0 ak47.AK_theta_join(table1, table2, table_res, element)
def update_Row(self, table, column1, column2, key, new_value): element = ak47.list_node() if type(key) == int: ak47.Ak_Update_Existing_Element(ak47.TYPE_INT, key, table, column1, element) elif type(key) == float: ak47.Ak_Update_Existing_Element(ak47.TYPE_FLOAT, key, table, column1, element) elif type(key) == str: ak47.Ak_Update_Existing_Element(ak47.TYPE_VARCHAR, key, table, column1, element) if type(new_value) == int: ak47.Ak_Insert_New_Element(ak47.TYPE_INT, new_value, table, column2, element) elif type(new_value) == float: ak47.Ak_Insert_New_Element(ak47.TYPE_FLOAT, new_value, table, column2, element) elif type(new_value) == str: ak47.Ak_Insert_New_Element(ak47.TYPE_VARCHAR, new_value, table, column2, element) return ak47.Ak_update_row(element)
def update_Row(self, table, column1, column2, key, new_value): element = ak47.list_node() if type(key) == int: ak47.AK_Update_Existing_Element(ak47.TYPE_INT, key, table, column1, element) elif type(key) == float: ak47.AK_Update_Existing_Element(ak47.TYPE_FLOAT, key, table, column1, element) elif type(key) == str: ak47.AK_Update_Existing_Element(ak47.TYPE_VARCHAR, key, table, column1, element) if type(new_value) == int: ak47.AK_Insert_New_Element(ak47.TYPE_INT, new_value, table, column2, element) elif type(new_value) == float: ak47.AK_Insert_New_Element(ak47.TYPE_FLOAT, new_value, table, column2, element) elif type(new_value) == str: ak47.AK_Insert_New_Element(ak47.TYPE_VARCHAR, new_value, table, column2, element) return ak47.AK_update_row(element)
def execute(self,expr): token = sql_tokenizer().AK_parse_where(expr) # Update table name table_name = str(token.tableName) if (ak47.AK_table_exist(table_name) == 0): print "Error: table '"+ table_name +"' does not exist" return False # Update values # update_attr_values = map(lambda x: x.replace("'",""),list(token.columnValues[0])) # Get table attribute list table_attr_names = str(ak47.AK_rel_eq_get_atrributes_char(table_name)).split(";") # Get table attribute type table_attr_types = str(ak47.AK_get_table_atribute_types(table_name)).split(";") # Attribute names for update update_attr_names = table_attr_names # WHERE condition condition = token.condition if (token.condition is not None) else '' # keep an eye on this test # Attributes for update if(token.columnNames): update_attr_names = [] table_types_temp = table_attr_types table_attr_types = [] update_columns = list(token.columnNames) for index,col in enumerate(update_columns): if col not in table_attr_names: print "\nError: table has no attribute " + str(col) + ":" akdbError(expr,col) return False # Check attributes for update for ic,col in enumerate(update_columns): for ia,tab in enumerate(table_attr_names): if col == tab: if tab not in update_attr_names: update_attr_names.append(tab) table_attr_types.append(int(table_types_temp[ia])) else: print "\nError: duplicate attribute " + tab + ":" akdbError(expr,tab) return False # UPDATE too many attributes if (len(update_attr_names) > len(table_attr_names)): print "\nError: too many attibutes, table " + str(token.tableName) + " has " + str(len(table_attr_names)) return False else: print "\nError: No attributes for for update!" return False # WHERE ... if (condition != ''): # condition attribute types condition_attr_types = map(lambda x: get_attr_type(x.replace("'","")),list(token.condition[1])) # Prepare update data element # This is Test Data! # Iteration required for more than one attribute! element = ak47.list_node() ak47.Ak_Init_L3(&element) ak47.Ak_DeleteAll_L3(&element) updateColumn = token.columnNames[0] whereColumn = token.condition[1][0] whereValue = token.condition[1][2] newValue = token.columnValues[0] if type(whereValue) == int: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_INT, whereValue, table_name, updateColumn, element, 1) elif type(whereValue) == float: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_FLOAT, whereValue, table_name, updateColumn, element, 1) #elif type(whereValue) == str: # ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_VARCHAR, whereValue, table_name, updateColumn, element, 1) if type(newValue) == int: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_INT, newValue, table_name, whereColumn, element, 0) elif type(newValue) == float: ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_FLOAT, newValue, table_name, whereColumn, element, 0) #elif type(newValue) == str: #ak47.Ak_Insert_New_Element_For_Update(ak47.TYPE_VARCHAR, newValue, table_name, whereColumn, element, 0) #update_Row(table, column1, column2, key, new_value) #if(ak47.update_Row(table_name, 'weight', 'id_student', 1, 80) == EXIT_SUCCESS): #if(ak47.Ak_update_row(element) == ak47.EXIT_SUCCESS): #return True else: return False return False
def projection(self, table1, table_res, attributes): att = ak47.list_node() for attribute in attributes: ak47.Ak_InsertAtEnd_L3(ak47.TYPE_ATTRIBS, attribute, len(attribute), att) return ak47.AK_projection(table1, table_res,att, None)