mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-29 10:49:36 +08:00
4.5.1.5
This commit is contained in:
parent
9416c307ca
commit
7a1e3dcb57
@ -101,7 +101,7 @@ namespace OrmTest.Demo
|
|||||||
var p11 = new SugarParameter("@p1", "1");
|
var p11 = new SugarParameter("@p1", "1");
|
||||||
var p22 = new SugarParameter("@p2", null, true);//isOutput=true
|
var p22 = new SugarParameter("@p2", null, true);//isOutput=true
|
||||||
//4
|
//4
|
||||||
var dt2 = db.Ado.UseStoredProcedure().GetDataTable("sp_school",p11,p22);
|
var dt2 = db.Ado.UseStoredProcedure().SqlQuery<School>("sp_school",p11,p22);
|
||||||
}
|
}
|
||||||
private static void Tran()
|
private static void Tran()
|
||||||
{
|
{
|
||||||
@ -175,6 +175,7 @@ namespace OrmTest.Demo
|
|||||||
var t2 = db.Ado.GetInt("select 1");
|
var t2 = db.Ado.GetInt("select 1");
|
||||||
var t3 = db.Ado.GetDataTable("select 1 as id");
|
var t3 = db.Ado.GetDataTable("select 1 as id");
|
||||||
db.Ado.CommitTran();
|
db.Ado.CommitTran();
|
||||||
|
var t11 = db.Ado.SqlQuery<Student>("select * from student");
|
||||||
//more
|
//more
|
||||||
//db.Ado.GetXXX...
|
//db.Ado.GetXXX...
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@ namespace SqlSugar
|
|||||||
public IDbTransaction Transaction { get; set; }
|
public IDbTransaction Transaction { get; set; }
|
||||||
public virtual SqlSugarClient Context { get; set; }
|
public virtual SqlSugarClient Context { get; set; }
|
||||||
internal CommandType OldCommandType { get; set; }
|
internal CommandType OldCommandType { get; set; }
|
||||||
internal bool OldClearParameters{ get; set; }
|
internal bool OldClearParameters { get; set; }
|
||||||
|
public IDataParameterCollection DataReaderParameters { get; set; }
|
||||||
public virtual IDbBind DbBind
|
public virtual IDbBind DbBind
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -98,7 +99,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Check.Exception(true,ErrorMessage.ConnnectionOpen, ex.Message);
|
Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +219,7 @@ namespace SqlSugar
|
|||||||
this.OldCommandType = this.CommandType;
|
this.OldCommandType = this.CommandType;
|
||||||
this.OldClearParameters = this.IsClearParameters;
|
this.OldClearParameters = this.IsClearParameters;
|
||||||
this.CommandType = CommandType.StoredProcedure;
|
this.CommandType = CommandType.StoredProcedure;
|
||||||
|
this.IsClearParameters = false;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -238,12 +240,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
|
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
|
||||||
{
|
{
|
||||||
|
var isSp = this.CommandType == CommandType.StoredProcedure;
|
||||||
if (this.ProcessingEventStartingSQL != null)
|
if (this.ProcessingEventStartingSQL != null)
|
||||||
ExecuteProcessingSQL(ref sql, parameters);
|
ExecuteProcessingSQL(ref sql, parameters);
|
||||||
ExecuteBefore(sql, parameters);
|
ExecuteBefore(sql, parameters);
|
||||||
IDbCommand sqlCommand = GetCommand(sql, parameters);
|
IDbCommand sqlCommand = GetCommand(sql, parameters);
|
||||||
var isAutoClose = this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null;
|
var isAutoClose = this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null;
|
||||||
IDataReader sqlDataReader = sqlCommand.ExecuteReader(isAutoClose ? CommandBehavior.CloseConnection : CommandBehavior.Default);
|
IDataReader sqlDataReader = sqlCommand.ExecuteReader(isAutoClose ? CommandBehavior.CloseConnection : CommandBehavior.Default);
|
||||||
|
if (isSp)
|
||||||
|
DataReaderParameters = sqlCommand.Parameters;
|
||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
@ -389,12 +394,25 @@ namespace SqlSugar
|
|||||||
builder.SqlQueryBuilder.sql.Append(sql);
|
builder.SqlQueryBuilder.sql.Append(sql);
|
||||||
if (parameters != null && parameters.Any())
|
if (parameters != null && parameters.Any())
|
||||||
builder.SqlQueryBuilder.Parameters.AddRange(parameters);
|
builder.SqlQueryBuilder.Parameters.AddRange(parameters);
|
||||||
|
List<T> result = null;
|
||||||
using (var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()))
|
using (var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray()))
|
||||||
{
|
{
|
||||||
var reval = this.DbBind.DataReaderToList<T>(typeof(T), dataReader, builder.SqlQueryBuilder.Fields);
|
result = this.DbBind.DataReaderToList<T>(typeof(T), dataReader, builder.SqlQueryBuilder.Fields);
|
||||||
builder.SqlQueryBuilder.Clear();
|
builder.SqlQueryBuilder.Clear();
|
||||||
return reval;
|
|
||||||
}
|
}
|
||||||
|
if (this.Context.Ado.DataReaderParameters != null)
|
||||||
|
{
|
||||||
|
foreach (IDataParameter item in this.Context.Ado.DataReaderParameters)
|
||||||
|
{
|
||||||
|
var parameter = parameters.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1));
|
||||||
|
if (parameter != null)
|
||||||
|
{
|
||||||
|
parameter.Value = item.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Context.Ado.DataReaderParameters = null;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
public virtual List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters)
|
public virtual List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters)
|
||||||
{
|
{
|
||||||
@ -572,7 +590,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.OldCommandType != 0) {
|
if (this.OldCommandType != 0)
|
||||||
|
{
|
||||||
this.CommandType = this.OldCommandType;
|
this.CommandType = this.OldCommandType;
|
||||||
this.IsClearParameters = this.OldClearParameters;
|
this.IsClearParameters = this.OldClearParameters;
|
||||||
this.OldCommandType = 0;
|
this.OldCommandType = 0;
|
||||||
|
@ -20,6 +20,7 @@ namespace SqlSugar
|
|||||||
void ExecuteBefore(string sql, SugarParameter[] pars);
|
void ExecuteBefore(string sql, SugarParameter[] pars);
|
||||||
void ExecuteAfter(string sql, SugarParameter[] pars);
|
void ExecuteAfter(string sql, SugarParameter[] pars);
|
||||||
|
|
||||||
|
IDataParameterCollection DataReaderParameters { get; set; }
|
||||||
CommandType CommandType { get; set; }
|
CommandType CommandType { get; set; }
|
||||||
bool IsEnableLogEvent { get; set; }
|
bool IsEnableLogEvent { get; set; }
|
||||||
Action<string, string> LogEventStarting { get; set; }
|
Action<string, string> LogEventStarting { get; set; }
|
||||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("4.5.1.4")]
|
[assembly: AssemblyVersion("4.5.1.5")]
|
||||||
[assembly: AssemblyFileVersion("4.5.1.4")]
|
[assembly: AssemblyFileVersion("4.5.1.5")]
|
||||||
|
Loading…
Reference in New Issue
Block a user