Skip to content

Commit

Permalink
0001806: dbfill only inserts 1 char for char fields. It should respec…
Browse files Browse the repository at this point in the history
…t the size of the char field
  • Loading branch information
chenson42 committed Jul 13, 2014
1 parent d8fac50 commit 72dc8bf
Showing 1 changed file with 9 additions and 7 deletions.
Expand Up @@ -570,12 +570,10 @@ private Object generateRandomValueForColumn(Column column) {
objectValue = DateUtils.truncate(randomDate(), Calendar.DATE);
} else if (type == Types.TIMESTAMP || type == Types.TIME) {
objectValue = randomTimestamp();
} else if (type == Types.CHAR) {
objectValue = randomChar().toString();
} else if (type == Types.INTEGER || type == Types.BIGINT) {
objectValue = randomInt();
} else if (type == Types.SMALLINT) {
objectValue = randomSmallInt();
objectValue = randomSmallInt(column.getJdbcTypeName().toLowerCase().contains("unsigned"));
} else if (type == Types.FLOAT) {
objectValue = randomFloat();
} else if (type == Types.DOUBLE) {
Expand All @@ -594,7 +592,7 @@ private Object generateRandomValueForColumn(Column column) {
objectValue = randomBytes();
} else if (type == Types.ARRAY) {
objectValue = null;
} else if (type == Types.VARCHAR || type == Types.LONGVARCHAR) {
} else if (type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.CHAR) {
int size = 0;
// Assume if the size is 0 there is no max size configured.
if (column.getSizeAsInt() != 0) {
Expand All @@ -612,9 +610,13 @@ private Object generateRandomValueForColumn(Column column) {
return objectValue;
}

private Object randomSmallInt() {
// TINYINT (-32768 32767)
return new Integer(getRand().nextInt(65535) - 32768);
private Object randomSmallInt(boolean unsigned) {
if (unsigned) {
return new Integer(getRand().nextInt(32768));
} else {
// TINYINT (-32768 32767)
return new Integer(getRand().nextInt(65535) - 32768);
}
}

private Object randomFloat() {
Expand Down

0 comments on commit 72dc8bf

Please sign in to comment.