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

MySQL additional DB utf-8 issue #58

Closed
sime-k opened this issue Jan 6, 2015 · 7 comments
Closed

MySQL additional DB utf-8 issue #58

sime-k opened this issue Jan 6, 2015 · 7 comments

Comments

@sime-k
Copy link

sime-k commented Jan 6, 2015

Utf-8 works with default database but when i use additional one it returns.

Example:
config.yml

charset: "utf-8"

plugins:
    Database:
      driver: 'mysql'
      database: 'data'
      host: 'localhost'
      username: 'user'
      password: 'pass'
      connections:
        stats:
              driver: 'mysql'
              database: 'data'
              host: 'localhost'
              username: 'user'
              password: 'pass'    

data: {NAME=>ščćđ}

Dancer

    my $test = database->quick_select('RECORDINGS', {ID=>'174309663'});
    return to_json $test;
        # returns {NAME=>ščćđ}

    my $test = database('stats')->quick_select('RECORDINGS', {ID=>'174309663'});
    return to_json $test;
        # returns {NAME=>????}

@gregapompe
Copy link

For some reason named connections don't get charset from settings. So an elegant workaround is to add charset: utf-8 to connection. In your case:

charset: "utf-8"

plugins:
    Database:
      driver: 'mysql'
      database: 'data'
      host: 'localhost'
      username: 'user'
      password: 'pass'
      connections:
        stats:
              driver: 'mysql'
              database: 'data'
              host: 'localhost'
              username: 'user'
              password: 'pass' 
              charset: "utf-8"

@sime-k
Copy link
Author

sime-k commented Jan 7, 2015

Thanks! 👍

@sime-k sime-k closed this as completed Jan 7, 2015
@bigpresh
Copy link
Owner

bigpresh commented Jan 7, 2015

Hmm - whilst you can, indeed, pass the charset parameter in each named connection, it doesn't seem reasonable behaviour for it to be automatically enabled for the "main" connection, but not for named connections - that's bound to surprise others - so I'm going to re-open this as still being a bug that ought to be fixed.

@bigpresh bigpresh reopened this Jan 7, 2015
@ambs
Copy link
Collaborator

ambs commented Jan 7, 2015

Indeed. I tested locally and I did not have any problem. So, I would really like to see this reproduced so we can fix the issue.

@esyphelon
Copy link

Oops: Ignore this, I did not set up the table properly.

As another interesting note: This is what I get from the mysql command-line client when I query a table with the example string.

Note: I inserted the string twice, once with the client set to UTF8 and once without.

mysql> insert into test (name) values ('ščćđ')
mysql> select * from test;
+-------+
| name |
+-------+
| š??? |
| š??? |
+-------+

@esyphelon
Copy link

Just FYI. Submitted PR #59 which handles charset inheritance of named connections.

@ambs
Copy link
Collaborator

ambs commented May 14, 2015

I think this is solved, so closing issue. Please let me know if not. Best,

@ambs ambs closed this as completed May 14, 2015
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

No branches or pull requests

5 participants