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.SQLNCharExpr; 17 18 import hunt.sql.ast.SQLDataType; 19 import hunt.sql.ast.statement.SQLCharacterDataType; 20 import hunt.sql.visitor.SQLASTVisitor; 21 import hunt.sql.ast.expr.SQLTextLiteralExpr; 22 import hunt.collection; 23 import std.array; 24 import hunt.String; 25 import hunt.util.StringBuilder; 26 27 import std.concurrency : initOnce; 28 29 public class SQLNCharExpr : SQLTextLiteralExpr { 30 31 static SQLDataType defaultDataType() { 32 __gshared SQLDataType inst; 33 return initOnce!inst(new SQLCharacterDataType("nvarchar")); 34 } 35 36 public this(){ 37 38 } 39 40 public this(String text){ 41 super(text); 42 } 43 44 public this(string text){ 45 super(new String(text)); 46 } 47 48 override public void output(StringBuilder buf) { 49 if ((this.text is null) || (this.text.value.length == 0)) { 50 buf.append("NULL"); 51 return; 52 } 53 54 buf.append("N'"); 55 buf.append(this.text.value().replace("'", "''")); 56 buf.append("'"); 57 } 58 59 override protected void accept0(SQLASTVisitor visitor) { 60 visitor.visit(this); 61 visitor.endVisit(this); 62 } 63 64 override public SQLNCharExpr clone() { 65 return new SQLNCharExpr(text); 66 } 67 68 override public SQLDataType computeDataType() { 69 return defaultDataType; 70 } 71 }