internal static void DbCommandExecuting(DbCommand cmd) { if (ExecutionEngine.SqlTranslationsEnabled) { TextWriter sqlLog = SqlLog; if (sqlLog != null) { lock (sqlLog) { bool flag2 = false; if ((cmd.Connection is SqlConnection) || ((cmd.Connection is LINQPadDbConnection) && (((LINQPadDbConnection)cmd.Connection).Proxy is SqlConnection))) { try { string serverVersion = cmd.Connection.ServerVersion; if (!(string.IsNullOrEmpty(serverVersion) || (int.Parse(serverVersion.Split(new char[] { '.' })[0]) < 10))) { flag2 = true; } } catch { } } if (SqlLog.GetStringBuilder().Length > 0) { sqlLog.WriteLine("GO\r\n"); } bool flag3 = false; if (cmd.Parameters.Count > 0) { sqlLog.WriteLine("-- Region Parameters"); foreach (DbParameter parameter in cmd.Parameters) { SqlParameter parameter2 = parameter as SqlParameter; if (parameter2 == null) { sqlLog.WriteLine(string.Concat(new object[] { "-- ", parameter.ParameterName, ": ", parameter.DbType, " [", parameter.Value, "]" })); } else if ((parameter2.Value == null) && ((parameter2.Direction == ParameterDirection.Input) || (parameter2.Direction == ParameterDirection.InputOutput))) { flag3 = true; } else { sqlLog.WriteLine(SqlParameterFormatter.GetInitializer(parameter2, flag2)); } } sqlLog.WriteLine("-- EndRegion"); } if (cmd.CommandType == CommandType.Text) { sqlLog.WriteLine(cmd.CommandText); } else if (cmd.CommandType == CommandType.TableDirect) { sqlLog.WriteLine("select * from " + cmd.CommandText); } else { DbParameter parameter3 = cmd.Parameters.OfType <DbParameter>().FirstOrDefault <DbParameter>(p => p.Direction == ParameterDirection.ReturnValue); StringBuilder builder = new StringBuilder("exec "); if (parameter3 != null) { builder.Append(parameter3.ParameterName + " = "); } builder.Append(cmd.CommandText); int num = 0; foreach (DbParameter parameter in cmd.Parameters) { if ((parameter.Direction != ParameterDirection.ReturnValue) && (parameter.Value != null)) { builder.Append(((num++ > 0) ? "," : "") + " " + (flag3 ? (parameter.ParameterName + "=") : "") + parameter.ParameterName + ((parameter.Direction == ParameterDirection.Input) ? "" : " OUTPUT")); } } sqlLog.WriteLine(builder.ToString()); } } } } }