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

Provide ability to override quoter on RunnerContext #687

Closed
volkanceylan opened this issue Dec 8, 2015 · 9 comments
Closed

Provide ability to override quoter on RunnerContext #687

volkanceylan opened this issue Dec 8, 2015 · 9 comments
Labels
feature A new feature (we all like those)

Comments

@volkanceylan
Copy link

First of all, thanks for this awesome tool, it changed the way i'm thinking about database versioning, and i'm using in it my business app platform, Serenity.

Considering a table created with this simple migration:

Create.Table("Users")

If you run this migration in SQL server, it quotes with brackets, and in PostgreSQL it uses double quotes, nothing seems wrong so far.

But later, when you wanted to execute a very simple query:

SELECT * FROM Users

This works in SQL Server, but not PostgreSQL.

SELECT * FROM users

Again this works in SQL Server, but not PostgreSQL.

In PostgreSQL, if you put double quotes in tablename, while creating a table, not only it becomes case sensitive, you must also use double quotes while querying it, even if you use the exact same case. I don't want to question their reasons. They probably had a very bright idea while designing this.

But i didn't put double quotes myself, PostgreSQLQuoter did this, and i have no option to turn it off.

I just want to be able to write database-independent SQL queries (with dapper etc) at least for very simple ones, without having to quote everything.

I don't ask you to change defaults, maybe some people are depending on this feature, but please provide a way to override default quoter of the generator. I think it should be a parameter on RunnerContext. I'll subclass quoter, and assign it before running migrations.

@fubar-coder
Copy link
Member

We probably need a way to enforce quoting, but it should't be enabled by default, because this would cause problems for databases like Firebird. Maybe configuration over DI would be an option too.

@fubar-coder fubar-coder added feature A new feature (we all like those) change-required-complex labels Mar 31, 2018
@fubar-coder
Copy link
Member

With 3.0, you're able to create a new class, derived from PostgresQuoter and add it via dependency injection:

services
    .AddScoped<PostgresQuoter, YourDerivedPostgresQuoter>();

Whenever the PostgresQuoter is queries, your implementation will be used instead. You can do the same with the SqlServer2008Quoter (or 2005 or 2000).

Just override the ShouldQuote function and always return true.

@a-jamil-idware
Copy link

@fubar-coder
Can I do that for Oracle as well using "OracleQuoter" class?

@jzabroski
Copy link
Collaborator

@a-jamil-idware Yes, you can look at where PostgresQuoter is used and add similar support for an OracleQuoter. Happy to accept a PR and get it merged quickly (within one week turnaround usually).

@jzabroski
Copy link
Collaborator

Related comment: #603 (comment) explains why by default we wouldn't quote. Although, I am a bit skeptical that quoting really does force case sensitivity of variable names

@a-jamil-idware
Copy link

I understand quoting does force case sensitivity, I would have created a PR for that but I am extremely busy and I have temporarily used character escape. I think there should be a proper way for that and I have added a feature request for this Enable Quoted Identifier functionality for Oracle

@a-jamil-idware
Copy link

@jzabroski I will create a PR for the above mentioned feature request.

@IRQ0x00
Copy link

IRQ0x00 commented Oct 7, 2021

With 3.0, you're able to create a new class, derived from PostgresQuoter and add it via dependency injection:

services
    .AddScoped<PostgresQuoter, YourDerivedPostgresQuoter>();

Whenever the PostgresQuoter is queries, your implementation will be used instead. You can do the same with the SqlServer2008Quoter (or 2005 or 2000).

Just override the ShouldQuote function and always return true.

How can I inject it using other platforms and DI Containers? I'm using .NET framework 4.6.1 and Castle Windsor. Added such code:

container.Register(Component.For().ImplementedBy());

But it looks like my quoter isn't used. Queries still work only with quotes.

@jzabroski
Copy link
Collaborator

@IRQ0x00 This question is way off topic for an issue closed over a year ago. Please open a new issue and follow the issue template, ideally with some reproducible code. I can't say I will try to come up with a proof-of-concept, but at minimum it may help others to post this as a Question in the Discussions area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature (we all like those)
Projects
None yet
Development

No branches or pull requests

5 participants