zoukankan      html  css  js  c++  java
  • ibatisNet 在运行时获取SQL的方法与限制

     1 、需引入如下4个namespace:

    using IBatisNet.DataMapper;
    using IBatisNet.DataMapper.Configuration;
    using IBatisNet.DataMapper.MappedStatements;
    using IBatisNet.DataMapper.Scope;
                    
    2、将下面语句添加到代码去,result 即为获取的SQL
                    ISqlMapper sqlMapper = new DomSqlMapBuilder().Configure();
                    IMappedStatement statement = sqlMapper.GetMappedStatement("getlist");
                    ISqlMapSession session = new SqlMapSession(sqlMapper);
                    if (sqlMapper.LocalSession != null)
                    {
                        session = sqlMapper.LocalSession;
                    }
                    else
                    {
                        session = sqlMapper.OpenConnection();
                    }
                    RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, ht, session);
                       
                    string resultSQL = scope.PreparedStatement.PreparedSql;

     -------------------------

    以上参考:   http://www.cnblogs.com/buguge/archive/2011/12/20/2294608.html

    3、ibatis获取正在执行的sql 限定条件


    a、不可用## 来获取字符串,只能用 $$

    b、必须传入对象Hashtable key value关系 然后直接

    c、若Hashtable 里面有 字符串需要传入,则添加数据格式如下
    ht.add("value"," '2121214-sadf-fds' ");
    xml里语句 select * from dual where id=$value$

    原先可直接传入 parameterClass="string"
    select * from dual where id=#value#
    这样会造成结果集为
    select * from dual where id=:param0

  • 相关阅读:
    微信Web开发者工具 移动调试 手机连接不上
    js 生成guid 自定义函数
    json
    c# 返回时间差
    Quartz.Net和队列应用demo
    数据库字段数字表示含义的枚举维护
    API文档自动生成,Swagger的配置
    请求资源文件报500错误
    文件上传三:base64文件上传
    文件上传二:FormData上传
  • 原文地址:https://www.cnblogs.com/wdw31210/p/2870168.html
Copyright © 2011-2022 走看看