Beispiel #1
0
 def execute(self):
         parser = sql_tokenizer()
         token = parser.AK_parse_drop(self.expr)
         if isinstance(token, str):
             print "Error: syntax error in expression"
             print token
             return False
         objekt = str(token.objekt)
         if(objekt == "table"):
             # izvlacimo ime tablice
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li tablica
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: table '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(0, table_name)
         elif(objekt == "index"):
             # izvlacimo ime indexa
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li index
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: index '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(1, table_name)
         elif(objekt == "view"):
             # izvlacimo ime view-a
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li view
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: table '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(2, table_name)
         elif(objekt == "sequence"):
             # izvlacimo ime sequence-a
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li sequence
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: sequence '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(3, table_name)
         elif(objekt == "trigger"):
             # izvlacimo ime triggera
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li trigger
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: trigger '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(4, table_name)
         elif(objekt == "function"):
             # izvlacimo ime funkcije
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li funkcija
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: funkcija '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(5, table_name)
         elif(objekt == "user"):
             # izvlacimo ime usera
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li user
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: user '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(6, table_name)
         elif(objekt == "group"):
             # izvlacimo ime grupe
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li grupa
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: group '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(7, table_name)
         elif(objekt == "constraint"):
             # izvlacimo ime constrainta
             table_name = str(token.ime_objekta)
             table_name = table_name.translate(None, "'[]")
             # postoji li constraint
             if (ak47.AK_table_exist(table_name) == 0):
                 print "Error: constraint '" + table_name + "' does not exist"
                 return False
             ak47.AK_drop_test_helper(8, table_name)
Beispiel #2
0
        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
Beispiel #3
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 #4
0
    def execute(self):
        expr = self.matcher.group(0)
        parser = sql_tokenizer()
        token = parser.AK_parse_insert_into(expr)
        if isinstance(token, str):
                print "Error: syntax error in expression"
                print expr
                print token
                return False
        table_name = str(token.tableName)
        # postoji li tablica
        if (ak47.AK_table_exist(table_name) == 0):
                print "Error: table '"+ table_name +"' does not exist"
                return False
        # vrijednosti podataka za unos
        insert_attr_values = map(lambda x: x.replace("'",""),list(token.columnValues[0]))
        # tipovi podataka za unos
        insert_attr_types = map(lambda x: get_attr_type(x.replace("'","")),list(token.columnValues[0]))
        #Dohvatiti listu atributa tablice
        table_attr_names = str(ak47.AK_rel_eq_get_atrributes_char(table_name)).split(";")
        #Dohvatiti tipove atributa tablice
        table_attr_types = str(ak47.AK_get_table_atribute_types(table_name)).split(";")
        # imena atributa za unos
        insert_attr_names = table_attr_names
        # navedeni su atributi za unos
        if(token.columns):
                insert_attr_names = []
                table_types_temp = table_attr_types
                table_attr_types = []
                insert_columns = list(token.columns[0])
                for index,col in enumerate(insert_columns):
                        if col not in table_attr_names:
                                print "\nError: table has no attribute '" + str(col) + "':"
                                akdbError(expr,col)
                                return False
                #provjera atributa za unos
                for ic,col in enumerate(insert_columns):
                        for ia,tab in enumerate(table_attr_names):
                                if col == tab:
                                        if tab not in insert_attr_names:
                                                insert_attr_names.append(tab)
                                                table_attr_types.append(int(table_types_temp[ia]))
                                        else:
                                                print "\nError: duplicate attribute " + tab + ":"
                                                akdbError(expr,tab)
                                                return False

                if (len(insert_columns) == len(insert_attr_values)):
                        for index,tip in enumerate(insert_attr_types):
                                if int(insert_attr_types[index]) != int(table_attr_types[index]):
                                        type_name = get_type_name(int(table_attr_types[index]))
                                        print "\nError: type error for attribute '" + insert_attr_names[index] + "':"
                                        akdbError(expr,insert_attr_values[index])
                                        print "Expected: " + type_name
                                        return False
                else:
                        print "\nError: attribute names number not matching attribute values number supplied for table '" + table_name + "':"
                        akdbError(expr,insert_columns[0])
                        return False
        # navedene su samo vrijednosti za unos
        elif (len(table_attr_names) < len(insert_attr_values)):
                print "\nError: too many attibutes, table " + str(token.tableName) + " has " + str(len(table_attr_names)) 
                return False
        elif (len(table_attr_names) > len(insert_attr_values)):
                print "\nError: too few attibutes, table " + str(token.tableName) + " has " + str(len(table_attr_names))
                return False
        else:
                for index,tip in enumerate(insert_attr_types):
                        if insert_attr_types[index] != int(table_attr_types[index]):
                                type_name = get_type_name(int(table_attr_types[index]))
                                print "\nError: type error for attribute '" + insert_attr_names[index] + "':"
                                akdbError(expr,insert_attr_values[index])
                                print "Expected: " + type_name
                                return False
        if(ak47.insert_data_test(table_name,insert_attr_names,insert_attr_values,insert_attr_types) == ak47.EXIT_SUCCESS):
                return True
        else:
                return False
        return False
Beispiel #5
0
 def execute(self):
         if ak47.AK_table_exist(self.matcher.group(1)) == 0:
                 result = "Table does not exist."
         else:
                 result = "Table exists. You can see it by typing \p <table_name>."
         return result
Beispiel #6
0
    def insert(self, expr):
        parser = sql_tokenizer()
        token = parser.AK_parse_insert_into(expr)
        if isinstance(token, str):
            print "Error: syntax error in expression"
            print expr
            print token
            return False
        table_name = str(token.tableName)
        # is there a table
        if (ak47.AK_table_exist(table_name) == 0):
            print "Error: table '" + table_name + "' does not exist"
            return False
        # data values for insert
        insert_attr_values = map(lambda x: x.replace(
            "'", ""), list(token.columnValues[0]))
        # data types for insert
        insert_attr_types = map(lambda x: get_attr_type(
            x.replace("'", "")), list(token.columnValues[0]))
        # get array of attributes for table
        table_attr_names = str(
            ak47.AK_rel_eq_get_atrributes_char(table_name)).split(";")
        # get attribute types for table
        table_attr_types = str(
            ak47.AK_get_table_atribute_types(table_name)).split(";")
        # attribute names for insert
        insert_attr_names = table_attr_names
        # attributes for insert
        if(token.columns):
            insert_attr_names = []
            table_types_temp = table_attr_types
            table_attr_types = []
            insert_columns = list(token.columns[0])
            for index, col in enumerate(insert_columns):
                if col not in table_attr_names:
                    print "\nError: table has no attribute '" + str(col) + "':"
                    akdbError(expr, col)
                    return False
            # check attributes for insert
            for ic, col in enumerate(insert_columns):
                for ia, tab in enumerate(table_attr_names):
                    if col == tab:
                        if tab not in insert_attr_names:
                            insert_attr_names.append(tab)
                            table_attr_types.append(int(table_types_temp[ia]))
                        else:
                            print "\nError: duplicate attribute " + tab + ":"
                            akdbError(expr, tab)
                            return False

            if (len(insert_columns) == len(insert_attr_values)):
                for index, tip in enumerate(insert_attr_types):
                    if int(insert_attr_types[index]) != int(table_attr_types[index]):
                        type_name = get_type_name(int(table_attr_types[index]))
                        print "\nError: type error for attribute '" + insert_attr_names[index] + "':"
                        akdbError(expr, insert_attr_values[index])
                        print "Expected: " + type_name
                        return False
            else:
                print "\nError: attribute names number not matching attribute values number supplied for table '" + table_name + "':"
                akdbError(expr, insert_columns[0])
                return False
        # values for insert
        elif (len(table_attr_names) < len(insert_attr_values)):
            print "\nError: too many attibutes, table " + str(token.tableName) + " has " + str(len(table_attr_names))
            return False
        elif (len(table_attr_names) > len(insert_attr_values)):
            print "\nError: too few attibutes, table " + str(token.tableName) + " has " + str(len(table_attr_names))
            return False
        else:
            for index, tip in enumerate(insert_attr_types):
                if insert_attr_types[index] != int(table_attr_types[index]):
                    type_name = get_type_name(int(table_attr_types[index]))
                    print "\nError: type error for attribute '" + insert_attr_names[index] + "':"
                    akdbError(expr, insert_attr_values[index])
                    print "Expected: " + type_name
                    return False
        if(ak47.insert_data_test(table_name, insert_attr_names, insert_attr_values, insert_attr_types) == ak47.EXIT_SUCCESS):
            return True
        else:
            return False
        return False