emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

'script_char_set' is applied incorrectly for migration scripts #49

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
Migration 3.0.1

Please describe the problem.  Unit tests are best!

Currently, 'script_char_set' is applied in ScriptRunner#executeStatement() 
method with the following line, but it doesn't work as intended.

new String(command.getBytes(), characterSetName);

The character set must be specified when reading the file.
In BootstrapCommand, for example, ScriptRunner#runScript() is currently called 
as follows:

runner.runScript(new MigrationReader(new FileReader(bootstrap), false, 
environmentProperties()));

but it should be something like:

runner.runScript(
  new MigrationReader(
    new InputStreamReader(
      new FileInputStream(bootstrap),
      environmentProperties().getProperty("script_char_set")
    ), 
    false, environmentProperties()
  )
);

The same goes for other commands as well.

Original issue reported on code.google.com by haraw...@gmail.com on 18 Jun 2010 at 8:51

GoogleCodeExporter commented 9 years ago
And I prefer 'utf-8' to be the default rather than the platform's default 
encoding when 'script_char_set' is not specified explicitly.

Original comment by haraw...@gmail.com on 18 Jun 2010 at 9:30

GoogleCodeExporter commented 9 years ago
Attached a patch against trunk revision 2390.

Original comment by haraw...@gmail.com on 25 Aug 2010 at 3:54

Attachments:

GoogleCodeExporter commented 9 years ago
By the way, this is not a simple cosmetic change. Without this fix, migration 
scripts containing data in languages such as Chinese do not work and renders 
the migration tool useless in such context.

Please up the priority of this fix.

Original comment by abde.sa...@gmail.com on 26 Apr 2011 at 5:18

GoogleCodeExporter commented 9 years ago
Attached a new patch against r3830.
I had to modify two existing test cases this time, but I believe the change was 
reasonable.
And with this version, the default charset is used when 'script_char_set' is 
not specified.

Thanks,
Iwao

Original comment by haraw...@gmail.com on 11 Jul 2011 at 5:28

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for keeping this updated Iwao. 

This is indeed an encoding bug, once the File is opened with the wrong charset 
it is too late to fix it with new String(byte[], encoding)

I think it is better not to use utf-8 by default to avoid backwards 
compatibility problems.

Fixed in r3836

Original comment by eduardo.macarron on 29 Jul 2011 at 5:46

GoogleCodeExporter commented 9 years ago
Eduardo, Thank you for committing the patch!

Original comment by haraw...@gmail.com on 31 Jul 2011 at 5:15

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 4 Apr 2012 at 10:36