mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
SQL SWERVER 返回当前日期和时间。
This commit is contained in:
parent
c5770b7801
commit
ca2e10dd70
@ -72,6 +72,7 @@ public class FuncName {
|
||||
public static final String FROM_UNIXTIME = "FROM_UNIXTIME";
|
||||
public static final String GET_FORMAT = "GET_FORMAT";
|
||||
public static final String GET_LOCT = "GET_LOCT";
|
||||
public static final String GET_DATE = "GETDATE";
|
||||
public static final String HEX = "HEX";
|
||||
public static final String HOUR = "HOUR";
|
||||
public static final String INET_ATON = "INET_ATON";
|
||||
|
||||
@ -15,18 +15,17 @@
|
||||
*/
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import static com.mybatisflex.core.constant.FuncName.*;
|
||||
|
||||
import com.mybatisflex.core.table.TableInfo;
|
||||
import com.mybatisflex.core.table.TableInfoFactory;
|
||||
import com.mybatisflex.core.util.ArrayUtil;
|
||||
import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.LambdaUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.constant.FuncName.*;
|
||||
|
||||
/**
|
||||
* SQL 函数。
|
||||
*/
|
||||
@ -1220,6 +1219,13 @@ public class QueryMethods {
|
||||
return new FunctionQueryColumn(NOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL SWERVER 返回当前日期和时间。
|
||||
*/
|
||||
public static QueryColumn getDate() {
|
||||
return new FunctionQueryColumn(GET_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前日期和时间。
|
||||
*/
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.mybatisflex.coretest;
|
||||
|
||||
import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT;
|
||||
|
||||
import com.mybatisflex.core.dialect.DbType;
|
||||
import com.mybatisflex.core.dialect.DialectFactory;
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QueryMethodsTest {
|
||||
|
||||
@Test
|
||||
public void testGetDate() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(ACCOUNT.ID)
|
||||
.from(ACCOUNT)
|
||||
.where(ACCOUNT.BIRTHDAY.lt(QueryMethods.getDate()));
|
||||
DialectFactory.setHintDbType(DbType.SQLSERVER);
|
||||
Assert.assertEquals("SELECT [id] FROM [tb_account] WHERE [birthday] < GETDATE()", queryWrapper.toSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSysDate() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(ACCOUNT.ID)
|
||||
.from(ACCOUNT)
|
||||
.where(ACCOUNT.BIRTHDAY.lt(QueryMethods.sysDate()));
|
||||
DialectFactory.setHintDbType(DbType.ORACLE);
|
||||
Assert.assertEquals("SELECT ID FROM TB_ACCOUNT WHERE BIRTHDAY < SYSDATE()", queryWrapper.toSQL());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user