P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package foundation.util;
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import foundation.server.config.DBaseType;
 
public class DBDate {
 
    private Date date;
    private boolean includeTime;
    
 
    public DBDate() {
        date = new Date();
        includeTime = false;
    }
    
    public DBDate(Date date) {
        this.date = date;
        includeTime = false;
    }
    
    public DBDate(Date date, boolean includeTime) {
        this.date = date;
        this.includeTime = includeTime;
    }
 
    public String toSqlString(DBaseType type) {
        if (date == null) {
            return "null";
        }
        
        String result = null;
        String formatter = this.includeTime ? "yyyy-MM-dd HH:mm:ss" : "yyyy-MM-dd";
        DateFormat dateFormat = new SimpleDateFormat(formatter);
        String value = dateFormat.format(this.date);
 
        if (type.isOracle()) {
            result = "to_date('" + value + "','YYYY-MM-DD')";
        } 
        else if (type.isSQLServer()) {
            result = "'" + value + "'";
        } 
        else if (type.isMySQL()) {
            result = "'" + value + "'";
        }
        else {
            result = "'" + value + "'";
        }
 
        return result;
    }
    
    public static String getDayAddFunciton(DBaseType dbType) {
        if (dbType.isOracle()) {
            return "ADD_DAYS";
        }
        else if (dbType.isMySQL()) {
            return "ADDDATE";
        }
        else if (dbType.isSQLServer()) {
            return "DATE_ADD";
        }
        
        return "ADD_DAYS";
    }
 
    public static String getCurrentTimeFunciton(DBaseType dbType) {
        if (dbType.isOracle()) {
            return "SYSDATE";
        }
        else if (dbType.isMySQL()) {
            return "now()";
        }
        else if (dbType.isSQLServer()) {
            return "GETDATE()";
        }
        
        return "SYSDATE";
    }
    
    public static String getCurrentDateFunciton(DBaseType dbType) {
        if (dbType.isOracle()) {
            return "SYSDATE";
        }
        else if (dbType.isMySQL()) {
            return "now()";
        }
        else if (dbType.isSQLServer()) {
            return "GETDATE()";
        }
        
        return "SYSDATE";
    }
    
}