示例#1
0
 private System.Data.IDbCommand GetDbCommand(ISqlMapper sqlMapper, string statementName, StrObjectDict paramObject, StrObjectDict dictParam, System.Collections.Generic.IDictionary <string, System.Data.ParameterDirection> dictParmDirection, System.Data.CommandType cmdType)
 {
     System.Data.IDbCommand result;
     if (cmdType == System.Data.CommandType.Text)
     {
         result = this.GetDbCommand(sqlMapper, statementName, paramObject);
     }
     else
     {
         IStatement       statement       = sqlMapper.GetMappedStatement(statementName).Statement;
         IMappedStatement mappedStatement = sqlMapper.GetMappedStatement(statementName);
         ISqlMapSession   sqlMapSession   = new SqlMapSession(sqlMapper);
         if (sqlMapper.LocalSession != null)
         {
             sqlMapSession = sqlMapper.LocalSession;
         }
         else
         {
             sqlMapSession = sqlMapper.OpenConnection();
         }
         RequestScope requestScope = statement.Sql.GetRequestScope(mappedStatement, paramObject, sqlMapSession);
         mappedStatement.PreparedCommand.Create(requestScope, sqlMapSession, statement, paramObject);
         System.Data.IDbCommand dbCommand = sqlMapSession.CreateCommand(cmdType);
         dbCommand.CommandText = requestScope.IDbCommand.CommandText;
         if (cmdType != System.Data.CommandType.StoredProcedure || dictParam == null)
         {
             result = dbCommand;
         }
         else
         {
             foreach (System.Collections.Generic.KeyValuePair <string, object> current in dictParam)
             {
                 string text = current.Key.ToString();
                 System.Data.IDbDataParameter dbDataParameter = dbCommand.CreateParameter();
                 dbDataParameter.ParameterName = text;
                 dbDataParameter.Value         = current.Value;
                 if (dictParmDirection != null && dictParmDirection.ContainsKey(text))
                 {
                     dbDataParameter.Direction = dictParmDirection[text];
                 }
                 dbCommand.Parameters.Add(dbDataParameter);
             }
             result = dbCommand;
         }
     }
     return(result);
 }
示例#2
0
        public System.Data.IDbCommand GetDbCommand(ISqlMapper sqlMapper, string statementName, object paramObject)
        {
            IStatement       statement       = sqlMapper.GetMappedStatement(statementName).Statement;
            IMappedStatement mappedStatement = sqlMapper.GetMappedStatement(statementName);
            ISqlMapSession   sqlMapSession   = new SqlMapSession(sqlMapper);

            if (sqlMapper.LocalSession != null)
            {
                sqlMapSession = sqlMapper.LocalSession;
            }
            else
            {
                sqlMapSession = sqlMapper.OpenConnection();
            }
            RequestScope requestScope = statement.Sql.GetRequestScope(mappedStatement, paramObject, sqlMapSession);

            mappedStatement.PreparedCommand.Create(requestScope, sqlMapSession, statement, paramObject);
            System.Data.IDbCommand dbCommand = sqlMapSession.CreateCommand(System.Data.CommandType.Text);
            dbCommand.CommandText = requestScope.IDbCommand.CommandText;
            return(dbCommand);
        }