Repository: empire-db Updated Branches: refs/heads/master 6e14aae47 -> 9a45804ce
EMPIREDB-251 Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/9a45804c Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/9a45804c Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/9a45804c Branch: refs/heads/master Commit: 9a45804cefb27c7628451532c1514d51d622da2f Parents: 6e14aae Author: Jan Glaubitz <j...@glaubitz.org> Authored: Thu Dec 1 13:58:11 2016 +0100 Committer: Jan Glaubitz <j...@glaubitz.org> Committed: Thu Dec 1 13:58:11 2016 +0100 ---------------------------------------------------------------------- .../empire/db/mysql/MySQLDDLGenerator.java | 35 +++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/empire-db/blob/9a45804c/empire-db/src/main/java/org/apache/empire/db/mysql/MySQLDDLGenerator.java ---------------------------------------------------------------------- diff --git a/empire-db/src/main/java/org/apache/empire/db/mysql/MySQLDDLGenerator.java b/empire-db/src/main/java/org/apache/empire/db/mysql/MySQLDDLGenerator.java index 236923c..b62d877 100644 --- a/empire-db/src/main/java/org/apache/empire/db/mysql/MySQLDDLGenerator.java +++ b/empire-db/src/main/java/org/apache/empire/db/mysql/MySQLDDLGenerator.java @@ -42,6 +42,10 @@ public class MySQLDDLGenerator extends DBDDLGenerator<DBDatabaseDriverMySQL> { private static final Logger log = LoggerFactory.getLogger(MySQLDDLGenerator.class); + // Data types + protected String DATATYPE_INT_TINY = "TINYINT"; // Integer with really small size (1 byte) + protected String DATATYPE_INT_MEDIUM = "MEDIUMINT"; // Integer with really medium size (3 byte) + public MySQLDDLGenerator(DBDatabaseDriverMySQL driver) { super(driver); @@ -72,7 +76,36 @@ public class MySQLDDLGenerator extends DBDDLGenerator<DBDatabaseDriverMySQL> if (driver.isUseSequenceTable()==false) sql.append(" AUTO_INCREMENT"); break; - } + } + case INTEGER: + { + int bytes = Math.abs((int) size); + if (bytes > 0 && bytes <= 1) + { + sql.append(DATATYPE_INT_TINY); + } + else if (bytes > 0 && bytes <= 2) + { + sql.append(DATATYPE_INT_SMALL); + } + else if (bytes > 0 && bytes <= 3) + { + sql.append(DATATYPE_INT_MEDIUM); + } + else if (bytes > 0 && bytes <= 4) + { + sql.append(DATATYPE_INTEGER); + } + else if (bytes > 0 && bytes <= 8) + { + sql.append(DATATYPE_INT_BIG); + } + else + { // Default + sql.append(DATATYPE_INTEGER); // Default integer length + } + break; + } default: // use default return super.appendColumnDataType(type, size, c, sql);