提交 23c0fae8 authored 作者: Thomas Mueller's avatar Thomas Mueller

New function SCOPE_IDENTITY().

上级 9b5cd887
......@@ -44,12 +44,13 @@ INSERT INTO TEST VALUES(1, 'Hello')
"
"Commands (DML)","UPDATE","
UPDATE tableName SET { columnName= { DEFAULT | expression } } [,...]
UPDATE tableName [ [ AS ] newTableAlias ] SET { columnName= { DEFAULT | expression } } [,...]
[ WHERE expression ]
","
Updates data in a table.
","
UPDATE TEST SET NAME='Hi' WHERE ID=1
UPDATE TEST SET NAME='Hi' WHERE ID=1;
UPDATE PERSON P SET NAME=(SELECT A.NAME FROM ADDRESS A WHERE A.ID=P.ID);
"
"Commands (DML)","DELETE","
......@@ -1034,7 +1035,7 @@ SET IGNORECASE TRUE
SET LOCK_MODE int
","
Sets the lock mode. The values 0, 1, 2, and 3 are supported. The default is 3
(READ_COMMITTED).
(READ_COMMITTED). This setting affects all connections.
The value 0 means no locking (should only be used for testing; also known as
READ_UNCOMMITTED). Please note that using SET LOCK_MODE 0 while at the same time
......@@ -3229,6 +3230,8 @@ CALL GREATEST(1, 2, 3);
IDENTITY()
","
Returns the last inserted identity value for this session.
This value changes whenever a new sequence number was generated,
even within a trigger or Java function. See also SCOPE_IDENTITY().
This method returns a long.
","
CALL IDENTITY();
......@@ -3351,6 +3354,16 @@ Returns the name of the default schema for this session.
CALL SCHEMA()
"
"Functions (System)","SCOPE_IDENTITY","
SCOPE_IDENTITY()
","
Returns the last inserted identity value for this session for the current scope.
Changes within triggers and Java functions are ignored. See also IDENTITY().
This method returns a long.
","
CALL SCOPE_IDENTITY();
"
"Functions (System)","SESSION_ID","
SESSION_ID()
","
......
......@@ -1993,6 +1993,10 @@ public class Database implements DataHandler {
public void setLockMode(int lockMode) throws SQLException {
switch (lockMode) {
case Constants.LOCK_MODE_OFF:
if (multiThreaded) {
// currently the combination of LOCK_MODE=0 and MULTI_THREADED is not supported
throw Message.getSQLException(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1, "LOCK_MODE=0 & MULTI_THREADED");
}
case Constants.LOCK_MODE_READ_COMMITTED:
case Constants.LOCK_MODE_TABLE:
case Constants.LOCK_MODE_TABLE_GC:
......
......@@ -292,6 +292,7 @@ public class FunctionAlias extends DbObjectBase {
}
}
boolean old = session.getAutoCommit();
Value identity = session.getScopeIdentity();
try {
session.setAutoCommit(false);
try {
......@@ -306,6 +307,7 @@ public class FunctionAlias extends DbObjectBase {
throw Message.convert(e);
}
} finally {
session.setScopeIdentity(identity);
session.setAutoCommit(old);
}
}
......
......@@ -67,6 +67,7 @@ public class Session extends SessionWithState {
private LogSystem logSystem;
private int lockTimeout;
private Value lastIdentity = ValueLong.get(0);
private Value scopeIdentity = ValueLong.get(0);
private int firstUncommittedLog = LogSystem.LOG_WRITTEN;
private int firstUncommittedPos = LogSystem.LOG_WRITTEN;
private HashMap<String, Integer> savepoints;
......@@ -686,6 +687,7 @@ public class Session extends SessionWithState {
}
public void setLastIdentity(Value last) {
this.scopeIdentity = last;
this.lastIdentity = last;
}
......@@ -1161,4 +1163,12 @@ public class Session extends SessionWithState {
return objectId++;
}
public void setScopeIdentity(Value scopeIdentity) {
this.scopeIdentity = scopeIdentity;
}
public Value getScopeIdentity() {
return scopeIdentity;
}
}
......@@ -91,8 +91,8 @@ public class Function extends Expression implements FunctionCall {
CURRENT_TIMESTAMP = 119, EXTRACT = 120, FORMATDATETIME = 121, PARSEDATETIME = 122,
ISO_YEAR = 123, ISO_WEEK = 124, ISO_DAY_OF_WEEK = 125;
public static final int DATABASE = 150, USER = 151, CURRENT_USER = 152, IDENTITY = 153, AUTOCOMMIT = 154,
READONLY = 155, DATABASE_PATH = 156, LOCK_TIMEOUT = 157;
public static final int DATABASE = 150, USER = 151, CURRENT_USER = 152, IDENTITY = 153, SCOPE_IDENTITY = 154,
AUTOCOMMIT = 155, READONLY = 156, DATABASE_PATH = 157, LOCK_TIMEOUT = 158;
public static final int IFNULL = 200, CASEWHEN = 201, CONVERT = 202, CAST = 203, COALESCE = 204, NULLIF = 205,
CASE = 206, NEXTVAL = 207, CURRVAL = 208, ARRAY_GET = 209, CSVREAD = 210, CSVWRITE = 211,
......@@ -286,6 +286,7 @@ public class Function extends Expression implements FunctionCall {
addFunctionNotDeterministic("USER", USER, 0, Value.STRING);
addFunctionNotDeterministic("CURRENT_USER", CURRENT_USER, 0, Value.STRING);
addFunctionNotDeterministic("IDENTITY", IDENTITY, 0, Value.LONG);
addFunctionNotDeterministic("SCOPE_IDENTITY", SCOPE_IDENTITY, 0, Value.LONG);
addFunctionNotDeterministic("IDENTITY_VAL_LOCAL", IDENTITY, 0, Value.LONG);
addFunctionNotDeterministic("LAST_INSERT_ID", IDENTITY, 0, Value.LONG);
addFunctionNotDeterministic("LASTVAL", IDENTITY, 0, Value.LONG);
......@@ -688,6 +689,9 @@ public class Function extends Expression implements FunctionCall {
case IDENTITY:
result = session.getLastIdentity();
break;
case SCOPE_IDENTITY:
result = session.getScopeIdentity();
break;
case AUTOCOMMIT:
result = ValueBoolean.get(session.getAutoCommit());
break;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论