提交 6c4afa7b authored 作者: noelgrandin's avatar noelgrandin

Add syntax for passing additional parameters into custom TableEngine implementations

上级 eb6934d0
......@@ -580,7 +580,8 @@ CREATE SEQUENCE SEQ_ID
CREATE [ CACHED | MEMORY ] [ TEMP | [ GLOBAL | LOCAL ] TEMPORARY ]
TABLE [ IF NOT EXISTS ] name
[ ( { columnDefinition | constraint } [,...] ) ]
[ ENGINE tableEngineName ] [ NOT PERSISTENT ] [ TRANSACTIONAL ]
[ ENGINE tableEngineName [ WITH tableEngineParam [,...] ] ]
[ NOT PERSISTENT ] [ TRANSACTIONAL ]
[ AS select ]","
Creates a new table.
......@@ -599,6 +600,7 @@ unless the temporary table is created using CREATE CACHED TABLE.
The ENGINE option is only required when custom table implementations are used.
The table engine class must implement the interface ""org.h2.api.TableEngine"".
Any table engine parameters are passed down in the tableEngineParams field of the CreateTableData object.
Tables with the NOT PERSISTENT modifier are kept fully in memory, and all
rows are lost when the database is closed.
......
......@@ -41,6 +41,7 @@ Change Log
</li><li>Issue 477: PgServer binary transmission of query params is unimplemented, patch from Andrew Franklin
</li><li>Issue 479: Support for SUBSTRING without a FROM condition, patch from Andrew Franklin
</li><li>Issue 472: PgServer does not work with any recent Postgres JDBC driver, patch from Andrew Franklin
</li><li>Add syntax for passing additional parameters into custom TableEngine implementations
</li></ul>
<h2>Version 1.3.172 (2013-05-25)</h2>
......
......@@ -1658,6 +1658,13 @@ and then create the table from SQL like this:
CREATE TABLE TEST(ID INT, NAME VARCHAR) ENGINE "acme.MyTableEngine";
</pre>
</p>
<p>
It is also possible to pass in parameters to the table engine, like so:
<pre>
CREATE TABLE TEST(ID INT, NAME VARCHAR) ENGINE "acme.MyTableEngine" WITH "param1", "param2";
</pre>
In which case the parameters are passed down in the tableEngineParams field of the CreateTableData object.
</p>
<h2 id="triggers">Triggers</h2>
<p>
......
......@@ -5369,6 +5369,13 @@ public class Parser {
}
} else {
command.setTableEngine(readUniqueIdentifier());
if (readIf("WITH")) {
ArrayList<String> tableEngineParams = New.arrayList();
do {
tableEngineParams.add(readUniqueIdentifier());
} while (readIf(","));
command.setTableEngineParams(tableEngineParams);
}
}
} else if (database.getSettings().defaultTableEngine != null) {
command.setTableEngine(database.getSettings().defaultTableEngine);
......
......@@ -289,6 +289,10 @@ public class CreateTable extends SchemaCommand {
data.tableEngine = tableEngine;
}
public void setTableEngineParams(ArrayList<String> tableEngineParams) {
data.tableEngineParams = tableEngineParams;
}
public void setHidden(boolean isHidden) {
data.isHidden = isHidden;
}
......
......@@ -72,6 +72,11 @@ public class CreateTableData {
*/
public String tableEngine;
/**
* The table engine params to use for creating the table.
*/
public ArrayList<String> tableEngineParams;
/**
* The table is hidden.
*/
......
......@@ -55,6 +55,7 @@ public class TestTableEngines extends TestBase {
return;
}
testEarlyFilter();
testEngineParams();
testSimpleQuery();
}
......@@ -71,6 +72,19 @@ public class TestTableEngines extends TestBase {
deleteDb("tableEngine");
}
private void testEngineParams() throws SQLException {
deleteDb("tableEngine");
Connection conn = getConnection("tableEngine");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE t1(id int, name varchar) ENGINE \"" + EndlessTableEngine.class.getName()
+ "\" WITH \"param1\", \"param2\"");
assertEquals(2, EndlessTableEngine.createTableData.tableEngineParams.size());
assertEquals("param1", EndlessTableEngine.createTableData.tableEngineParams.get(0));
assertEquals("param2", EndlessTableEngine.createTableData.tableEngineParams.get(1));
conn.close();
deleteDb("tableEngine");
}
private void testSimpleQuery() throws SQLException {
deleteDb("tableEngine");
......@@ -352,6 +366,8 @@ public class TestTableEngines extends TestBase {
*/
public static class EndlessTableEngine implements TableEngine {
public static CreateTableData createTableData;
/**
* A table implementation with one row.
*/
......@@ -407,6 +423,7 @@ public class TestTableEngines extends TestBase {
*/
@Override
public EndlessTable createTable(CreateTableData data) {
createTableData = data;
return new EndlessTable(data);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论