• 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)


         string text = "select * from [admin] where aa=1 and cc='b' order by aa desc ";
         Regex reg = null; reg = new Regex(@"s+froms+.*?(s+wheres+|s+orders+|s+groups+)|s+froms+.+", RegexOptions.IgnoreCase);
    string table = reg.Match(text).Value; table = Regex.Replace(table.ToLower(), @"s+froms+|s+wheres+|[|]|s+orders+|s+groups+", "");
    reg = new Regex(@"selects+.*?s+froms+", RegexOptions.IgnoreCase); string field = reg.Match(text).Value;
    field = Regex.Replace(field.ToLower(), @"selects+|s+froms+|[|]", ""); reg = new Regex(@"s+wheres+.*?(s+orders+|s+groups+)|s+wheres+.+", RegexOptions.IgnoreCase); string condition = reg.Match(text).Value; condition = Regex.Replace(condition.ToLower(), @"s+wheres+|s+orders+|s+groups+|[|]", ""); reg = new Regex(@"s+orders+bys+.*?s(desc|asc)|s+orders+bys+.*?s", RegexOptions.IgnoreCase); string order = reg.Match(text).Value; order = Regex.Replace(order.ToLower(),@"s+orders+bys+|[|]", "");

      

  • 相关阅读:
    feign远程调用问题
    java8--stream
    feign业务组件远程请求 /oauth/token
    redis实现自增序列
    MySQL数据库 相关知识点
    netty
    spring的启动流程及bean的生命周期
    MethodHandleVS反射
    并发与并行
    关于注解的思考
  • 原文地址:https://www.cnblogs.com/babietongtianta/p/5325696.html
Copyright © 2020-2023  润新知