private LinkedList <Attrs> newLista(LinkedList <Attrs> oldList, LinkedList <string> mensajes, BaseDeDatos db)
        {
            LinkedList <Attrs> newL = new LinkedList <Attrs>();

            foreach (Attrs a in oldList)
            {
                if (a.type.Equals("string") || a.type.Equals("int") || a.type.Equals("double") || a.type.Equals("boolean") || a.type.Equals("map") ||
                    a.type.Equals("date") || a.type.Equals("time"))
                {
                    newL.AddLast(a);
                }
                else if (a.type.ToLower().Contains("list") || a.type.ToLower().Contains("map") || a.type.ToLower().Contains("set"))
                {
                    newL.AddLast(a);
                }
                else if (TablaBaseDeDatos.getUserType(a.type.ToLower(), db) || a.type.ToLower().Equals(id))
                {
                    newL.AddLast(a);
                }
                else
                {
                    Mensaje mensa = new Mensaje();
                    mensajes.AddLast(mensa.error("No se reconoce el tipo " + a.type + " en el USER TYPE : " + id, linea, columna, "Semantico"));
                }
            }

            return(newL);
        }
Example #2
0
        /*
         * Metodo que se encargara de ver si existen los tipos de columnas
         * @lista1 nuevas columnas
         * @lista2 columnas ya existentes
         * @mensajes output de mensajes
         */
        public Boolean searchTipo(LinkedList <Columna> lista, LinkedList <string> mensajes, BaseDeDatos db)
        {
            Mensaje mensa = new Mensaje();

            foreach (Columna cc in lista)
            {
                if (cc.tipo.Equals("string") || cc.tipo.Equals("counter") || cc.tipo.Equals("double") || cc.tipo.Equals("int") || cc.tipo.Equals("boolean") || cc.tipo.Equals("date") || cc.tipo.Equals("time"))
                {
                }
                else if (cc.tipo.Contains("map") || cc.tipo.Contains("list") || cc.tipo.Contains("set"))
                {
                }
                else
                {
                    Boolean existe = TablaBaseDeDatos.getUserType(cc.tipo, db);
                    if (!existe)
                    {
                        mensajes.AddLast(mensa.error("No existe este USER TYPE: " + cc.tipo, l, c, "Sematico"));
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #3
0
        /*
         * Metodo que verificara el tipo a guardar
         * @columna columan actual
         * @valor es el valor  a guardar
         * @original es la expresion sin ejecutar
         * @mensajes output de salida
         * @db BaseDeDatos actual
         */

        private Atributo checkinfo(Columna columna, object valor, object original, LinkedList <string> mensajes, BaseDeDatos db, Ambito ambito)
        {
            Mensaje mensa = new Mensaje();

            if (original == null)
            {
                if (!columna.pk)
                {
                    if (columna.tipo.Equals("string") || columna.tipo.Equals("date") || columna.tipo.Equals("time"))
                    {
                        return(new Atributo(columna.name, null, columna.tipo));
                    }
                    else if (columna.tipo.Equals("int") || columna.tipo.Equals("double") || columna.tipo.Equals("boolean") || columna.tipo.Contains("map") || columna.tipo.Contains("list") || columna.tipo.Contains("set"))
                    {
                        ambito.listadoExcepciones.AddLast(new Excepcion("valuesexception", "No se le puede asignar a un tipo: " + columna.tipo + " un valor null"));
                        mensajes.AddLast(mensa.error("No se le puede asignar a un tipo: " + columna.tipo + " un valor null", l, c, "Semantico"));
                    }
                    else
                    {
                        Boolean temp = TablaBaseDeDatos.getUserType(columna.tipo, db);
                        if (temp)
                        {
                            return(new Atributo(columna.name, new InstanciaUserType(columna.tipo, null), columna.tipo));
                        }
                        else
                        {
                            mensajes.AddLast(mensa.error("No existe el USER TYPE: " + columna.tipo + " en la DB: " + db.nombre, l, c, "Semantico"));
                        }
                    }
                }
                else
                {
                    ambito.listadoExcepciones.AddLast(new Excepcion("valuesexception", "La columna: " + columna.name + " es clave primaria no puede asignarsele un valor null"));

                    mensajes.AddLast(mensa.error("La columna: " + columna.name + " es clave primaria no puede asignarsele un valor null", l, c, "Semantico"));
                }
            }
            else
            {
                if (valor != null)
                {
                    if (columna.tipo.Equals("string") && valor.GetType() == typeof(string))
                    {
                        return(new Atributo(columna.name, (string)valor, "string"));
                    }
                    else if (columna.tipo.Equals("int") && valor.GetType() == typeof(int))
                    {
                        return(new Atributo(columna.name, (int)valor, "int"));
                    }
                    else if (columna.tipo.Equals("double") && valor.GetType() == typeof(Double))
                    {
                        return(new Atributo(columna.name, (Double)valor, "double"));
                    }
                    else if (columna.tipo.Equals("boolean") && valor.GetType() == typeof(Boolean))
                    {
                        return(new Atributo(columna.name, (Boolean)valor, "boolean"));
                    }
                    else if (columna.tipo.Equals("date") && valor.GetType() == typeof(DateTime))
                    {
                        return(new Atributo(columna.name, (DateTime)valor, "date"));
                    }
                    else if (columna.tipo.Equals("time") && valor.GetType() == typeof(TimeSpan))
                    {
                        return(new Atributo(columna.name, (TimeSpan)valor, "time"));
                    }
                    else if (columna.tipo.Equals("counter") && valor.GetType() == typeof(int))
                    {
                        return(new Atributo(columna.name, (int)valor, "int"));
                    }
                    else if (columna.tipo.Contains("map") && valor.GetType() == typeof(Map))
                    {
                        Map    temp = (Map)valor;
                        string tipo = columna.tipo.TrimStart('m').TrimStart('a').TrimStart('p').TrimStart('<');
                        if (tipo.EndsWith('>'))
                        {
                            tipo = tipo.Substring(0, tipo.Length - 1);
                        }
                        if (temp.id.Equals(tipo))
                        {
                            return(new Atributo(columna.name, temp, tipo));
                        }
                        mensajes.AddLast(mensa.error("No coinciden los tipos de map: " + tipo + " con: " + temp.id, l, c, "Semantico"));
                    }
                    else if (columna.tipo.Contains("set") && valor.GetType() == typeof(Set))
                    {
                        Set temp = (Set)valor;

                        string tipo = columna.tipo.TrimStart('s').TrimStart('e').TrimStart('t').TrimStart('<');
                        if (tipo.EndsWith('>'))
                        {
                            tipo = tipo.Substring(0, tipo.Length - 1);
                        }
                        if (temp.id.Equals(tipo))
                        {
                            return(new Atributo(columna.name, temp, tipo));
                        }
                        mensajes.AddLast(mensa.error("No coinciden los tipos de Set: " + tipo + " con: " + temp.id, l, c, "Semantico"));
                    }
                    else if (columna.tipo.Contains("list") && valor.GetType() == typeof(List))
                    {
                        List temp = (List)valor;

                        string tipo = columna.tipo.TrimStart('l').TrimStart('i').TrimStart('s').TrimStart('t').TrimStart('<');
                        if (tipo.EndsWith('>'))
                        {
                            tipo = tipo.Substring(0, tipo.Length - 1);
                        }
                        if (temp.id.Equals(tipo))
                        {
                            return(new Atributo(columna.name, temp, tipo));
                        }
                        mensajes.AddLast(mensa.error("No coinciden los tipos de List: " + tipo + " con: " + temp.id, l, c, "Semantico"));
                    }
                    else if (valor.GetType() == typeof(InstanciaUserType))
                    {
                        InstanciaUserType temp = (InstanciaUserType)valor;
                        if (columna.tipo.Equals(temp.tipo))
                        {
                            return(new Atributo(columna.name, (InstanciaUserType)valor, columna.tipo));
                        }
                        else
                        {
                            mensajes.AddLast(mensa.error("No se le puede asignar a la columna: " + columna.name + " un tipo: " + temp.tipo, l, c, "Semantico"));
                        }
                    }
                    else
                    {
                        ambito.listadoExcepciones.AddLast(new Excepcion("valuesexception", "No se puede asignar a la columna: " + columna.name + " el valor: " + valor));
                        mensajes.AddLast(mensa.error("No se puede asignar a la columna: " + columna.name + " el valor: " + valor, l, c, "Semantico"));
                    }
                }
                else
                {
                    if (columna.tipo.Equals("string") || columna.tipo.Equals("date") || columna.tipo.Equals("time"))
                    {
                        return(new Atributo(columna.name, null, columna.tipo));
                    }
                    else if (columna.tipo.Equals("boolean") || columna.tipo.Equals("int") || columna.tipo.Equals("double") || columna.tipo.Contains("map") || columna.tipo.Contains("list") || columna.tipo.Contains("set"))
                    {
                        ambito.listadoExcepciones.AddLast(new Excepcion("valuesexception", "No se puede asignar a la columna: " + columna.name + " el valor: " + valor + valor));

                        mensajes.AddLast(mensa.error("No se puede asignar a la columna: " + columna.name + " el valor: " + valor, l, c, "Semantico"));
                    }
                    else
                    {
                        return(new Atributo(columna.name, new InstanciaUserType(columna.tipo, null), columna.tipo));
                    }
                }
            }
            return(null);
        }
        /*
         * Metodo del padre
         * @ts tabla de simbolos global
         * @user usuario que esta ejecutando la accion
         * @baseD base de datos donde se esta ejecutando la accion
         * @mensajes respuesta por parte de la accion
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje     mensa = new Mensaje();
            BaseDeDatos db    = TablaBaseDeDatos.getBase(ambito.baseD);

            if (db != null)
            {
                if (ambito.usuario.Equals("admin"))
                {
                    if (!TablaBaseDeDatos.getUserType(id, db))
                    {
                        LinkedList <Attrs> newL = newLista(lista, ambito.mensajes, db);
                        if (lista.Count() == newL.Count())
                        {
                            User_Types u = new User_Types(id, newL);
                            db.objetos.user_types.AddLast(u);
                        }

                        return("");
                    }
                    else
                    {
                        if (!flag)
                        {
                            ambito.listadoExcepciones.AddLast(new Excepcion("typealreadyexists", "El USER TYPE : " + id + " ya existe en la base de datos : " + ambito.baseD));
                            ambito.mensajes.AddLast(mensa.error("El USER TYPE : " + id + " ya existe en la base de datos : " + ambito.baseD, linea, columna, "Semantico"));
                        }
                        else
                        {
                            return("");
                        }
                    }
                }
                else
                {
                    Usuario us = TablaBaseDeDatos.getUsuario(ambito.usuario);
                    if (us != null)
                    {
                        if (TablaBaseDeDatos.getPermiso(us, ambito.baseD))
                        {
                            if (!TablaBaseDeDatos.getUserType(id, db))
                            {
                                LinkedList <Attrs> newL = newLista(lista, ambito.mensajes, db);
                                if (lista.Count() == newL.Count())
                                {
                                    User_Types u = new User_Types(id, newL);
                                    db.objetos.user_types.AddLast(u);
                                }

                                return("");
                            }
                            else
                            {
                                if (!flag)
                                {
                                    ambito.listadoExcepciones.AddLast(new Excepcion("typealreadyexists", "El USER TYPE : " + id + " ya existe en la base de datos : " + ambito.baseD));
                                    ambito.mensajes.AddLast(mensa.error("El USER TYPE : " + id + " ya existe en la base de datos : " + ambito.baseD, linea, columna, "Semantico"));
                                }
                                else
                                {
                                    return("");
                                }
                            }
                        }
                        else
                        {
                            ambito.mensajes.AddLast(mensa.error("El usuario : " + ambito.usuario + " no tiene permisos sobre la base de datos : " + ambito.baseD, linea, columna, "Semantico"));
                        }
                    }
                    else
                    {
                        ambito.mensajes.AddLast(mensa.error("El usuario : " + ambito.usuario + " no existe ", linea, columna, "Semantico"));
                    }
                }
            }
            else
            {
                ambito.mensajes.AddLast(mensa.error("La base de datos : " + ambito.baseD + " no existe o seleccione una antes Comando (USE) ", linea, columna, "Semantico"));
            }

            return(null);
        }
        /*
         * Metodo de la implementacion
         * @ts tabla de simbolos global
         * @user usuario que ejecuta la accion
         * @baseD base de datos donde estamos ejecutando todo
         * @mensajes linkedlist con la salida deseada
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje             mensa    = new Mensaje();
            object              a        = (valor == null) ? null : valor.ejecutar(ts, ambito, tsT);
            LinkedList <string> mensajes = ambito.mensajes;
            object              res      = ts.getValor(id);
            string              baseD    = ambito.baseD;
            string              existe   = (res == null) ? "si" : res.ToString();

            if (parametro)
            {
                ts.AddLast(new Simbolo(tipo, id));
                if (tipo.Equals("list"))
                {
                    ts.setValor(id, new List("none", new LinkedList <object>()));
                }
                else if (tipo.Equals("set"))
                {
                    ts.setValor(id, new Set("none", new LinkedList <object>()));
                }
                else if (tipo.Equals("map"))
                {
                    ts.setValor(id, new Map("none", new LinkedList <KeyValue>()));
                }
                else if (tipo.Equals("string") || tipo.Equals("int") || tipo.Equals("double") || tipo.Equals("date") || tipo.Equals("time") || tipo.Equals("boolean") || tipo.Equals("cursor"))
                {
                }
                else
                {
                    ts.setValor(id, new InstanciaUserType("none", new LinkedList <Atributo>()));
                }

                return("");
            }
            else if (existe.Equals("none"))
            {
                if (valor == null)
                {
                    if (tipo.Equals("int"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, 0);
                    }
                    else if (tipo.Equals("double"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, 0.0);
                    }
                    else if (tipo.Equals("boolean"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, false);
                    }
                    else if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, null);
                        return("");
                    }
                    else if (tipo.Equals("map"))
                    {
                        mensajes.AddLast(mensa.error("El tipo MAP necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else if (tipo.Equals("list"))
                    {
                        mensajes.AddLast(mensa.error("El tipo LIST necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else if (tipo.Equals("set"))
                    {
                        mensajes.AddLast(mensa.error("El tipo SET necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else if (tipo.Equals("cursor"))
                    {
                        mensajes.AddLast(mensa.error("El tipo CURSOR necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else
                    {
                        BaseDeDatos bd = TablaBaseDeDatos.getBase(baseD);
                        if (bd != null)
                        {
                            if (TablaBaseDeDatos.getUserType(tipo.ToLower(), bd))
                            {
                                ts.AddLast(new Simbolo(tipo, id));
                                ts.setValor(id, new InstanciaUserType(tipo, null));
                            }
                            else
                            {
                                mensajes.AddLast(mensa.error("El tipo " + tipo + " no es un userType en esta base de datos: " + baseD, l, c, "Semantico"));
                                return(null);
                            }
                        }
                        return("");
                    }
                }
                else
                {
                    if (a != null)
                    {
                        if (tipo.Equals("string") && a.GetType() == typeof(string))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (string)a);
                        }
                        else if (tipo.Equals("int") && a.GetType() == typeof(int))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (int)a);
                        }
                        else if (tipo.Equals("int") && a.GetType() == typeof(Double))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, Convert.ToInt32((Double)a));
                        }
                        else if (tipo.Equals("double") && a.GetType() == typeof(Double))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (Double)a);
                        }
                        else if (tipo.Equals("double") && a.GetType() == typeof(int))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, Convert.ToDouble((int)a));
                        }
                        else if (tipo.Equals("boolean") && a.GetType() == typeof(Boolean))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (Boolean)a);
                        }
                        else if (tipo.Equals("date") && a.GetType() == typeof(DateTime))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (DateTime)a);
                        }
                        else if (tipo.Equals("time") && a.GetType() == typeof(TimeSpan))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (TimeSpan)a);
                        }
                        else if (tipo.Equals("map") && a.GetType() == typeof(Map))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (Map)a);
                        }
                        else if (tipo.Equals("list") && a.GetType() == typeof(List))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (List)a);
                        }
                        else if (tipo.Equals("set") && a.GetType() == typeof(Set))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            Set    temp = (Set)a;
                            object resp = temp.buscarRepetidos(mensajes, l, c);
                            if (resp == null)
                            {
                                return(null);
                            }
                            temp.order();
                            ts.setValor(id, temp);
                        }
                        else if (tipo.Equals("cursor") && a.GetType() == typeof(TypeCursor))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (TypeCursor)a);
                        }
                        else if (a.GetType() == typeof(InstanciaUserType))
                        {
                            InstanciaUserType ins = (InstanciaUserType)a;
                            if (tipo.Equals(ins.tipo.ToLower()))
                            {
                                ts.AddLast(new Simbolo(tipo, id));
                                ts.setValor(id, ins);
                            }
                            else
                            {
                                Mensaje me = new Mensaje();
                                mensajes.AddLast(me.error("La variable " + id + " es de Tipo: " + tipo + " no se puede instanciar al tipo: " + ins.tipo, l, c, "Semantico"));
                            }
                        }
                        else
                        {
                            Mensaje me = new Mensaje();
                            mensajes.AddLast(me.error("La variable " + id + " no se le puede asignar este valor " + a.ToString(), l, c, "Semantico"));
                            return(null);
                        }
                        return("");
                    }
                    else
                    {
                        if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time"))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, null);
                        }
                        else if (tipo.Equals("int") || tipo.Equals("double") || tipo.Equals("map") || tipo.Equals("set") || tipo.Equals("list") || tipo.Equals("cursor") || tipo.Equals("boolean"))
                        {
                            mensajes.AddLast(mensa.error("No se le puede asignar un valor null al tipo: " + tipo, l, c, "Semantico"));
                            return(null);
                        }
                        else
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, new InstanciaUserType(tipo, null));
                        }
                        return("");
                    }
                }
            }
            else
            {
                Mensaje me = new Mensaje();
                ambito.listadoExcepciones.AddLast(new Excepcion("objectalreadyexists", "La variable " + id + " ya existe en este ambito"));
                mensajes.AddLast(me.error("La variable " + id + " ya existe en este ambito", l, c, "Semantico"));
            }

            return(null);
        }