Commit 9afb2fca authored by Marc Gravell's avatar Marc Gravell

Introducing: literal value replacements, i.e. `where row.Id={=id}` - use...

Introducing: literal value replacements, i.e. `where row.Id={=id}` - use rarely, but to avoid query-plan poisoning
parent 056b22a5
This diff is collapsed.
......@@ -27,7 +27,7 @@ public static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn, C
{
object param = command.Parameters;
var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(T), param == null ? null : param.GetType(), null);
var info = GetCacheInfo(identity);
var info = GetCacheInfo(identity, param);
bool wasClosed = cnn.State == ConnectionState.Closed;
using (var cmd = (DbCommand)command.SetupCommand(cnn, info.ParamReader))
{
......@@ -61,7 +61,7 @@ public static async Task<int> ExecuteAsync(this IDbConnection cnn, CommandDefini
{
object param = command.Parameters;
var identity = new Identity(command.CommandText, command.CommandType, cnn, null, param == null ? null : param.GetType(), null);
var info = GetCacheInfo(identity);
var info = GetCacheInfo(identity, param);
bool wasClosed = cnn.State == ConnectionState.Closed;
using (var cmd = (DbCommand)command.SetupCommand(cnn, info.ParamReader))
{
......@@ -252,7 +252,7 @@ public static async Task<int> ExecuteAsync(this IDbConnection cnn, CommandDefini
{
object param = command.Parameters;
var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(TFirst), param == null ? null : param.GetType(), new[] { typeof(TFirst), typeof(TSecond), typeof(TThird), typeof(TFourth), typeof(TFifth), typeof(TSixth), typeof(TSeventh) });
var info = GetCacheInfo(identity);
var info = GetCacheInfo(identity, param);
bool wasClosed = cnn.State == ConnectionState.Closed;
try
{
......@@ -308,7 +308,7 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
{
object param = command.Parameters;
Identity identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(GridReader), param == null ? null : param.GetType(), null);
CacheInfo info = GetCacheInfo(identity);
CacheInfo info = GetCacheInfo(identity, param);
DbCommand cmd = null;
IDataReader reader = null;
......
......@@ -1696,6 +1696,7 @@ public void Add(IDbDataParameter value)
{
foreach (IDbDataParameter parameter in parameters)
command.Parameters.Add(parameter);
}
}
public void TestCustomParameters()
......@@ -2667,6 +2668,25 @@ public void TestParameterInclusionNotSensitiveToCurrentCulture()
Thread.CurrentThread.CurrentCulture = current;
}
}
public void LiteralReplacement()
{
connection.Execute("create table #literal1 (id int not null)");
connection.Execute("insert #literal1 (id) values ({=id})", new { id = 123 });
var count = connection.Query<int>("select count(1) from #literal1 where id={=foo}", new { foo = 123 }).Single();
count.IsEqualTo(1);
}
public void LiteralReplacementDynamic()
{
var args = new DynamicParameters();
args.Add("id", 123);
connection.Execute("create table #literal2 (id int not null)");
connection.Execute("insert #literal2 (id) values ({=id})", args);
args = new DynamicParameters();
args.Add("foo", 123);
var count = connection.Query<int>("select count(1) from #literal2 where id={=foo}", args).Single();
count.IsEqualTo(1);
}
public void TestProcedureWithTimeParameter()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment