Bug #12897 CHAR and NCHAR shuld use CHAR_LENGTH to get column length
Submitted: 31 Aug 2005 5:47 Modified: 18 Oct 2005 18:55
Reporter: Sadao Hiratsuka (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Migration Toolkit Severity:S3 (Non-critical)
Version:1.0.15 OS:Windows (WindowsXP)
Assigned to: CPU Architecture:Any

[31 Aug 2005 5:47] Sadao Hiratsuka
Description:
CHAR and NCHAR shuld use CHAR_LENGTH to get column length
instead of DATA_LENGTH.

How to repeat:
I tested with
Migration Toolkit 1.0.15 (WindowsXP),
Oracle 9.2.0.6 (Linux) JA16SJISTILDE (1 to 2bytes character set),
and MySQL 5.0.10 (Linux) CP932.

-- Oracle
create table test003_nchar
(col1 nchar(1), -- means char length = 1 and byte length = 2
 col2 nchar(127),
 col3 nchar(128),
 col4 nchar(255),
 col5 nchar(256),
 col6 nchar(1000))
/

create table test004_nvarchar2
(col1 nvarchar2(1),
 col2 nvarchar2(127),
 col3 nvarchar2(128),
 col4 nvarchar2(255),
 col5 nvarchar2(256),
 col6 nvarchar2(2000))
/

-- MySQL
CREATE TABLE `mi`.`test003_nchar` (
  `col1` CHAR(2) NULL,
  `col2` CHAR(254) NULL,
  `col3` LONGTEXT NULL,
  `col4` LONGTEXT NULL,
  `col5` LONGTEXT NULL,
  `col6` LONGTEXT NULL
)
ENGINE = INNODB;

CREATE TABLE `mi`.`test004_nvarchar2` (
  `col1` VARCHAR(1) NULL,
  `col2` VARCHAR(127) NULL,
  `col3` VARCHAR(128) NULL,
  `col4` VARCHAR(255) NULL,
  `col5` VARCHAR(256) NULL,
  `col6` VARCHAR(2000) NULL
)
ENGINE = INNODB;

Suggested fix:
test003_nchar shuld be this.

CREATE TABLE `mi`.`test003_nchar` (
  `col1` CHAR(1) NULL,
  `col2` CHAR(127) NULL,
  `col3` CHAR(128) NULL,
  `col4` CHAR(255) NULL,
  `col5` LONGTEXT NULL,
  `col6` LONGTEXT NULL
)
ENGINE = INNODB;

I think that CHAR and NCHAR entries shuld be added to following routine.
-> protected void reverseEngineerTableColumns

if (column.getDatatypeName().equalsIgnoreCase("VARCHAR2")
		|| column.getDatatypeName().equalsIgnoreCase(
				"NVARCHAR2")
		|| column.getDatatypeName().equalsIgnoreCase("LONG")) {
	try {
		// in Oracle 9i there is CHAR_LENGTH
		column.setLength(colRset.getInt("CHAR_LENGTH"));
	} catch (Exception e) {
		column.setLength(colRset.getInt("DATA_LENGTH"));
	}
} else
	column.setLength(colRset.getInt("DATA_LENGTH"));
[31 Aug 2005 6:35] Jorge del Conde
Thanks for your bug report.

I was able to reporduce this using MT 1.0.15 and the attached queries.
[18 Oct 2005 18:55] Michael G. Zinner
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html