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

--no commit message

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