提交 e0c13513 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #547 from zepfred/master

Fix for Issue #543
...@@ -2211,6 +2211,7 @@ public class Parser { ...@@ -2211,6 +2211,7 @@ public class Parser {
r = new CompareLike(database, r, b, esc, false); r = new CompareLike(database, r, b, esc, false);
} else if (readIf("REGEXP")) { } else if (readIf("REGEXP")) {
Expression b = readConcat(); Expression b = readConcat();
recompileAlways = true;
r = new CompareLike(database, r, b, null, true); r = new CompareLike(database, r, b, null, true);
} else if (readIf("IS")) { } else if (readIf("IS")) {
if (readIf("NOT")) { if (readIf("NOT")) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package org.h2.test.jdbc; package org.h2.test.jdbc;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Savepoint; import java.sql.Savepoint;
...@@ -45,6 +46,7 @@ public class TestStatement extends TestBase { ...@@ -45,6 +46,7 @@ public class TestStatement extends TestBase {
testSavepoint(); testSavepoint();
testConnectionRollback(); testConnectionRollback();
testStatement(); testStatement();
testPreparedStatement();
testIdentityMerge(); testIdentityMerge();
testIdentity(); testIdentity();
conn.close(); conn.close();
...@@ -395,5 +397,37 @@ public class TestStatement extends TestBase { ...@@ -395,5 +397,37 @@ public class TestStatement extends TestBase {
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
stat.execute("DROP TABLE TEST2"); 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());
//Changes the table structure
stat.execute("create index t_id on test(name)");
//Test the prepared statement again to check if the internal cache attributes were reset
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论