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

CURRENT_TIMESTAMP() and so on now return the same value within a transaction.

上级 d5418c20
......@@ -3109,6 +3109,7 @@ CALL XMLTEXT('test')
{ CURRENT_DATE [ () ] | CURDATE() | SYSDATE | TODAY }
","
Returns the current date.
This method always returns the same value within a transaction.
","
CURRENT_DATE()
"
......@@ -3117,6 +3118,7 @@ CURRENT_DATE()
{ CURRENT_TIME [ () ] | CURTIME() }
","
Returns the current time.
This method always returns the same value within a transaction.
","
CURRENT_TIME()
"
......@@ -3126,6 +3128,7 @@ CURRENT_TIME()
","
Returns the current timestamp.
The precision parameter for nanoseconds precision is optional.
This method always returns the same value within a transaction.
","
CURRENT_TIMESTAMP()
"
......
......@@ -17,15 +17,16 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The statement CALL no longer converts an ARRAY return value to a list of values.
Now an ARRAY is returned.
<ul><li>CURRENT_TIMESTAMP() and so on now return the same value within a transaction.
</li><li>The statement CALL no longer converts an ARRAY return value to a list of values.
Now an ARRAY is returned.
</li><li>VALUES is now supported as a standalone command and as a table source:
SELECT * FROM (VALUES(1, 'Hello'), (2, 'World')) AS V;
</li><li>TIMESTAMPADD is now an alias for DATEADD.
Most SQL_TSI_ constants are now supported for for TIMESTAMPADD and TIMESTAMPDIFF
(all except SQL_TSI_QUARTER and SQL_TSI_FRAC_SECOND).
(all except SQL_TSI_QUARTER and SQL_TSI_FRAC_SECOND).
</li><li>Issue 313: NullPointerException in select query with a subquery or view.
</li><li>Native fulltext search: the characters '<', '>', and '\' are now also whitespace
</li><li>Native fulltext search: the characters '&lt;', '&gt;', and '\' are now also whitespace
characters. Also, the list of whitespace characters can be changed using
FullText.setWhitespaceChars(conn, ...)
</li><li>When reading from the classpath (for example read_file('classpath:logo.png')),
......@@ -79,7 +80,7 @@ Change Log
</li><li>Improved error message for syntax error: the list of expected tokens was sometimes not set correctly.
</li><li>Database file growth can now be limited using the database setting PAGE_STORE_MAX_GROWTH.
Slower growth may slow down operation, but speed up closing database.
</li><li>A read only database with writeable linked tables could lead to a DATABASE_IS_READ_ONLY (90097) error.
</li><li>A read only database with writable linked tables could lead to a DATABASE_IS_READ_ONLY (90097) error.
This is fixed now.
</li></ul>
......
......@@ -92,6 +92,7 @@ public class Session extends SessionWithState {
private volatile long cancelAt;
private boolean closed;
private long sessionStart = System.currentTimeMillis();
private long transactionStart;
private long currentCommandStart;
private HashMap<String, Value> variables;
private HashSet<ResultInterface> temporaryResults;
......@@ -454,6 +455,7 @@ public class Session extends SessionWithState {
public void commit(boolean ddl) {
checkCommitRollback();
currentTransactionName = null;
transactionStart = 0;
if (containsUncommitted()) {
// need to commit even if rollback is not possible
// (create/drop table and so on)
......@@ -1070,6 +1072,13 @@ public class Session extends SessionWithState {
return sessionStart;
}
public long getTransactionStart() {
if (transactionStart == 0) {
transactionStart = System.currentTimeMillis();
}
return transactionStart;
}
public Table[] getLocks() {
// copy the data without synchronizing
ArrayList<Table> copy = New.arrayList();
......
......@@ -677,18 +677,23 @@ public class Function extends Expression implements FunctionCall {
result = ValueInt.get(DateTimeUtils.getIsoDayOfWeek(v0.getDateNoCopy()));
break;
case CURDATE:
case CURRENT_DATE:
case CURRENT_DATE: {
long now = session.getTransactionStart();
// need to normalize
result = ValueDate.get(new Date(System.currentTimeMillis()));
result = ValueDate.get(new Date(now));
break;
}
case CURTIME:
case CURRENT_TIME:
case CURRENT_TIME: {
long now = session.getTransactionStart();
// need to normalize
result = ValueTime.get(new Time(System.currentTimeMillis()));
result = ValueTime.get(new Time(now));
break;
}
case NOW:
case CURRENT_TIMESTAMP: {
ValueTimestamp vt = ValueTimestamp.getNoCopy(new Timestamp(System.currentTimeMillis()));
long now = session.getTransactionStart();
ValueTimestamp vt = ValueTimestamp.getNoCopy(new Timestamp(now));
if (v0 != null) {
Mode mode = database.getMode();
vt = (ValueTimestamp) vt.convertScale(mode.convertOnlyToSmallerScale, v0.getInt());
......
......@@ -655,11 +655,15 @@ factor [ { { + | - } factor } [...] ]
","
A value or a numeric sum."
"Other Grammar","Table Expression","
{ [ schemaName. ] tableName | ( select ) } [ [ AS ] newTableAlias ]
{ [ schemaName. ] tableName | ( select ) | valuesExpression } [ [ AS ] newTableAlias ]
[ { { LEFT | RIGHT } [ OUTER ] | [ INNER ] | CROSS | NATURAL }
JOIN tableExpression [ ON expression ] ]
","
Joins a table."
"Other Grammar","Values Expression","
VALUES { ( expression [,...] ) } [,...]
","
A list of rows that can be used like a table."
"Other Grammar","Term","
value
| columnName
......@@ -1148,7 +1152,7 @@ Returns the current time."
","
Returns the current timestamp."
"Functions (Time and Date)","DATEADD","
DATEADD(unitString, addInt, timestamp)
{ DATEADD| TIMESTAMPADD } (unitString, addInt, timestamp)
","
Adds units to a timestamp."
"Functions (Time and Date)","DATEDIFF","
......
select count(distinct now()) c from system_range(1, 100), system_range(1, 1000);
> 1;
select {fn TIMESTAMPADD(SQL_TSI_DAY, 1, {ts '2011-10-20 20:30:40.001'})};
> 2011-10-21 20:30:40.001;
select {fn TIMESTAMPADD(SQL_TSI_SECOND, 1, cast('2011-10-20 20:30:40.001' as timestamp))};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论