Closed yamac closed 1 year ago
From reading the XML file and loading the Satement,
It can be seen that the final SQL statement uses DbProvider.ParameterPrefix
to replace SmartSqlConfig.Settings.ParameterPrefix
.In your example, ?
Replaced $
.
However, this part is missing when loading Satement from StatementAttribute
.
https://github.com/dotnetcore/SmartSql/blob/d3df83b1a06f8ee1f047060bcd55f138216eeacd/src/SmartSql.DyRepository/EmitRepositoryBuilder.cs#L317-L329
Fixed in 4.1.65
SmartSql version
4.1.64
Database provider and version
DbProvider = "MySql" MySql.Data: 8.0.31 MySql Server: 8.0.21
Steps to reproduce
I've searched the documentation but couldn't find if this is the spec or not.
Prepare a SmartSqlMapConfig.xml. Set ParameterPrefix to
$
in Settings tag.SmartSqlMapConfig.xml
Prepare the following two interface methods. The first one applies Sql from Xml, The next one applies Sql from StatementAttribute's Sql parameter.
Prepare Mapper.
Item.xml
Executes two methods.
FindByIdWithXml succeeds. I defined the placeholder as
$id
on the Xml because I set the Settings.ParameterPrefix to$
.But FindByIdWithAttribute fails with error message "Unknown column '$id' in 'where clause'". It seems that Settings.ParameterPrefix is not affected in method using StatementAttribute.
I'm not sure if this is the spec or not.
Expected result
FindByIdWithXml and FindByIdWithAttribute behave the same.
Actual result
FindByIdWithXml succeeds. But FindByIdWithAttribute fails with error message "Unknown column '$id' in 'where clause'".
It works if change the placeholder from
$id
to?id
like below.Stack trace