Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to set a custom parameter prefix (instead of '@') #152

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jonataspc
Copy link

Added support for defining a custom parameter prefix (instead of the hard-coded @) for SQL query and parameters collection, separately.

Some providers have problems with @ as a default parameter prefix when used with Dapper, such as Devart dotConnect for MySQL. In that specific case, we have to use : on the SQL query instead (e.g: SELECT foo FROM table WHERE bar=:parameter). With this feature we are able to use Dapper.Contrib on those scenarios.

The configuration was implemented using delegate pattern (same way of GetDatabaseType and TableNameMapper)

Example of use:

SqlMapperExtensions.GetParameterPrefixForQuery = () => ":";
SqlMapperExtensions.GetParameterPrefixForParameterCollection = () => "@";

This PR may also solve/fix:
#14
#124
#127

Related topics:
DapperLib/Dapper#1296
DapperLib/Dapper#1232

@jonataspc jonataspc requested a review from aravindk777 January 5, 2023 22:12
Copy link

@aravindk777 aravindk777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. A much needed one. If I may also request, can the readme/documentation be updated about this feature/custom support? Let me know if i can be of any help in contributing as well. At this point, I am not sure if I have the authority to approve and the contributor process to adhere in.

@jonataspc
Copy link
Author

Looks good to me. A much needed one. If I may also request, can the readme/documentation be updated about this feature/custom support? Let me know if i can be of any help in contributing as well. At this point, I am not sure if I have the authority to approve and the contributor process to adhere in.

Sure, documentation was changed to describe the feature.

@jonataspc jonataspc requested a review from aravindk777 January 6, 2023 21:55
Readme.md Outdated Show resolved Hide resolved
Copy link

@aravindk777 aravindk777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Already shared my review feedback earlier and providing my approval after review of the file(s) that underwent the change to support this.

@aravindk777
Copy link

@jonataspc - This requires a maintainer to give the final approval to merge/approval workflows.

@Safirion
Copy link

Does it solve ODBC parameters syntax : ?paramname? ?

Or does it need a parameter suffix to be add ?

@jonataspc
Copy link
Author

Does it solve ODBC parameters syntax : ?paramname? ?

Or does it need a parameter suffix to be add ?

I think you'll need a parameter suffix to work with ODBC indeed.
This PR only adds a custom prefix param.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants