Beispiel #1
0
 def sel(self, src_table, dest_table, query, query_types ):
     return ak47.selection_test(src_table, dest_table, query, query_types)
Beispiel #2
0
        def execute(self,expr):
                token = sql_tokenizer().AK_parse_where(expr)
                # Selection 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

                # 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 selection (*)
                select_attr_names = table_attr_names
                # WHERE condition
                condition = token.condition if (token.condition is not None) else '' # keep an eye on this test
                # Expression
                expression = []
                # Expression types
                expr_types = []
                # Result table name (randomized)
                resultTable = "student"

                # Specific attributes for selection
                if(token.attributes):
                    if(token.attributes[0] == '*'):
                        
                        table_types_temp = table_attr_types
                        table_attr_types = []

                        for index,name in enumerate(select_attr_names):
                            table_attr_types.append(int(table_types_temp[index]))
                            expr_types.append(get_attr_type(table_types_temp[index]))
                    else:
                        select_attr_names = []
                        table_types_temp = table_attr_types
                        table_attr_types = []
                        select_columns = list(token.attributes)
                        for index,col in enumerate(select_columns):
                            if col not in table_attr_names:
                                print "\nError: table has no attribute " + str(col) + ":"
                                akdbError(expr,col)
                                return False
                        # Check attributes for selection
                        for ic,col in enumerate(select_columns):
                            for ia,tab in enumerate(table_attr_names):
                                if col == tab:
                                    if tab not in select_attr_names:
                                        select_attr_names.append(tab)
                                        table_attr_types.append(int(table_types_temp[ia]))
                                        expr_types.append(get_attr_type(table_types_temp[index]))
                                    else:
                                        print "\nError: duplicate attribute " + tab + ":"
                                        akdbError(expr,tab)
                                        return False

                        # SELECT too many attributes
                        if (len(select_attr_names) > len(table_attr_names)):
                            print "\nError: too many attibutes, table " + str(token.tableName) + " has " + str(len(table_attr_names)) 
                            return False

                # SELECT * ...
                else:
                    table_types_temp = table_attr_types
                    table_attr_types = []

                    for index,name in enumerate(select_attr_names):
                        table_attr_types.append(int(table_types_temp[index]))
                        expr_types.append(get_attr_type(table_types_temp[index]))

                # WHERE ...
                if (condition != ''):
                    # condition attribute types
                    condition_attr_types = map(lambda x: get_attr_type(x.replace("'","")),list(token.condition.expression[0]))
                    for cond in condition_attr_types:
                        expr_types.append(cond)

                expression.append(expr)
                
                # TEST DATA!
                print expression
                expression = ["year", "1990", ">"]
                expr_types = [ak47.TYPE_ATTRIBS, ak47.TYPE_INT, ak47.TYPE_OPERATOR]
                
                #if(ak47.AK_selection(table_name, resultTable, expression) == EXIT_SUCCESS):   
                if(ak47.selection_test(table_name, resultTable, expression, expr_types) == 1):
                    return True
                else:
                    return False
                return False
Beispiel #3
0
 def sel(self, src_table, dest_table, query, query_types):
     return ak47.selection_test(src_table, dest_table, query, query_types)