提交 2afa260c authored 作者: Thomas Mueller's avatar Thomas Mueller

PreparedStatement.setObject now converts a java.lang.Character to a string.

上级 7b4862d8
...@@ -882,6 +882,8 @@ public class DataType { ...@@ -882,6 +882,8 @@ public class DataType {
v[i] = convertToValue(session, o[i], type); v[i] = convertToValue(session, o[i], type);
} }
return ValueArray.get(v); return ValueArray.get(v);
} else if (x instanceof Character) {
return ValueStringFixed.get(((Character) x).toString());
} else { } else {
return ValueJavaObject.getNoCopy(ObjectUtils.serialize(x)); return ValueJavaObject.getNoCopy(ObjectUtils.serialize(x));
} }
......
...@@ -332,8 +332,13 @@ public class TestPreparedStatement extends TestBase { ...@@ -332,8 +332,13 @@ public class TestPreparedStatement extends TestBase {
private void testSetObject(Connection conn) throws SQLException { private void testSetObject(Connection conn) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(C CHAR(1))");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?)");
prep.setObject(1, 'x');
prep.execute();
stat.execute("DROP TABLE TEST");
stat.execute("CREATE TABLE TEST(ID INT, DATA BINARY, JAVA OTHER)"); stat.execute("CREATE TABLE TEST(ID INT, DATA BINARY, JAVA OTHER)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)"); prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");
prep.setInt(1, 1); prep.setInt(1, 1);
prep.setObject(2, new Integer(11)); prep.setObject(2, new Integer(11));
prep.setObject(3, null); prep.setObject(3, null);
...@@ -720,7 +725,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -720,7 +725,7 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(12, java.sql.Timestamp.valueOf("2001-02-03 04:05:06.123456789")); prep.setObject(12, java.sql.Timestamp.valueOf("2001-02-03 04:05:06.123456789"));
prep.setObject(13, new java.util.Date(java.sql.Date.valueOf("2001-02-03").getTime())); prep.setObject(13, new java.util.Date(java.sql.Date.valueOf("2001-02-03").getTime()));
prep.setObject(14, new byte[] { 10, 20, 30 }); prep.setObject(14, new byte[] { 10, 20, 30 });
prep.setObject(15, new Character('a')); prep.setObject(15, new Character('a'), Types.OTHER);
prep.setObject(16, "2001-01-02", Types.DATE); prep.setObject(16, "2001-01-02", Types.DATE);
// converting to null seems strange... // converting to null seems strange...
prep.setObject(17, "2001-01-02", Types.NULL); prep.setObject(17, "2001-01-02", Types.NULL);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论