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.visitor.MySqlExportParameterVisitor; 17 18 19 import hunt.collection; 20 21 import hunt.sql.ast.SQLOrderBy; 22 import hunt.sql.ast.expr.SQLBetweenExpr; 23 import hunt.sql.ast.expr.SQLBinaryOpExpr; 24 import hunt.sql.ast.expr.SQLInListExpr; 25 import hunt.sql.ast.expr.SQLMethodInvokeExpr; 26 import hunt.sql.ast.statement.SQLSelectGroupByClause; 27 import hunt.sql.ast.statement.SQLSelectItem; 28 import hunt.sql.ast.SQLLimit; 29 import hunt.sql.dialect.mysql.ast.statement.MySqlFlushStatement; 30 import hunt.sql.visitor.ExportParameterVisitor; 31 import hunt.sql.visitor.ExportParameterVisitorUtils; 32 import hunt.sql.dialect.mysql.visitor.MySqlOutputVisitor; 33 import hunt.sql.visitor.SQLASTOutputVisitor; 34 import hunt.util.Appendable; 35 import hunt.util.Common; 36 37 public class MySqlExportParameterVisitor : MySqlOutputVisitor , ExportParameterVisitor { 38 39 alias visit = MySqlOutputVisitor.visit; 40 alias endVisit = MySqlOutputVisitor.endVisit; 41 /** 42 * true= if require parameterized sql output 43 */ 44 private bool requireParameterizedOutput; 45 46 override public bool isParameterizedMergeInList() 47 { 48 return super.isParameterizedMergeInList(); 49 } 50 override public void setParameterizedMergeInList(bool flag) 51 { 52 return super.setParameterizedMergeInList(flag); 53 } 54 55 public this(List!(Object) parameters, Appendable appender, bool wantParameterizedOutput){ 56 super(appender, true); 57 this.parameters = parameters; 58 this.requireParameterizedOutput = wantParameterizedOutput; 59 } 60 61 public this() { 62 this(new ArrayList!(Object)()); 63 } 64 65 public this(List!(Object) parameters) { 66 this(parameters, null, false); 67 } 68 69 public this( Appendable appender) { 70 this(new ArrayList!(Object)(),appender, true); 71 } 72 73 override public List!(Object) getParameters() { 74 return parameters; 75 } 76 77 override 78 public bool visit( SQLSelectItem x) { 79 if(requireParameterizedOutput){ 80 return (super).visit(x); 81 } 82 return true; 83 } 84 85 override 86 public bool visit(SQLLimit x) { 87 if(requireParameterizedOutput){ 88 return (super).visit(x); 89 } 90 91 return true; 92 } 93 94 override 95 public bool visit(SQLOrderBy x) { 96 if(requireParameterizedOutput){ 97 return (super).visit(x); 98 } 99 return false; 100 } 101 102 override 103 public bool visit(SQLSelectGroupByClause x) { 104 if(requireParameterizedOutput){ 105 return (super).visit(x); 106 } 107 return false; 108 } 109 110 override 111 public bool visit(SQLMethodInvokeExpr x) { 112 if(requireParameterizedOutput){ 113 return (super).visit(x); 114 } 115 116 ExportParameterVisitorUtils.exportParamterAndAccept(this.parameters, x.getParameters()); 117 return true; 118 } 119 120 override 121 public bool visit(SQLInListExpr x) { 122 if(requireParameterizedOutput){ 123 return (super).visit(x); 124 } 125 ExportParameterVisitorUtils.exportParamterAndAccept(this.parameters, x.getTargetList()); 126 127 return true; 128 } 129 130 override 131 public bool visit(SQLBetweenExpr x) { 132 if(requireParameterizedOutput){ 133 return (super).visit(x); 134 } 135 ExportParameterVisitorUtils.exportParameter(this.parameters, x); 136 return true; 137 } 138 139 override public bool visit(SQLBinaryOpExpr x) { 140 if(requireParameterizedOutput){ 141 return (super).visit(x); 142 } 143 ExportParameterVisitorUtils.exportParameter(this.parameters, x); 144 return true; 145 } 146 147 override 148 public bool visit(MySqlFlushStatement x) { 149 return true; 150 } 151 152 override 153 public void endVisit(MySqlFlushStatement x) { 154 155 } 156 }