This commit is contained in:
sunkaixuan 2017-09-12 18:56:01 +08:00
parent 2cf85ba888
commit 54b082e75b

View File

@ -227,16 +227,26 @@ namespace SqlSugar
#region Core #region Core
public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters) public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters)
{ {
if (this.ProcessingEventStartingSQL != null) try
ExecuteProcessingSQL(ref sql, parameters); {
ExecuteBefore(sql, parameters); if (this.ProcessingEventStartingSQL != null)
IDbCommand sqlCommand = GetCommand(sql, parameters); ExecuteProcessingSQL(ref sql, parameters);
int count = sqlCommand.ExecuteNonQuery(); ExecuteBefore(sql, parameters);
if (this.IsClearParameters) IDbCommand sqlCommand = GetCommand(sql, parameters);
sqlCommand.Parameters.Clear(); int count = sqlCommand.ExecuteNonQuery();
ExecuteAfter(sql, parameters); if (this.IsClearParameters)
if (this.IsClose()) this.Close(); sqlCommand.Parameters.Clear();
return count; ExecuteAfter(sql, parameters);
return count;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (this.IsClose()) this.Close();
}
} }
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters) public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
{ {
@ -255,33 +265,53 @@ namespace SqlSugar
} }
public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters) public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters)
{ {
if (this.ProcessingEventStartingSQL != null) try
ExecuteProcessingSQL(ref sql, parameters); {
ExecuteBefore(sql, parameters); if (this.ProcessingEventStartingSQL != null)
IDataAdapter dataAdapter = this.GetAdapter(); ExecuteProcessingSQL(ref sql, parameters);
IDbCommand sqlCommand = GetCommand(sql, parameters); ExecuteBefore(sql, parameters);
this.SetCommandToAdapter(dataAdapter, sqlCommand); IDataAdapter dataAdapter = this.GetAdapter();
DataSet ds = new DataSet(); IDbCommand sqlCommand = GetCommand(sql, parameters);
dataAdapter.Fill(ds); this.SetCommandToAdapter(dataAdapter, sqlCommand);
if (this.IsClearParameters) DataSet ds = new DataSet();
sqlCommand.Parameters.Clear(); dataAdapter.Fill(ds);
ExecuteAfter(sql, parameters); if (this.IsClearParameters)
if (this.IsClose()) this.Close(); sqlCommand.Parameters.Clear();
return ds; ExecuteAfter(sql, parameters);
return ds;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (this.IsClose()) this.Close();
}
} }
public virtual object GetScalar(string sql, params SugarParameter[] parameters) public virtual object GetScalar(string sql, params SugarParameter[] parameters)
{ {
if (this.ProcessingEventStartingSQL != null) try
ExecuteProcessingSQL(ref sql, parameters); {
ExecuteBefore(sql, parameters); if (this.ProcessingEventStartingSQL != null)
IDbCommand sqlCommand = GetCommand(sql, parameters); ExecuteProcessingSQL(ref sql, parameters);
object scalar = sqlCommand.ExecuteScalar(); ExecuteBefore(sql, parameters);
scalar = (scalar == null ? 0 : scalar); IDbCommand sqlCommand = GetCommand(sql, parameters);
if (this.IsClearParameters) object scalar = sqlCommand.ExecuteScalar();
sqlCommand.Parameters.Clear(); scalar = (scalar == null ? 0 : scalar);
ExecuteAfter(sql, parameters); if (this.IsClearParameters)
if (this.IsClose()) this.Close(); sqlCommand.Parameters.Clear();
return scalar; ExecuteAfter(sql, parameters);
return scalar;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (this.IsClose()) this.Close();
}
} }
#endregion #endregion