Exemple #1
0
 public static List<ApiParameter> GetRequestParamsFromSql(string sql)
 {
     var parmList = new List<ApiParameter>();
     var segments = SqlParserUtil.GetParsedSqlSegmentList(sql).Find(s => s.SegmentRegExp.StartsWith("(where)")); //取第三段
     if (segments != null)
     {
         foreach (var piece in segments.BodyPieces)
         {
             var match = Regex.Match(piece, @"(?<=:)[\w\W]+?(?=[\W])");
             if (match.Success)
             {
                 ApiParameter param = new ApiParameter()
                 {
                     data_type = DataType.String,
                     is_required = true,
                     parameter_name = match.Value,
                     parameter_name_chs = match.Value,
                 };
                 parmList.Add(param);
             }
         }
     }
     return parmList;
     
 }
Exemple #2
0
 public static List<ApiParameter> GetResponseParamsFromSql(string sql)
 {
     var parmList = new List<ApiParameter>();
     var segments = SqlParserUtil.GetParsedSqlSegmentList(sql).Find(s => s.SegmentRegExp.StartsWith("(select)")); //取第一段
     if (segments != null)
     {
         foreach (var piece in segments.BodyPieces)
         {
             string[] keyValue = Regex.Split(piece, "\\.");
             string parameterName = keyValue[0].Trim(',').Trim();
             if (keyValue.Length == 2)
             {
                 parameterName = keyValue[1].Trim(',').Trim();
             }
             ApiParameter param = new ApiParameter()
             {
                 data_type = DataType.String,
                 is_required = true,
                 parameter_name = parameterName,
                 parameter_name_chs = parameterName,
             };
             parmList.Add(param);
         }
     }
     return parmList;
 }
        public void GenerateParserTest()
        {
            var sql = @"select p.pca_code, p.pca_name
  from ompd.t_pca p
 where p.pca_code like substr(':pca_code', 0, 4) || '%';";

            //Console.WriteLine(SqlParserUtil.GetParsedSql(sql));
            //Console.WriteLine("---------------");
            SqlParserUtil.GetParsedSqlSegmentList(sql).ForEach(f =>
            {
                Console.Write(f.GetParsedSqlSegment());
                Console.WriteLine("\r\n-----------------\r\n");
            });
        }
Exemple #4
0
 public string ParseSql(string sql)
 {
     return SqlParserUtil.GetParsedSql(sql);
 }