예제 #1
0
def p_const_keys(p):
    '''const_keys   : const_keys COMA CONSTRAINT ID PRIMARY KEY PARIZQ lista_id PARDER
                    | const_keys COMA CONSTRAINT ID FOREIGN KEY PARIZQ ID PARDER REFERENCES ID PARIZQ ID PARDER
                    | const_keys COMA PRIMARY KEY PARIZQ lista_id PARDER
                    | const_keys COMA FOREIGN KEY PARIZQ ID PARDER REFERENCES ID PARIZQ ID PARDER'''

    if str(p[3]).upper() == 'CONSTRAINT':
        if str(p[5]).upper() == 'PRIMARY':
            for x in p[8]:
                const = TS.const(p[4], None, None, TS.t_constraint.PRIMARY,x)
                p[1].append(const)
        elif str(p[5]).upper() == 'FOREIGN':
            o = str(p[11]) + ',' + str(p[13])
            const = TS.const(p[4], o, None, TS.t_constraint.FOREIGN, p[8])
            p[1].append(const)
    elif str(p[3]).upper() == 'PRIMARY':
        for x in p[6]:
            const = TS.const(None, None, None, TS.t_constraint.PRIMARY,x)
            p[1].append(const)
    elif str(p[3]).upper() == 'FOREIGN':
        oo = str(p[9]) + ',' + str(p[11])
        const = TS.const(None, oo, None, TS.t_constraint.FOREIGN, p[6])
        p[1].append(const)
    
    p[0] = p[1]
예제 #2
0
def p_const_keys_2(p):
    '''const_keys   : CONSTRAINT ID PRIMARY KEY PARIZQ lista_id PARDER
                    | CONSTRAINT ID FOREIGN KEY PARIZQ ID PARDER REFERENCES ID PARIZQ ID PARDER
                    | PRIMARY KEY PARIZQ lista_id PARDER
                    | FOREIGN KEY PARIZQ ID PARDER REFERENCES ID PARIZQ ID PARDER'''
    arr = []
    
    if str(p[1]).upper() == 'CONSTRAINT':
        if str(p[3]).upper() == 'PRIMARY':
            for x in p[6]:
                const = TS.const(p[2], None, None, TS.t_constraint.PRIMARY,x)
                arr.append(const)
        elif str(p[3]).upper() == 'FOREIGN':
            t_c = str(p[9]) + ',' + str(p[11])
            const = TS.const(p[2], t_c, None, TS.t_constraint.FOREIGN, p[6])
            arr.append(const)
    elif str(p[1]).upper() == 'PRIMARY':
        for x in p[4]:
            const = TS.const(None, None, None, TS.t_constraint.PRIMARY,x)
            arr.append(const)
    elif str(p[1]).upper() == 'FOREIGN':
        t_t = str(p[7]) + ',' + str(p[9])
        const = TS.const(None, t_t, None, TS.t_constraint.FOREIGN, p[4])
        arr.append(const)

    p[0] = arr
예제 #3
0
def p_const_2(p):
    '''const    : DEFAULT valores
                | NOT NULL
                | NULL
                | CONSTRAINT ID UNIQUE
                | CONSTRAINT ID  UNIQUE PARIZQ lista_id PARDER
                | UNIQUE
                | CONSTRAINT ID CHECK PARIZQ exp_check PARDER
                | CHECK PARIZQ exp_check PARDER
                | PRIMARY KEY
                | REFERENCES ID PARIZQ lista_id PARDER
                 '''

    arr = []
    const = ''
    creado = False
    if str(p[1]).upper() == 'DEFAULT':
        const = TS.const(None, p[2], None, TS.t_constraint.DEFOULT, None)
    elif str(p[1]).upper() == 'NOT':
        const = TS.const(None, None, None, TS.t_constraint.NOT_NULL, None)
    elif str(p[1]).upper() == 'NULL':
        const = TS.const(None, None, None, TS.t_constraint.NULL, None)
    elif str(p[1]).upper() == 'UNIQUE':
        const = TS.const(None, None, None, TS.t_constraint.UNIQUE, None)
    elif str(p[1]).upper() == 'PRIMARY':
        const = TS.const(None, None, None, TS.t_constraint.PRIMARY, None)
    elif str(p[1]).upper() == 'REFERENCES':
        const = TS.const(
            p[2], p[4], None, TS.t_constraint.FOREIGN, None
        )  #ID va a ser igual al ID de la tabla y valor = columna de referencia
    elif str(p[1]).upper() == 'CHECK':
        x = str(p[3]).split(',')
        const = TS.const(None, x[2], x[1], TS.t_constraint.CHECK, None)
    elif str(p[1]).upper() == 'CONSTRAINT':
        if str(p[3]).upper() == 'UNIQUE':

            try:
                if (str(p[4]) == '('):
                    lista_id = p[5]
                    for t_id in lista_id:  #esto es para el alter, si viene varios id, el constraint se aplica a varias columnas
                        const = TS.const(str(p[2]), None, None,
                                         TS.t_constraint.UNIQUE, str(t_id))
                        arr.append(
                            const
                        )  #al agregarlos a las columnas verificar que no este dos o mas veces la misma
                    creado = True
            except:
                #constraint id unique
                const = TS.const(str(p[2]), None, None, TS.t_constraint.UNIQUE,
                                 None)

        elif str(p[3]).upper() == 'CHECK':
            x = str(p[5]).split(',')
            const = TS.const(p[2], x[2], x[1], TS.t_constraint.CHECK, None)

    if (creado == False):
        arr.append(const)

    p[0] = arr
예제 #4
0
def p_exp_check(p):
    '''exp_check    : ID MAYOR valores
                    | ID MENOR valores
                    | ID MAYIG valores
                    | ID MENIG valores
                    | ID IGUAL valores
                    | ID DIFEQ valores'''
    p[0] = TS.const(None, p[3], p[2], TS.t_constraint.CHECK, p[1])