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

--no commit message

--no commit message
上级 d536591a
...@@ -22,6 +22,7 @@ Initial Developer: H2 Group ...@@ -22,6 +22,7 @@ Initial Developer: H2 Group
<br /> <br />
<b>JDBC</b><br /> <b>JDBC</b><br />
<a href="org/h2/jdbc/JdbcArray.html" target="javadoc">Array</a><br />
<a href="org/h2/jdbc/JdbcBlob.html" target="javadoc">Blob</a><br /> <a href="org/h2/jdbc/JdbcBlob.html" target="javadoc">Blob</a><br />
<a href="org/h2/jdbc/JdbcCallableStatement.html" target="javadoc">CallableStatement</a><br /> <a href="org/h2/jdbc/JdbcCallableStatement.html" target="javadoc">CallableStatement</a><br />
<a href="org/h2/jdbc/JdbcClob.html" target="javadoc">Clob</a><br /> <a href="org/h2/jdbc/JdbcClob.html" target="javadoc">Clob</a><br />
...@@ -46,6 +47,7 @@ Package org.h2.tools<br /> ...@@ -46,6 +47,7 @@ Package org.h2.tools<br />
<a href="org/h2/tools/Csv.html" target="javadoc">Csv</a><br /> <a href="org/h2/tools/Csv.html" target="javadoc">Csv</a><br />
<a href="org/h2/tools/DeleteDbFiles.html" target="javadoc">DeleteDbFiles</a><br /> <a href="org/h2/tools/DeleteDbFiles.html" target="javadoc">DeleteDbFiles</a><br />
<a href="org/h2/tools/MultiDimension.html" target="javadoc">MultiDimension</a><br /> <a href="org/h2/tools/MultiDimension.html" target="javadoc">MultiDimension</a><br />
<a href="org/h2/tools/Script.html" target="javadoc">Script</a><br />
<a href="org/h2/tools/Recover.html" target="javadoc">Recover</a><br /> <a href="org/h2/tools/Recover.html" target="javadoc">Recover</a><br />
<a href="org/h2/tools/RunScript.html" target="javadoc">RunScript</a><br /> <a href="org/h2/tools/RunScript.html" target="javadoc">RunScript</a><br />
<a href="org/h2/tools/Server.html" target="javadoc">Server</a><br /> <a href="org/h2/tools/Server.html" target="javadoc">Server</a><br />
......
...@@ -161,6 +161,7 @@ public class Parser { ...@@ -161,6 +161,7 @@ public class Parser {
private boolean rightsChecked; private boolean rightsChecked;
private boolean recompileAlways; private boolean recompileAlways;
private ObjectArray indexedParameterList; private ObjectArray indexedParameterList;
private int tempViewId;
public Parser(Session session) { public Parser(Session session) {
this.session = session; this.session = session;
...@@ -734,7 +735,8 @@ public class Parser { ...@@ -734,7 +735,8 @@ public class Parser {
if(isToken("SELECT") || isToken("FROM")) { if(isToken("SELECT") || isToken("FROM")) {
Query query = parseQueryWithParams(); Query query = parseQueryWithParams();
String querySQL = query.getSQL(); String querySQL = query.getSQL();
table = new TableView(mainSchema, 0, "TEMP_VIEW", querySQL, query.getParameters(), null, session, false); int id = tempViewId++;
table = new TableView(mainSchema, 0, "TEMP_VIEW_" + id, querySQL, query.getParameters(), null, session, false);
read(")"); read(")");
} else { } else {
TableFilter top = readTableFilter(fromOuter); TableFilter top = readTableFilter(fromOuter);
...@@ -1675,6 +1677,21 @@ public class Parser { ...@@ -1675,6 +1677,21 @@ public class Parser {
read(")"); read(")");
break; break;
} }
case Function.TABLE: {
int i = 0;
ObjectArray columns = new ObjectArray();
do {
String columnName = readAliasIdentifier();
Column column = parseColumn(columnName);
columns.add(column);
read("=");
function.setParameter(i, readExpression());
i++;
} while(readIf(","));
read(")");
function.setColumns(columns);
break;
}
default: default:
if(!readIf(")")) { if(!readIf(")")) {
int i=0; int i=0;
...@@ -3157,51 +3174,46 @@ public class Parser { ...@@ -3157,51 +3174,46 @@ public class Parser {
} }
private Query parserWith() throws SQLException { private Query parserWith() throws SQLException {
// String tempViewName = readUniqueIdentifier(); String tempViewName = readIdentifierWithSchema();
// if(readIf("(")) { Schema schema = getSchema();
// String[] cols = parseColumnList(false); TableData recursiveTable;
// command.setColumnNames(cols); read("(");
// String[] cols = parseColumnList(false);
// ObjectArray columns = new ObjectArray();
// if(recursive) { for(int i=0; i<cols.length; i++) {
// ObjectArray columns = new ObjectArray(); columns.add(new Column(cols[i], Value.STRING, 0, 0));
// for(int i=0; i<cols.length; i++) { }
// columns.add(new Column(cols[i], Value.STRING, 0, 0)); int id = database.allocateObjectId(true, true);
// } recursiveTable = new TableData(schema, tempViewName, id, columns, false);
// recursiveTable = new TableData(getSchema(), viewName, 0, columns, false); recursiveTable.setTemporary(true);
// recursiveTable.setTemporary(true); session.addLocalTempTable(recursiveTable);
// session.addLocalTempTable(recursiveTable); String querySQL = StringCache.getNew(sqlCommand.substring(parseIndex));
// } read("AS");
return null; Query withQuery = parseSelect();
withQuery.prepare();
session.removeLocalTempTable(recursiveTable);
id = database.allocateObjectId(true, true);
TableView view = new TableView(schema, id, tempViewName, querySQL, null, cols, session, true);
view.setTemporary(true);
// view.setOnCommitDrop(true);
session.addLocalTempTable(view);
Query query = parseSelect();
query.prepare();
query.setPrepareAlways(true);
// session.removeLocalTempTable(view);
return query;
} }
private CreateView parseCreateView(boolean force) throws SQLException { private CreateView parseCreateView(boolean force) throws SQLException {
int test;
TableData recursiveTable = null;
boolean recursive = readIf("RECURSIVE");
boolean ifNotExists = readIfNoExists(); boolean ifNotExists = readIfNoExists();
String viewName = readIdentifierWithSchema(); String viewName = readIdentifierWithSchema();
CreateView command = new CreateView(session, getSchema()); CreateView command = new CreateView(session, getSchema());
command.setRecursive(recursive);
command.setViewName(viewName); command.setViewName(viewName);
command.setIfNotExists(ifNotExists); command.setIfNotExists(ifNotExists);
command.setComment(readCommentIf()); command.setComment(readCommentIf());
if(readIf("(")) { if(readIf("(")) {
String[] cols = parseColumnList(false); String[] cols = parseColumnList(false);
command.setColumnNames(cols); command.setColumnNames(cols);
if(recursive) {
ObjectArray columns = new ObjectArray();
for(int i=0; i<cols.length; i++) {
columns.add(new Column(cols[i], Value.STRING, 0, 0));
}
int id = database.allocateObjectId(true, true);
recursiveTable = new TableData(getSchema(), viewName, id, columns, false);
recursiveTable.setTemporary(true);
session.addLocalTempTable(recursiveTable);
}
} }
String select = StringCache.getNew(sqlCommand.substring(parseIndex)); String select = StringCache.getNew(sqlCommand.substring(parseIndex));
read("AS"); read("AS");
...@@ -3216,11 +3228,6 @@ public class Parser { ...@@ -3216,11 +3228,6 @@ public class Parser {
throw e; throw e;
} }
} }
if(recursiveTable != null) {
session.removeLocalTempTable(recursiveTable);
}
return command; return command;
} }
...@@ -3756,6 +3763,21 @@ public class Parser { ...@@ -3756,6 +3763,21 @@ public class Parser {
command.setIndex(schema.findIndex(indexName)); command.setIndex(schema.findIndex(indexName));
} }
read("REFERENCES"); read("REFERENCES");
parseReferences(command, schema, tableName);
} else {
if(name != null) {
throw getSyntaxError();
}
return null;
}
command.setTableName(tableName);
command.setConstraintName(name);
command.setComment(comment);
return command;
}
private void parseReferences(AlterTableAddConstraint command, Schema schema, String tableName) throws SQLException {
String[] cols;
if(readIf("(")) { if(readIf("(")) {
command.setRefTableName(schema, tableName); command.setRefTableName(schema, tableName);
cols = parseColumnList(false); cols = parseColumnList(false);
...@@ -3785,16 +3807,6 @@ public class Parser { ...@@ -3785,16 +3807,6 @@ public class Parser {
} else { } else {
readIf("DEFERRABLE"); readIf("DEFERRABLE");
} }
} else {
if(name != null) {
throw getSyntaxError();
}
return null;
}
command.setTableName(tableName);
command.setConstraintName(name);
command.setComment(comment);
return command;
} }
private CreateLinkedTable parseCreateLinkedTable() throws SQLException { private CreateLinkedTable parseCreateLinkedTable() throws SQLException {
...@@ -3869,21 +3881,18 @@ public class Parser { ...@@ -3869,21 +3881,18 @@ public class Parser {
unique.setColumnNames(new String[]{columnName}); unique.setColumnNames(new String[]{columnName});
unique.setTableName(tableName); unique.setTableName(tableName);
command.addConstraintCommand(unique); command.addConstraintCommand(unique);
} else if(readIf("CHECK")) { }
if(readIf("CHECK")) {
Expression expr = readExpression(); Expression expr = readExpression();
column.addCheckConstraint(session, expr); column.addCheckConstraint(session, expr);
} else if(readIf("REFERENCES")) { }
if(readIf("REFERENCES")) {
AlterTableAddConstraint ref = new AlterTableAddConstraint(session, schema); AlterTableAddConstraint ref = new AlterTableAddConstraint(session, schema);
ref.setConstraintName(constraintName); ref.setConstraintName(constraintName);
ref.setType(AlterTableAddConstraint.REFERENTIAL); ref.setType(AlterTableAddConstraint.REFERENTIAL);
ref.setColumnNames(new String[]{columnName}); ref.setColumnNames(new String[]{columnName});
ref.setTableName(tableName); ref.setTableName(tableName);
String refTableName = readIdentifierWithSchema(schema.getName()); parseReferences(ref, schema, tableName);
ref.setRefTableName(getSchema(), refTableName);
if(readIf("(")) {
String[] cols = parseColumnList(false);
ref.setRefColumnNames(cols);
}
command.addConstraintCommand(ref); command.addConstraintCommand(ref);
} }
} }
......
...@@ -138,6 +138,9 @@ public class Script extends ScriptBase { ...@@ -138,6 +138,9 @@ public class Script extends ScriptBase {
ObjectArray datatypes = db.getAllUserDataTypes(); ObjectArray datatypes = db.getAllUserDataTypes();
for(int i=0; i<datatypes.size(); i++) { for(int i=0; i<datatypes.size(); i++) {
UserDataType datatype = (UserDataType) datatypes.get(i); UserDataType datatype = (UserDataType) datatypes.get(i);
if(drop) {
add(datatype.getDropSQL(), false);
}
add(datatype.getCreateSQL(), false); add(datatype.getCreateSQL(), false);
} }
ObjectArray constants = db.getAllSchemaObjects(DbObject.CONSTANT); ObjectArray constants = db.getAllSchemaObjects(DbObject.CONSTANT);
...@@ -148,6 +151,9 @@ public class Script extends ScriptBase { ...@@ -148,6 +151,9 @@ public class Script extends ScriptBase {
ObjectArray functionAliases = db.getAllFunctionAliases(); ObjectArray functionAliases = db.getAllFunctionAliases();
for(int i=0; i<functionAliases.size(); i++) { for(int i=0; i<functionAliases.size(); i++) {
FunctionAlias alias = (FunctionAlias) functionAliases.get(i); FunctionAlias alias = (FunctionAlias) functionAliases.get(i);
if(drop) {
add(alias.getDropSQL(), false);
}
add(alias.getCreateSQL(), false); add(alias.getCreateSQL(), false);
} }
ObjectArray tables = db.getAllSchemaObjects(DbObject.TABLE_OR_VIEW); ObjectArray tables = db.getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
...@@ -167,20 +173,15 @@ public class Script extends ScriptBase { ...@@ -167,20 +173,15 @@ public class Script extends ScriptBase {
// null for metadata tables // null for metadata tables
continue; continue;
} }
String tableType = table.getTableType();
if(drop) { if(drop) {
if(Table.VIEW.equals(tableType)) { add(table.getDropSQL(), false);
add("DROP VIEW IF EXISTS " + table.getSQL(), false);
} else {
add("DROP TABLE IF EXISTS " + table.getSQL(), false);
}
} }
} }
ObjectArray sequences = db.getAllSchemaObjects(DbObject.SEQUENCE); ObjectArray sequences = db.getAllSchemaObjects(DbObject.SEQUENCE);
for(int i=0; i<sequences.size(); i++) { for(int i=0; i<sequences.size(); i++) {
Sequence sequence = (Sequence) sequences.get(i); Sequence sequence = (Sequence) sequences.get(i);
if(drop && !sequence.getBelongsToTable()) { if(drop) {
add("DROP SEQUENCE IF EXISTS " + sequence.getSQL(), false); add(sequence.getDropSQL(), false);
} }
add(sequence.getCreateSQL(), false); add(sequence.getCreateSQL(), false);
} }
......
...@@ -39,7 +39,6 @@ public class ScriptBase extends Prepared implements DataHandler { ...@@ -39,7 +39,6 @@ public class ScriptBase extends Prepared implements DataHandler {
protected OutputStream out; protected OutputStream out;
protected InputStream in; protected InputStream in;
protected String fileName; protected String fileName;
private String compressionAlgorithm; private String compressionAlgorithm;
public ScriptBase(Session session) { public ScriptBase(Session session) {
...@@ -81,6 +80,7 @@ public class ScriptBase extends Prepared implements DataHandler { ...@@ -81,6 +80,7 @@ public class ScriptBase extends Prepared implements DataHandler {
Database db = session.getDatabase(); Database db = session.getDatabase();
// script files are always in text format // script files are always in text format
store = FileStore.open(db, fileName, magic, cipher, key); store = FileStore.open(db, fileName, magic, cipher, key);
store.setCheckedWriting(false);
store.init(); store.init();
} }
......
...@@ -33,7 +33,6 @@ import org.h2.value.ValueArray; ...@@ -33,7 +33,6 @@ import org.h2.value.ValueArray;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
* visibleColumnCount <= distinctColumnCount <= expressionCount * visibleColumnCount <= distinctColumnCount <= expressionCount
* Sortable count could include ORDER BY expressions that are not in the select list * Sortable count could include ORDER BY expressions that are not in the select list
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论