Example #1
0
        public Declare ReadDeclare()
        {
            SkipComments();
            Declare dec = new Declare();

            Next();
            var exp = ReadExpression();

            if (exp is Variable vari1)
            {
                dec.VarName = vari1.Name;
            }
            else
            {
                ex("declare语法错误。");
            }
            exp = ReadExpression();
            SqlDataTyoe t = new SqlDataTyoe();

            if (exp is Variable vari)
            {
                t.DataType = SqlDataTyoe.GetDataType(vari.Name);
            }
            else if (exp is Function func)
            {
                t.DataType = SqlDataTyoe.GetDataType(func.Name);
                var paras = func.Arguments?.GetList();
                if (paras != null && paras.Count > 0)
                {
                    try
                    {
                        t.Length1 = int.Parse(((Constant)paras[0]).Content);
                        if (paras.Count > 1)
                        {
                            t.Length2 = int.Parse(((Constant)paras[1]).Content);
                            if (paras.Count > 2)
                            {
                                ex($"类型[{func.Name}]的长度/精度参数错误。");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        ex($"类型[{func.Name}]的长度/精度参数错误。");
                    }
                }
            }
            dec.DataType = t;

            return(dec);
        }
Example #2
0
 public virtual string Declare(Declare dec)
 {
     return($"DECLARE {dec.VarName} {GetDataType(dec.DataType)}");
 }