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