Is there a way to set the sql_mode (for MySql database) in Hibernate properties or in connection string?
Thanks,
Stefano
Yes, as documented sessionVariables property which is defined as follows can be used in JDBC connection string:
A comma-separated list of name/value pairs to be sent as SET SESSION
... to the server when the driver connects.
List of values goes inside single quotes:
sessionVariables=sql_mode='ALLOW_INVALID_DATES,NO_BACKSLASH_ESCAPES'
Related
I need to add 2 session variables in JDBC connection string.
sessionVariables=FOREIGN_KEY_CHECKS=0&sessionVariables=SQL_SAFE_UPDATES=0
The second one is overwriting the first variable. Is there any option in JDBC connection to add 2 session variables?
We can pass this as comma separated like sessionVariables=group_concat_max_len=204800,time_zone='-00:00'
The following SQL runs as expected in the workbench, but generates an error "parameter #search must be defined" when I fire it in from a C# application. Can anyone explain this?
set #search = 'b%';
select * from country where Name like #search
MySQL use the #variable_name expression as a user defined variable. C# (or the provider - not really sure which) on the other hand uses the #parameter_name to annotate parameter placeholder in the query.
If you want to use sql user defined variables, then add the following parameter to the connection string of your .Net connector connection:
Allow User Variables=True
or
AllowUserVariables=True
This option was added to connector v5.2.2
I'm using Entity Framework 5, MySQL 5.6 and MySQLConnector 6.6.5.
I would like to set up the FOUND_ROWS flag in my Entity Framework connection string.
I tried the following configuration.
...
server=localhost;user id=root;option=2
..
According to the MySQL documentation the value '2' equals FOUND_ROWS parameter.
But it throws an InvalidOperationException saying that the Keyword is not supported (name parameter : option).
How am I supposed to do?
try
UseAffectedRows=false
reference.
UseAffectedRows
When true, the connection reports changed rows instead of found rows.
This option was added in Connector/Net version 5.2.6.
I'm trying to optimize for bulk inserts via play(1.2.4)+mysql.
I saw some posts talking about adding the following to jdbc configuration (adding it to the connection string): useServerPrepStmts=false&rewriteBatchedStatements=true&useCompression=true
I've tried to do:
db=mysql://root#localhost/data?useServerPrepStmts=false&rewriteBatchedStatements=true&useCompression=true
But I get this error:
A database error occured : Cannot connected to the database, The connection property 'useCompression' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true?useUnicode=yes' is not in this set.
I also tried to use db=jdbc:mysql://....
Still no luck.
What am I missing?
Play automatically appends the MySQL connection string with the following:
?useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci
So I am guessing your connection string ends up invalid as there is now two sets of parameters (starting with a question mark).
Unfortunately, that part of Play code is quite hard-coded in the DBPlugin class which means that you can't add the options that way. You will have to look for a way to alter the options in a later stage.
Is it possible to set connection collation within MySql connection string and how, since there's a default setting on the server that's used for new connections.
Two things I can't do:
Can't call SET COLLATION_CONNECTION after I open a connection, because I'm using Entity Framework that does all the calls for me not entirely true as you may see in the edit
Can't change server default connection collation because of other databases and their respected applications that use them.
All I'd like to specify is a certain connection string parameter in my web.config file like:
"User id=dbuser;Password=dbpass;Host=dbserver;Database=testung;Collation=utf8_general_ci"
but Collation setting/variable isn't recognised.
Technologies used
Asp.net MVC 2
IIS 7
Entity Framework 1
DevArt dotConnect MySql connector
MySql 5.1
EDIT 1
I've tried this code as #Devart suggested but to no avail:
partial void OnContextCreated()
{
System.Data.Common.DbCommand command = this.Connection.CreateCommand();
command.CommandText = "set collation_connection = utf8_slovenian_ci;";
command.CommandType = System.Data.CommandType.Text;
this.Connection.Open();
command.ExecuteNonQuery();
// this.Connection.Close();
}
We recommend you to implement the OnContextCreated partial method.
You have access to the store connection in it and you can execute ADO.NET command "SET COLLATION = ..." using this connection.
If anyone else stumbles over this problem or wants to issue a command when opening a connection: The answer regarding OnContextCreated does no longer work as the method does no longer exist/is no longer supported.
An alternative, which I use for executing SET NAMES <character set used by the database> is to append ;initialization command=\"SET NAMES '" + CharSet + "';\" to your connection string. According to Devart's documentation this also works for PostgreSQL, MSSQL and Oracle
This property can also be set inside EntityDeveloper when accessing the properties of the database connection and clicking on the Advanced button.