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.statement.MySqlExplainStatement; 17 18 import hunt.sql.SQLUtils; 19 import hunt.sql.ast.SQLExpr; 20 import hunt.sql.ast.SQLName; 21 import hunt.sql.ast.statement.SQLExplainStatement; 22 import hunt.sql.dialect.mysql.ast.clause.MySqlExplainType; 23 import hunt.sql.dialect.mysql.ast.clause.MySqlFormatName; 24 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 25 import hunt.sql.visitor.SQLASTVisitor; 26 import hunt.sql.util.DBType; 27 import hunt.sql.dialect.mysql.ast.statement.MySqlStatement; 28 29 public class MySqlExplainStatement : SQLExplainStatement , MySqlStatement { 30 private bool describe; 31 private SQLName tableName; 32 private SQLName columnName; 33 private SQLExpr wild; 34 private string format; 35 private SQLExpr connectionId; 36 37 public this() { 38 super (DBType.MYSQL.name); 39 } 40 41 public this(string dbType) { 42 super (dbType); 43 } 44 45 46 override 47 public void accept0(MySqlASTVisitor visitor) { 48 if (visitor.visit(this)) { 49 // tbl_name [col_name | wild] 50 if (tableName !is null) { 51 acceptChild(visitor, tableName); 52 if (columnName !is null) { 53 acceptChild(visitor, columnName); 54 } else if (wild !is null) { 55 acceptChild(visitor, wild); 56 } 57 } else { 58 // {explainable_stmt | FOR CONNECTION connection_id} 59 if (connectionId !is null) { 60 acceptChild(visitor, connectionId); 61 } else { 62 acceptChild(visitor, statement); 63 } 64 } 65 } 66 67 visitor.endVisit(this); 68 } 69 70 override protected void accept0(SQLASTVisitor visitor) { 71 accept0(cast(MySqlASTVisitor) visitor); 72 } 73 74 override public string toString() { 75 return SQLUtils.toMySqlString(this); 76 } 77 78 public bool isDescribe() { 79 return describe; 80 } 81 82 public void setDescribe(bool describe) { 83 this.describe = describe; 84 } 85 86 public SQLName getTableName() { 87 return tableName; 88 } 89 90 public void setTableName(SQLName tableName) { 91 this.tableName = tableName; 92 } 93 94 public SQLName getColumnName() { 95 return columnName; 96 } 97 98 public void setColumnName(SQLName columnName) { 99 this.columnName = columnName; 100 } 101 102 public SQLExpr getWild() { 103 return wild; 104 } 105 106 public void setWild(SQLExpr wild) { 107 this.wild = wild; 108 } 109 110 public string getFormat() { 111 return format; 112 } 113 114 public void setFormat(string format) { 115 this.format = format; 116 } 117 118 public SQLExpr getConnectionId() { 119 return connectionId; 120 } 121 122 public void setConnectionId(SQLExpr connectionId) { 123 this.connectionId = connectionId; 124 } 125 126 }