提交 471902e0 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Fix for #349

上级 4231eb92
...@@ -230,15 +230,28 @@ public class PgServerThread implements Runnable { ...@@ -230,15 +230,28 @@ public class PgServerThread implements Runnable {
Prepared p = new Prepared(); Prepared p = new Prepared();
p.name = readString(); p.name = readString();
p.sql = getSQL(readString()); p.sql = getSQL(readString());
int count = readShort(); int paramTypesCount = readShort();
p.paramType = new int[count]; int[] paramTypes = null;
for (int i = 0; i < count; i++) { if (paramTypesCount > 0) {
int type = readInt(); paramTypes = new int[paramTypesCount];
server.checkType(type); for (int i = 0; i < paramTypesCount; i++) {
p.paramType[i] = type; paramTypes[i] = readInt();
}
} }
try { try {
p.prep = (JdbcPreparedStatement) conn.prepareStatement(p.sql); p.prep = (JdbcPreparedStatement) conn.prepareStatement(p.sql);
ParameterMetaData meta = p.prep.getParameterMetaData();
p.paramType = new int[meta.getParameterCount()];
for (int i = 0; i < p.paramType.length; i++) {
int type;
if (i < paramTypesCount && paramTypes[i] != 0) {
type = paramTypes[i];
server.checkType(type);
} else {
type = PgServer.convertType(meta.getParameterType(i + 1));
}
p.paramType[i] = type;
}
prepared.put(p.name, p); prepared.put(p.name, p);
sendParseComplete(); sendParseComplete();
} catch (Exception e) { } catch (Exception e) {
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
*/ */
package org.h2.test.unit; package org.h2.test.unit;
import java.math.BigDecimal;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.ParameterMetaData; import java.sql.ParameterMetaData;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -14,6 +16,7 @@ import java.sql.ResultSet; ...@@ -14,6 +16,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
...@@ -429,18 +432,25 @@ public class TestPgServer extends TestBase { ...@@ -429,18 +432,25 @@ public class TestPgServer extends TestBase {
"jdbc:postgresql://localhost:5535/test", props); "jdbc:postgresql://localhost:5535/test", props);
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
stmt.executeUpdate("create table t1 (id integer, value boolean)"); stmt.executeUpdate("create table t1 (id integer, value timestamp)");
stmt.executeUpdate("INSERT INTO t1 VALUES (1,'t')");
stmt.executeUpdate("INSERT INTO t1 VALUES (2,'f')");
stmt.close(); stmt.close();
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM t1 WHERE value = ?"); PreparedStatement pstmt = conn.prepareStatement("insert into t1 values(100500, ?)");
// assertTrue(((PGStatement) pstmt).isUseServerPrepare()); // assertTrue(((PGStatement) pstmt).isUseServerPrepare());
assertEquals(Types.TIMESTAMP, pstmt.getParameterMetaData().getParameterType(1));
pstmt.setObject(1, false, Types.OTHER); Timestamp t = new Timestamp(System.currentTimeMillis());
pstmt.setObject(1, t);
assertEquals(1, pstmt.executeUpdate());
pstmt.close();
pstmt = conn.prepareStatement("SELECT * FROM t1 WHERE value = ?");
assertEquals(Types.TIMESTAMP, pstmt.getParameterMetaData().getParameterType(1));
pstmt.setObject(1, t);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals(2, rs.getInt(1)); assertEquals(100500, rs.getInt(1));
rs.close(); rs.close();
pstmt.close(); pstmt.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论