提交 62e880b1 authored 作者: Max Englander's avatar Max Englander

enum-support: create table (with enum column) from select statement

上级 eb396945
......@@ -16,6 +16,7 @@ import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Session;
import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.Sequence;
......@@ -248,7 +249,18 @@ public class CreateTable extends SchemaCommand {
if (scale > precision) {
precision = scale;
}
Column col = new Column(name, type, precision, scale, displaySize);
String[] enumerators = null;
if (dt.enumerated) {
/**
* Only columns of tables may be enumerated.
*/
if(!(expr instanceof ExpressionColumn)) {
throw DbException.get(ErrorCode.GENERAL_ERROR_1,
"Unable to resolve enumerators of expression");
}
enumerators = ((ExpressionColumn)expr).getColumn().getEnumerators();
}
Column col = new Column(name, type, precision, scale, displaySize, enumerators);
addColumn(col);
}
}
......
......@@ -6,7 +6,7 @@
package org.h2.table;
import java.sql.ResultSetMetaData;
import java.util.Iterator;
import java.util.Arrays;
import org.h2.api.ErrorCode;
import org.h2.command.Parser;
import org.h2.engine.Constants;
......@@ -470,6 +470,7 @@ public class Column {
buff.append(',');
}
}
buff.append(')');
case Value.BYTES:
case Value.STRING:
case Value.STRING_IGNORECASE:
......@@ -779,7 +780,7 @@ public class Column {
displaySize = source.displaySize;
name = source.name;
precision = source.precision;
enumerators = source.enumerators;
enumerators = Arrays.copyOf(source.enumerators, source.enumerators.length);
scale = source.scale;
// table is not set
// columnId is not set
......
......@@ -80,7 +80,7 @@ public class ValueEnum extends Value {
return;
default:
throw DbException.get(ErrorCode.VALUE_NOT_PERMITTED,
"Provided value is does not match any enumerators");
"Provided value does not match any enumerators", value.toString());
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论