1 /*
2  * Copyright 2015-2018 HuntLabs.cn
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 module hunt.sql.dialect.mysql.ast.expr.MySqlCharExpr;
17 
18 import hunt.sql.ast.expr.SQLCharExpr;
19 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor;
20 import hunt.sql.visitor.SQLASTVisitor;
21 import hunt.sql.dialect.mysql.ast.expr.MySqlExpr;
22 import hunt.collection;
23 import hunt.String;
24 import hunt.util.StringBuilder;
25 
26 public class MySqlCharExpr : SQLCharExpr , MySqlExpr {
27 
28     alias output = SQLCharExpr.output;
29 
30     private string charset;
31     private string collate;
32 
33     public this(){
34 
35     }
36 
37     public this(string text){
38         super(text);
39     }
40 
41      public this(String text){
42         super(text);
43     }
44 
45     public string getCharset() {
46         return charset;
47     }
48 
49     public void setCharset(string charset) {
50         this.charset = charset;
51     }
52 
53     public string getCollate() {
54         return collate;
55     }
56 
57     public void setCollate(string collate) {
58         this.collate = collate;
59     }
60 
61     override public void output(StringBuilder buf) {
62         if (charset !is null) {
63             buf.append(charset);
64             buf.append(' ');
65         }
66         if (super.text !is null){
67             super.output(buf);
68         }
69 
70         if (collate !is null) {
71             buf.append(" COLLATE ");
72             buf.append(collate);
73         }
74     }
75 
76     
77     override  protected void accept0(SQLASTVisitor visitor) {
78         if (cast(MySqlASTVisitor)(visitor) !is null) {
79             accept0(cast(MySqlASTVisitor) visitor);
80         } else {
81             visitor.visit(this);
82             visitor.endVisit(this);
83         }
84     }
85 
86     public void accept0(MySqlASTVisitor visitor) {
87         visitor.visit(this);
88         visitor.endVisit(this);
89     }
90     
91     override public string toString() {
92         StringBuilder buf = new StringBuilder();
93         output(buf);
94         return buf.toString();
95     }
96     
97     override public MySqlCharExpr clone() {
98     	MySqlCharExpr x = new MySqlCharExpr(text);
99         x.setCharset(charset);
100         x.setCollate(collate);
101         return x;
102     }
103 }