提交 0dd5f1b9 authored 作者: Thomas Mueller's avatar Thomas Mueller

Sequences: the functions NEXTVAL and CURRVAL did not work as expected when using…

Sequences: the functions NEXTVAL and CURRVAL did not work as expected when using quoted, mixed case sequence names.
上级 eafec1c0
...@@ -30,6 +30,7 @@ import org.h2.engine.Database; ...@@ -30,6 +30,7 @@ import org.h2.engine.Database;
import org.h2.engine.Mode; import org.h2.engine.Mode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.Sequence; import org.h2.schema.Sequence;
import org.h2.security.BlockCipher; import org.h2.security.BlockCipher;
import org.h2.security.CipherFactory; import org.h2.security.CipherFactory;
...@@ -1109,7 +1110,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1109,7 +1110,7 @@ public class Function extends Expression implements FunctionCall {
case CSVREAD: { case CSVREAD: {
String fileName = v0.getString(); String fileName = v0.getString();
String columnList = v1 == null ? null : v1.getString(); String columnList = v1 == null ? null : v1.getString();
Csv csv = Csv.getInstance(); Csv csv = new Csv();
String options = v2 == null ? null : v2.getString(); String options = v2 == null ? null : v2.getString();
String charset = null; String charset = null;
if (options != null && options.indexOf('=') >= 0) { if (options != null && options.indexOf('=') >= 0) {
...@@ -1145,7 +1146,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1145,7 +1146,7 @@ public class Function extends Expression implements FunctionCall {
case CSVWRITE: { case CSVWRITE: {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
Connection conn = session.createConnection(false); Connection conn = session.createConnection(false);
Csv csv = Csv.getInstance(); Csv csv = new Csv();
String options = v2 == null ? null : v2.getString(); String options = v2 == null ? null : v2.getString();
String charset = null; String charset = null;
if (options != null && options.indexOf('=') >= 0) { if (options != null && options.indexOf('=') >= 0) {
...@@ -1229,14 +1230,9 @@ public class Function extends Expression implements FunctionCall { ...@@ -1229,14 +1230,9 @@ public class Function extends Expression implements FunctionCall {
schemaName = seq.getOriginalTableAliasName(); schemaName = seq.getOriginalTableAliasName();
if (schemaName == null) { if (schemaName == null) {
schemaName = session.getCurrentSchemaName(); schemaName = session.getCurrentSchemaName();
sequenceName = sql;
} else { } else {
if (schemaName.equals(StringUtils.toLowerEnglish(schemaName))) { sequenceName = seq.getColumnName();
schemaName = StringUtils.toUpperEnglish(schemaName);
}
}
sequenceName = seq.getColumnName();
if (sequenceName.equals(StringUtils.toLowerEnglish(sequenceName))) {
sequenceName = StringUtils.toUpperEnglish(sequenceName);
} }
} else { } else {
throw DbException.getSyntaxError(sql, 1); throw DbException.getSyntaxError(sql, 1);
...@@ -1245,7 +1241,17 @@ public class Function extends Expression implements FunctionCall { ...@@ -1245,7 +1241,17 @@ public class Function extends Expression implements FunctionCall {
schemaName = v0.getString(); schemaName = v0.getString();
sequenceName = v1.getString(); sequenceName = v1.getString();
} }
return database.getSchema(schemaName).getSequence(sequenceName); Schema s = database.findSchema(schemaName);
if (s == null) {
schemaName = StringUtils.toUpperEnglish(schemaName);
s = database.getSchema(schemaName);
}
Sequence seq = s.findSequence(sequenceName);
if (seq == null) {
sequenceName = StringUtils.toUpperEnglish(sequenceName);
seq = s.getSequence(sequenceName);
}
return seq;
} }
private static long length(Value v) { private static long length(Value v) {
...@@ -2011,7 +2017,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -2011,7 +2017,7 @@ public class Function extends Expression implements FunctionCall {
throw DbException.get(ErrorCode.PARAMETER_NOT_SET_1, "fileName"); throw DbException.get(ErrorCode.PARAMETER_NOT_SET_1, "fileName");
} }
String columnList = argList.length < 2 ? null : argList[1].getValue(session).getString(); String columnList = argList.length < 2 ? null : argList[1].getValue(session).getString();
Csv csv = Csv.getInstance(); Csv csv = new Csv();
String options = argList.length < 3 ? null : argList[2].getValue(session).getString(); String options = argList.length < 3 ? null : argList[2].getValue(session).getString();
String charset = null; String charset = null;
if (options != null && options.indexOf('=') >= 0) { if (options != null && options.indexOf('=') >= 0) {
......
...@@ -2500,6 +2500,18 @@ drop schema "TestSchema"; ...@@ -2500,6 +2500,18 @@ drop schema "TestSchema";
drop sequence main_seq; drop sequence main_seq;
> ok > ok
create sequence "test";
> ok
select nextval('test');
> NEXTVAL('test')
> ---------------
> 1
> rows: 1
drop sequence "test";
> ok
set autocommit on; set autocommit on;
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论