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.ast.expr.SQLCharExpr; 17 18 import hunt.sql.SQLUtils; 19 import hunt.sql.ast.SQLDataType; 20 import hunt.sql.ast.SQLObject; 21 import hunt.sql.ast.statement.SQLCharacterDataType; 22 import hunt.sql.visitor.SQLASTOutputVisitor; 23 import hunt.sql.visitor.SQLASTVisitor; 24 import hunt.sql.ast.expr.SQLTextLiteralExpr; 25 import hunt.sql.ast.expr.SQLValuableExpr; 26 import hunt.collection; 27 import hunt.String; 28 import hunt.util.Appendable; 29 import hunt.util.Common; 30 import hunt.util.StringBuilder; 31 32 import std.concurrency : initOnce; 33 34 public class SQLCharExpr : SQLTextLiteralExpr , SQLValuableExpr { 35 36 static SQLDataType DEFAULT_DATA_TYPE() { 37 __gshared SQLDataType inst; 38 return initOnce!inst(new SQLCharacterDataType("varchar")); 39 } 40 41 public this(){ 42 43 } 44 45 public this(String text){ 46 super(text); 47 } 48 49 // public this(String text){ 50 // super(new String(text.value)); 51 // } 52 53 public this(string text){ 54 super(new String(text)); 55 } 56 57 override public void output(StringBuilder buf) { 58 output(cast(Appendable) buf); 59 } 60 61 public void output(Appendable buf) { 62 this.accept(new SQLASTOutputVisitor(buf)); 63 } 64 65 override protected void accept0(SQLASTVisitor visitor) { 66 visitor.visit(this); 67 visitor.endVisit(this); 68 } 69 70 override 71 public Object getValue() { 72 return this.text; 73 } 74 75 override public string toString() { 76 return SQLUtils.toSQLString(this); 77 } 78 79 override public SQLCharExpr clone() { 80 return new SQLCharExpr(this.text); 81 } 82 83 override public SQLDataType computeDataType() { 84 return DEFAULT_DATA_TYPE; 85 } 86 87 override public List!SQLObject getChildren() { 88 return Collections.emptyList!(SQLObject)(); 89 } 90 }