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

Session Initialization SQL for Shared Hosting #519

Closed
caleblloyd opened this issue Jun 15, 2018 · 2 comments
Closed

Session Initialization SQL for Shared Hosting #519

caleblloyd opened this issue Jun 15, 2018 · 2 comments

Comments

@caleblloyd
Copy link
Contributor

caleblloyd commented Jun 15, 2018

A user of a shared hosting MySQL service may wish to set default values in their session that are different than the default values of the server. A shared hosting user permission level typically will only allow them to run a SET @@session command, which must be run on every session

MySqlConnector could support this by adding either:

  1. A Connection String option with Session variables to set
    a. If the option was a string of SQL, putting SET @@session.sql_mode = 'TRADITIONAL in the string would look odd and we'd need to come up with an easy way to escape the string
    b. Creating an option for every @@session variable in the connection string would be quite work intensive
  2. A helper utility function that allows the user to associate a SQL Initialization String with a Connection String
    a. This would look something like SessionInitUtil.setSessionInitSql(connectionString, "SET @@session.sql_mode = 'TRADITIONAL")
    b. This seems cleaner than putting it in the connection string, but still feels kind of hacky

The initialization code could go right after the session is created:

m_session = await CreateSessionAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

@bgrainger
Copy link
Member

If ADO.NET exposed a connection pooling API (dotnet/corefx#26714), setting a property on the pool could be a natural to specify this information. For now, it seems like the connection string would have to be used, since that's the only piece of information passed to MySqlConnection.

we'd need to come up with an easy way to escape the string

This should be done by using a property on MySqlConnectionStringBuilder (same issue for escaping special characters in passwords).

@bgrainger
Copy link
Member

There is a good suggestion in this SO answer: add an event handler to Connection.StateChange to execute the command when e.CurrentState == ConnectionState.Open. (This will be called right after the line of code @caleblloyd identified, so the effect will be the same as if MySqlConnector handled it directly.)

I think this can be solved adequately in user code and doesn't need to be part of this library.

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

No branches or pull requests

2 participants