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
Need "SET NAMES utf8" #395
Comments
How about: sequelize.query("SET NAMES utf8;") |
sequelize.query("SET NAMES utf8;") It is not works because this query must be executed after establish EACH new connection. But I don't know how to controll connection factory without chainging source code :( |
So far I made this ugly hack in connector-manager.js inside connect() function: var connect = function(done) {
var connection = mysql.createConnection({
host: this.config.host,
port: this.config.port,
user: this.config.username,
password: this.config.password,
database: this.config.database
})
console.log("SET NAMES utf8");
connection.query("SET NAMES utf8"); // Bad idea, but what can i do?
// client.setMaxListeners(self.maxConcurrentQueries)
this.isConnecting = false
done(null, connection)
} |
you could probably wait at least for the query to succeed :) connection.query('set names utf8').success(function() { this.isConnecting = false Sascha Depold Am Dienstag, 8. Januar 2013 um 07:39 schrieb Дубров Олег:
|
You don't need to do this (if you want UTF-8) as the mysql package takes care of setting the connection's charset, and the default is UTF8_GENERAL_CI. You can check this by running: sequelize.query("SHOW VARIABLES LIKE 'character_set_%'").success(function(data) {
console.log(data);
}); Look for these three:
Check This of course is no use to people who want to use something other than UTF-8. It'd be really useful if Sequelize could provide a method to parse a value through to the mysql package's charset option. |
@jacksleight thanks for pointing out that node-mysql already has a charset option. In that case this is already fully possible. This test sequelize/test/configuration.test.js Line 102 in cf4ab02 var sequelize = new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialectOptions: {
charset: 'something',
}
})
var config = sequelize.config |
Gotta note that I wish this were documented a little better. It's pretty common to need to insert Twitter emoji characters into a MySQL db, and it took me a while to discover this twist. Ended up being easier to actually trace it through the code. Anyhoo... I'd bet the charset option is commonly troublesome. |
@treejanitor - Docs PRs always welcome :) |
What was the solution to this problem? |
@sushantdhiman Thanks, I don't see the query get executed but "SET NAMES utf8;", but it's maybe the same as setting setting the charset. |
I'm facing the very same problem, using sequelize Using:
And then
Results in:
Doing
The output is
But
...and the new ones come back to What can I do to solve this? |
You can use sequelize.afterConnect(connection => {
return Promise.fromCallback(callback => connection.query('SET NAMES UTF8', callback);
}); |
I use mysql and I need execute "SET NAMES utf8" after connection. How can I do that?
The text was updated successfully, but these errors were encountered: