private void checkTryCatchClause(procedureInfo procedureInfo, TMssqlCreateProcedure procedure) { TSourceTokenList tokenList = procedure.sourcetokenlist; for (int i = 0; i < tokenList.size(); i++) { TSourceToken token = tokenList.get(i); if (token.tokentype == ETokenType.ttkeyword && token.astext.Trim().Equals("try", StringComparison.OrdinalIgnoreCase)) { procedureInfo.hasTryCatch = true; } } }
private static bool verifyTokens(TSourceTokenList originalTokens, TSourceTokenList targetTokens, bool partialChecking) { bool result = true; int old = 0; bool startParenthesis = false; int nestedParenthesis = 0; for (int i = 0; i < targetTokens.size(); i++) { if (targetTokens.get(i).tokentype == ETokenType.ttkeyword) { // must a space after keyword if (i != targetTokens.size() - 1) { if ((targetTokens.get(i + 1).tokencode == TBaseType.lexnewline) || (targetTokens.get(i + 1).tokencode == TBaseType.lexspace) || (targetTokens.get(i + 1).tokencode < 127)) { continue; } else { Console.Write("lack space after keyword:" + targetTokens.get(i).ToString()); result = false; break; } } } if (targetTokens.get(i).tokentype == ETokenType.ttidentifier) { // must a space between identifier and keyword/identifier if (i != 0) { if ((targetTokens.get(i - 1).tokentype == ETokenType.ttkeyword) || (targetTokens.get(i - 1).tokentype == ETokenType.ttidentifier)) { Console.Write("lack space between identifier and keyword:" + targetTokens.get(i).ToString()); result = false; break; } else { continue; } } } } if (!result) { return(result); } for (int i = 0; i < originalTokens.size(); i++) { if ((originalTokens.get(i).tokencode == TBaseType.lexnewline) || (originalTokens.get(i).tokencode == TBaseType.lexspace) || (originalTokens.get(i).tokentype == ETokenType.ttsimplecomment) || ((originalTokens.get(i).tokentype == ETokenType.ttbracketedcomment) && (!originalTokens.get(i).ToString().StartsWith("/*+", StringComparison.Ordinal))) || (originalTokens.get(i).tokentype == ETokenType.ttsemicolon)) { continue; } if (partialChecking) { if (originalTokens.get(i).tokencode == '(') { startParenthesis = true; nestedParenthesis++; } else if (originalTokens.get(i).tokencode == ')') { if (nestedParenthesis > 0) { nestedParenthesis--; } if ((nestedParenthesis == 0) && startParenthesis) { result = true; break; } } } result = false; for (int j = old; j < targetTokens.size(); j++) { if ((targetTokens.get(j).tokencode == TBaseType.lexnewline) || (targetTokens.get(j).tokencode == TBaseType.lexspace) || (targetTokens.get(j).tokentype == ETokenType.ttsimplecomment) || ((targetTokens.get(j).tokentype == ETokenType.ttbracketedcomment) && (!targetTokens.get(i).ToString().StartsWith("/*+", StringComparison.Ordinal))) || (targetTokens.get(j).tokentype == ETokenType.ttsemicolon)) { continue; } if ((originalTokens.get(i).tokencode == TBaseType.outer_join) && (targetTokens.get(j).tokencode == TBaseType.outer_join)) { result = true; } else { result = originalTokens.get(i).ToString().Equals(targetTokens.get(j).ToString(), StringComparison.CurrentCultureIgnoreCase); } old = j + 1; break; } if (!result) { Console.Write("source token:" + originalTokens.get(i).ToString() + "(" + originalTokens.get(i).lineNo + "," + originalTokens.get(i).columnNo + ")"); Console.Write(", target token:" + targetTokens.get(old - 1).ToString() + "(" + targetTokens.get(old - 1).lineNo + "," + targetTokens.get(old - 1).columnNo + ")"); break; } // if (! result) break; } return(result); }
private void checkFunction(spInfo spInfo, TSourceTokenList tokenList) { for (int i = 0; i < tokenList.size(); i++) { TSourceToken token = tokenList.get(i); if (token.DbObjType == EDbObjectType.function) { List <TParseTreeNode> list = token.nodesStartFromThisToken; for (int j = 0; j < list.Count; j++) { TParseTreeNode node = (TParseTreeNode)list[j]; if (node is TFunctionCall) { builtInFunctionInfo function = new builtInFunctionInfo(); function.function = token.astext; function.lineNo = token.lineNo; function.columnNo = token.columnNo; TCustomSqlStatement stmt = token.stmt; if (stmt == null) { bool flag = false; for (int k = token.posinlist - 1; k >= 0; k--) { TSourceToken before = node.Gsqlparser.sourcetokenlist.get(k); if (token.nodesStartFromThisToken != null) { for (int z = 0; z < before.nodesStartFromThisToken.Count; z++) { if (before.nodesStartFromThisToken[z] is TCustomSqlStatement) { TCustomSqlStatement tempStmt = (TCustomSqlStatement)before.nodesStartFromThisToken[z]; if (tempStmt.startToken.posinlist <= token.posinlist && tempStmt.endToken.posinlist >= token.posinlist) { stmt = tempStmt; flag = true; break; } } } } if (flag) { break; } } } if (stmt is TInsertSqlStatement) { function.stmtType = usageType.Insert; } else if (stmt is TSelectSqlStatement) { function.stmtType = usageType.Read; } else if (stmt is TUpdateSqlStatement) { function.stmtType = usageType.Update; } else if (stmt is TDeleteSqlStatement) { function.stmtType = usageType.Delete; } else if (stmt is TMssqlDropTable) { function.stmtType = usageType.Drop; } else if (stmt is TDropTableSqlStatement) { function.stmtType = usageType.Drop; } else if (stmt is TMssqlExecute) { function.stmtType = usageType.Exec; } else if (stmt is TMssqlCreateProcedure) { function.stmtType = usageType.Create; } spInfo.functions.Add(function); } } } } }