Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

"param11" replace "param1"

Open LIHualiPlus opened this issue 3 years ago • 5 comments

sql :“Select Id from table where Id in @Param1 ” parameters: {param1:"param1",param11:"param11"}

使用query方法和以上两个参数 得到的结果却是 Select Id from table1 where Id in param11 ,很奇怪 本该使用param1 作为参数却变成了param11 image

LIHualiPlus avatar Mar 31 '22 00:03 LIHualiPlus

var db = _databaseLocator.GetArchiveDatabase();
var sql = "Select Id from tb_documentcoderule where Id in @Param1";
var sql2 = $"select * from information_schema.PROCESSLIST where DB = 'accenter'and  info is not null and NOT EXISTS({sql}) ";
var json = "{\"Param1\":[\"Param1\"],\"Param11\":[\"Param11\"]}";
object parameters = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(json);

var res = await db.QueryAsync(sql, new DynamicParameters(parameters));
var res2 = await db.QueryAsync(sql2, new DynamicParameters(parameters),null,null,commandType: System.Data.CommandType.Text);
var dic =JsonConvert.DeserializeObject<Dictionary<string,dynamic>>(JsonConvert.SerializeObject(res2.First()));
Console.WriteLine(dic["INFO"]);

LIHualiPlus avatar Mar 31 '22 00:03 LIHualiPlus

Interesting. Yes, I think I can understand what is happening here; question: did this actually execute the wrong thing? Or did the SQL just look unexpected? i.e. what value was passed as param11?

I would expect this to either fail outright (duplicate param key), or work correctly, but look unexpected. If it works and passes the wrong value, that's a much bigger issue.

mgravell avatar Mar 31 '22 06:03 mgravell

I think from the image you're saying the wrong value was passed, is that correct?

mgravell avatar Mar 31 '22 06:03 mgravell

the SQL look unexpected ,I expectparam1 but got param11

LIHualiPlus avatar Mar 31 '22 06:03 LIHualiPlus

After my test, "*1" always mistakenly replaces " * "

LIHualiPlus avatar Mar 31 '22 06:03 LIHualiPlus