提交 3b67839d authored 作者: Thomas Mueller's avatar Thomas Mueller

Trying to create a view with parameters in the query will now throw an exception.

上级 c2e881d0
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>New experimental feature SHUTDOWN DEFRAG.
<ul><li>Trying to create a view with parameters in the query will now throw an exception.
So far, creating the view was allowed, but the parameter value was not used (null was used instead).
</li><li>New experimental feature SHUTDOWN DEFRAG.
This option re-orders the pages while closing the database so that table scans are faster.
</li><li>When using the MULTI_THREADED option, concurrently reading from a database
(specially from a larger database, or when using a small cache size) could throw an exception.
......
......@@ -13,7 +13,9 @@ import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.expression.Parameter;
import org.h2.message.DbException;
import org.h2.message.TraceObject;
import org.h2.schema.Schema;
import org.h2.table.Table;
import org.h2.table.TableView;
......@@ -89,7 +91,6 @@ public class CreateView extends SchemaCommand {
if (ifNotExists) {
return 0;
}
if (orReplace && existingView.getTableType().equals(Table.VIEW)) {
db.renameSchemaObject(session, existingView, db.getTempTableName(session));
loadDependentViewSql(existingView, dependentViewSql);
......@@ -102,7 +103,11 @@ public class CreateView extends SchemaCommand {
if (select == null) {
querySQL = selectSQL;
} else {
querySQL = select.getSQL();
ArrayList<Parameter> params = select.getParameters();
if (params != null && params.size() > 0) {
throw DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1, "parameters in views");
}
querySQL = TraceObject.toString(select.getSQL(), select.getParameters());
}
Session sysSession = db.getSystemSession();
TableView view;
......@@ -120,7 +125,6 @@ public class CreateView extends SchemaCommand {
// this is not strictly required - ignore exceptions, specially when using FORCE
}
db.addSchemaObject(session, view);
if (existingView != null) {
recreateDependentViews(db, existingView, dependentViewSql, view);
}
......
......@@ -30,6 +30,7 @@ public class TestView extends TestBase {
}
public void test() throws SQLException {
testParameterizedView();
testCache();
testCacheFunction(true);
testCacheFunction(false);
......@@ -39,6 +40,33 @@ public class TestView extends TestBase {
deleteDb("view");
}
private void testParameterizedView() throws SQLException {
deleteDb("view");
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Test(id INT AUTO_INCREMENT NOT NULL, f1 VARCHAR NOT NULL, f2 VARCHAR NOT NULL)");
stat.execute("INSERT INTO Test(f1, f2) VALUES ('value1','value2')");
stat.execute("INSERT INTO Test(f1, f2) VALUES ('value1','value3')");
PreparedStatement ps = conn.prepareStatement("CREATE VIEW Test_View AS SELECT f2 FROM Test WHERE f1=?");
ps.setString(1, "value1");
try {
ps.executeUpdate();
fail();
} catch (SQLException e) {
assertKnownException(e);
}
// ResultSet rs;
// rs = stat.executeQuery("SELECT * FROM Test_View");
// assertTrue(rs.next());
// assertFalse(rs.next());
// rs = stat.executeQuery("select VIEW_DEFINITION " +
// "from information_schema.views " +
// "where TABLE_NAME='TEST_VIEW'");
// rs.next();
// assertEquals("...", rs.getString(1));
conn.close();
}
private void testCacheFunction(boolean deterministic) throws SQLException {
deleteDb("view");
Connection conn = getConnection("view");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论