提交 bd1bc289 authored 作者: Thomas Mueller's avatar Thomas Mueller

Prepared statements could only be re-used if the same data types were used the…

Prepared statements could only be re-used if the same data types were used the second time they were executed.
上级 4f5f82e7
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>In error messages about referential constraint violation, the values are now included. <ul><li>Prepared statements could only be re-used if the same data types were used
the second time they were executed.
</li><li>In error messages about referential constraint violation, the values are now included.
</li><li>SCRIPT and RUNSCRIPT: the password can now be set using a prepared statement. </li><li>SCRIPT and RUNSCRIPT: the password can now be set using a prepared statement.
Previously, it was required to be a literal in the SQL statement. Previously, it was required to be a literal in the SQL statement.
</li><li>MySQL compatibility: SUBSTR with a negative start index now works like MySQL. </li><li>MySQL compatibility: SUBSTR with a negative start index now works like MySQL.
...@@ -40,6 +42,8 @@ Change Log ...@@ -40,6 +42,8 @@ Change Log
</li><li>Issue 362: support LIMIT in UPDATE statements. </li><li>Issue 362: support LIMIT in UPDATE statements.
</li><li>Browser: if no default browser is set, Google Chrome is now used if available. </li><li>Browser: if no default browser is set, Google Chrome is now used if available.
If not available, then Konqueror, Netscape, or Opera is used if available (as before). If not available, then Konqueror, Netscape, or Opera is used if available (as before).
</li><li>CSV tool: new feature to disable writing the column header
(option writeColumnHeader).
</li><li>CSV tool: new feature to preserve the case sensitivity of column names </li><li>CSV tool: new feature to preserve the case sensitivity of column names
(option caseSensitiveColumnNames). (option caseSensitiveColumnNames).
</li><li>PostgreSQL compatibility: LOG(x) is base 10 in the PostgreSQL mode. </li><li>PostgreSQL compatibility: LOG(x) is base 10 in the PostgreSQL mode.
......
...@@ -236,7 +236,8 @@ public abstract class Query extends Prepared { ...@@ -236,7 +236,8 @@ public abstract class Query extends Prepared {
} }
Database db = s.getDatabase(); Database db = s.getDatabase();
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
if (!db.areEqual(lastParams[i], params[i])) { Value a = lastParams[i], b = params[i];
if (a.getType() != b.getType() || !db.areEqual(a, b)) {
return false; return false;
} }
} }
......
...@@ -51,6 +51,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -51,6 +51,7 @@ public class TestPreparedStatement extends TestBase {
public void test() throws Exception { public void test() throws Exception {
deleteDb("preparedStatement"); deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement"); Connection conn = getConnection("preparedStatement");
testChangeType(conn);
testDateTimeTimestampWithCalendar(conn); testDateTimeTimestampWithCalendar(conn);
testCallTablePrepared(conn); testCallTablePrepared(conn);
testValues(conn); testValues(conn);
...@@ -89,6 +90,18 @@ public class TestPreparedStatement extends TestBase { ...@@ -89,6 +90,18 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement"); deleteDb("preparedStatement");
} }
private void testChangeType(Connection conn) throws SQLException {
PreparedStatement prep = conn.prepareStatement("select (? || ? || ?) from dual");
prep.setString(1, "a");
prep.setString(2, "b");
prep.setString(3, "c");
prep.executeQuery();
prep.setInt(1, 1);
prep.setString(2, "ab");
prep.setInt(3, 45);
prep.executeQuery();
}
private void testDateTimeTimestampWithCalendar(Connection conn) throws SQLException { private void testDateTimeTimestampWithCalendar(Connection conn) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table ts(x timestamp primary key)"); stat.execute("create table ts(x timestamp primary key)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论