1 module hunt.sql.ast.expr.SQLTimestampExpr;
2 import hunt.sql.ast.expr.SQLValuableExpr;
3 import hunt.sql.ast.SQLDataType;
4 import hunt.sql.visitor.SQLASTVisitor;
5 import hunt.sql.ast.SQLExprImpl;
6 import hunt.collection;
7 import hunt.sql.ast.SQLObject;
8 import hunt.sql.ast.statement.SQLCharacterDataType;
9 import hunt.sql.SQLUtils;
10 //import hunt.lang;
11 import hunt.String;
12 
13 import std.concurrency : initOnce;
14 
15 public class SQLTimestampExpr : SQLExprImpl , SQLValuableExpr {
16     
17     static SQLDataType DEFAULT_DATA_TYPE() {
18         __gshared SQLDataType inst;
19         return initOnce!inst(new SQLCharacterDataType("datetime"));
20     }
21 
22     protected string  literal;
23     protected string  timeZone;
24     protected bool withTimeZone = false;
25 
26     this()
27     {
28     }
29     public this(string literal){
30         this.literal = literal;
31     }
32 
33 
34     override public SQLTimestampExpr clone() {
35         SQLTimestampExpr x = new SQLTimestampExpr();
36         x.literal = literal;
37         x.timeZone = timeZone;
38         x.withTimeZone = withTimeZone;
39         return x;
40     }
41 
42     override public Object getValue() {
43         return new String(literal);
44     }
45 
46     public string getLiteral() {
47         return literal;
48     }
49 
50     public void setLiteral(string literal) {
51         this.literal = literal;
52     }
53 
54     public string getTimeZone() {
55         return this.timeZone;
56     }
57 
58     public void setTimeZone(string timeZone) {
59         this.timeZone = timeZone;
60     }
61 
62     public bool isWithTimeZone() {
63         return withTimeZone;
64     }
65 
66     public void setWithTimeZone(bool withTimeZone) {
67         this.withTimeZone = withTimeZone;
68     }
69 
70     public override size_t toHash() @trusted nothrow {
71          int prime = 31;
72         size_t result = 1;
73         result = prime * result + hashOf(literal);
74         result = prime * result + hashOf(timeZone);
75         result = prime * result + (withTimeZone ? 1231 : 1237);
76         return result;
77     }
78 
79     public override bool opEquals(Object obj) {
80         if (this is obj) {
81             return true;
82         }
83         if (obj is null) {
84             return false;
85         }
86         if (typeid(SQLTimestampExpr) != typeid(obj)) {
87             return false;
88         }
89         SQLTimestampExpr other = cast(SQLTimestampExpr) obj;
90         if (literal is null) {
91             if (other.literal !is null) {
92                 return false;
93             }
94         } else if (!(literal == other.literal)) {
95             return false;
96         }
97         if (timeZone is null) {
98             if (other.timeZone !is null) {
99                 return false;
100             }
101         } else if (!(timeZone == other.timeZone)) {
102             return false;
103         }
104         if (withTimeZone != other.withTimeZone) {
105             return false;
106         }
107         return true;
108     }
109 
110     protected override void accept0(SQLASTVisitor visitor) {
111         visitor.visit(this);
112 
113         visitor.endVisit(this);
114     }
115 
116     override public string toString() {
117         return SQLUtils.toSQLString(this, null);
118     }
119 
120     override public SQLDataType computeDataType() {
121         return DEFAULT_DATA_TYPE;
122     }
123 
124     public override List!SQLObject getChildren() {
125         return Collections.emptyList!(SQLObject)();
126     }
127 }