Beispiel #1
0
        public void PreparaComando(string cadenaSQL, List <CamposTabla> lp, object unaConexion = null, object unaTransaccion = null)
        {
            //OBJETO PARA MANIPULACION DE CADENA SQL
            StringBuilder sqlNueva = new StringBuilder(cadenaSQL);

            //VERIFICACION DE CAMPOS DEFINIDOS COMO AUTONUMERICOS
            if (lp.Count(x => x.Autonumerico == true) == 1)
            {
                exeAutoNum = true;
            }
            else
            {
                exeAutoNum = false;
            }

            //DETERMINAMOS NOMBRE DE TABLA

            /*if (cadenaSQL.Contains("insert into"))
             * {
             *  mensaje = "agregando";
             * }
             * if (cadenaSQL.Contains("update "))
             * {
             *  mensaje = "actualizando"; exeAutoNum = false;
             * }
             * if (cadenaSQL.Contains("delete from"))
             * {
             *  mensaje = "eliminando"; exeAutoNum = false;
             * }*/

            //CREAMOS OBJETO COMANDO
            comandoPreparado = new IfxCommand();
            comandoPreparado.Parameters.Clear();
            comandoPreparado.CommandType = System.Data.CommandType.Text;

            //SI ES EJECUCION DE AUTONUMERICO ESTABLECE LA DEVOLUCION DEL VALOR DE LA SECUENCIA
            if (exeAutoNum)
            {
                sqlNueva.Replace("{%}", "coalesce");
            }

            //CREACION DE PARAMETROS EN EL COMANDO Y DESCARTE DE CAMPOS AUTONUMERICOS
            foreach (CamposTabla item in lp)
            {
                if (item.Autonumerico == false)
                {
                    IfxParameter parametro = new IfxParameter();
                    parametro.ParameterName = "@" + item.Nombre;
                    if (item.TipoEstablecido)
                    {
                        parametro.DbType = item.Tipo;
                        parametro.Size   = item.Tamaño;
                    }
                    parametro.Direction = item.Direccion;
                    comandoPreparado.Parameters.Add(parametro);
                }
            }

            //command.CommandText = sqlNueva.Replace("@", ":").ToString();
            comandoPreparado.CommandText = sqlNueva.ToString();
            //ASIGNACION DE CONEXION Y TRANSACCION
            if (unaConexion == null)
            {
                comandoPreparado.Connection = this.Conexion;
            }
            else
            {
                comandoPreparado.Connection = (IfxConnection)unaConexion;
            }

            if (unaConexion != null && unaTransaccion != null)
            {
                comandoPreparado.Transaction = (IfxTransaction)unaTransaccion;
            }
            comandoPreparado.Prepare();
        }