OPENJPA-2242 - Extends procedure call parameter String cast length if value length is greater than the default length

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1371268 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Albert Lee 2012-08-09 16:01:30 +00:00
parent 9ebe6c7ca5
commit 17ecb7a338

View File

@ -219,7 +219,7 @@ public class DB2Dictionary
// if the literal is a string, use the default char col size
// in the cast statement.
if (String.class.equals(c))
selectSQL.append("(" + characterColumnSize + ")");
selectSQL.append("(" + getCastStringColumnSize(val) + ")");
selectSQL.append(")");
}
@ -799,7 +799,7 @@ public class DB2Dictionary
String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val
.getType()), false));
if (String.class.equals(val.getType()))
type = type + "(" + characterColumnSize + ")";
type = type + "(" + getCastStringColumnSize(val) + ")";
fstring = "CAST(? AS " + type + ")";
return fstring;
}
@ -927,7 +927,7 @@ public class DB2Dictionary
// case "(?" - convert to "CAST(? AS type"
String typeName = getTypeName(type);
if (String.class.equals(val.getType()))
typeName = typeName + "(" + characterColumnSize + ")";
typeName = typeName + "(" + getCastStringColumnSize(val) + ")";
String str = "CAST(? AS " + typeName + ")";
buf.replaceSqlString(sqlString.length() - 1,
sqlString.length(), str);
@ -1076,6 +1076,20 @@ public class DB2Dictionary
}
}
private int getCastStringColumnSize(Object val) {
int colSize = characterColumnSize;
if (val instanceof Lit) {
String literal = (String) ((Lit) val).getValue();
if (literal != null) {
int literalLen = literal.length();
if (literalLen > characterColumnSize) {
colSize = literalLen;
}
}
}
return colSize;
}
@Override
public void insertBlobForStreamingLoad(Row row, Column col,
JDBCStore store, Object ob, Select sel) throws SQLException {