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.clause.MySqlStatementType; 17 18 import hunt.sql.ast.SQLStatement; 19 import hunt.sql.ast.statement; 20 import hunt.sql.dialect.mysql.ast.statement.MySqlDeleteStatement; 21 import hunt.sql.dialect.mysql.ast.statement.MySqlInsertStatement; 22 import hunt.sql.dialect.mysql.ast.statement.MySqlUpdateStatement; 23 24 25 public struct MySqlStatementType { 26 //select statement 27 enum MySqlStatementType SELECT = MySqlStatementType("SQLSelectStatement"); 28 //update statement 29 enum MySqlStatementType UPDATE = MySqlStatementType("MySqlUpdateStatement"); 30 //insert statement 31 enum MySqlStatementType INSERT = MySqlStatementType("MySqlInsertStatement"); 32 //delete statement 33 enum MySqlStatementType DELETE = MySqlStatementType("MySqlDeleteStatement"); 34 //while statement 35 enum MySqlStatementType WHILE = MySqlStatementType("SQLWhileStatement"); 36 //begin-end 37 enum MySqlStatementType IF = MySqlStatementType("SQLIfStatement"); 38 //begin-end 39 enum MySqlStatementType LOOP = MySqlStatementType("SQLLoopStatement"); 40 //begin-end 41 enum MySqlStatementType BLOCK = MySqlStatementType("SQLBlockStatement"); 42 //declare statement 43 enum MySqlStatementType DECLARE = MySqlStatementType("MySqlDeclareStatement"); 44 //select into 45 enum MySqlStatementType SELECTINTO = MySqlStatementType("MySqlSelectIntoStatement"); 46 //case 47 enum MySqlStatementType CASE = MySqlStatementType("MySqlCaseStatement"); 48 49 enum MySqlStatementType UNDEFINED = MySqlStatementType(""); 50 51 static MySqlStatementType[] _types; 52 53 // static this() 54 // { 55 // _types = [SELECT,UPDATE,INSERT,DELETE,WHILE,IF,LOOP,BLOCK,DECLARE,SELECTINTO,CASE,UNDEFINED]; 56 // } 57 58 static MySqlStatementType[] values() 59 { 60 return _types; 61 } 62 63 public string name; 64 65 // this(){ 66 // this(""); 67 // } 68 69 this(string name){ 70 this.name = name; 71 } 72 public static MySqlStatementType getType(SQLStatement stmt) 73 { 74 foreach (MySqlStatementType type ; MySqlStatementType.values()) { 75 if (type.name == typeof(stmt).stringof) { 76 return type; 77 } 78 } 79 return UNDEFINED; 80 } 81 82 bool opEquals(const MySqlStatementType h) nothrow { 83 return name == h.name ; 84 } 85 86 bool opEquals(ref const MySqlStatementType h) nothrow { 87 return name == h.name ; 88 } 89 }