提交 42bb1fe7 authored 作者: fred's avatar fred

*Test case for the issue #543

上级 96a75797
......@@ -6,6 +6,7 @@
package org.h2.test.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
......@@ -45,6 +46,7 @@ public class TestStatement extends TestBase {
testSavepoint();
testConnectionRollback();
testStatement();
testPreparedStatement();
testIdentityMerge();
testIdentity();
conn.close();
......@@ -395,5 +397,37 @@ public class TestStatement extends TestBase {
stat.execute("DROP TABLE TEST");
stat.execute("DROP TABLE TEST2");
}
private void testPreparedStatement() throws SQLException{
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar(255))");
stat.execute("insert into test values(1, 'Hello')");
stat.execute("insert into test values(2, 'World')");
PreparedStatement ps = conn.prepareStatement("select name from test where id in (select id from test where name REGEXP ?)");
ps.setString(1, "Hello");
ResultSet rs = ps.executeQuery();
assertTrue(rs.next());
assertEquals("Hello", rs.getString("name"));
assertFalse(rs.next());
ps.setString(1, "World");
rs = ps.executeQuery();
assertTrue(rs.next());
assertEquals("World", rs.getString("name"));
assertFalse(rs.next());
//Change the table difinition
stat.execute("create index t_id on test(name)");
//Test the prepared statement again
ps.setString(1, "Hello");
rs = ps.executeQuery();
assertTrue(rs.next());
assertEquals("Hello", rs.getString("name"));
assertFalse(rs.next());
ps.setString(1, "World");
rs = ps.executeQuery();
assertTrue(rs.next());
assertEquals("World", rs.getString("name"));
assertFalse(rs.next());
stat.execute("drop table test");
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论