/// <summary> /// Unwraps a variable context and returns the variable name. /// </summary> /// <param name="context"></param> /// <returns></returns> public static string Unwrap(this TSQLParser.VariableContext context) { var parameterName = context; var parameterPart = Unwrap( parameterName.Identifier() != null ? parameterName.Identifier().GetText() : parameterName.keyword().GetText()); return(string.Join("", context.AT().Select(a => "@")) + parameterPart); }
/// <summary> /// Visit a parse tree produced by <see cref="TSQLParser.variable" />. /// </summary> /// <param name="context">The parse tree.</param> /// <returns></returns> /// <return>The visitor result.</return> public override object VisitVariable(TSQLParser.VariableContext context) { var variableName = context.GetText(); if (variableName.StartsWith("@@")) { } else if (ConfirmConsistency(context)) { ReplaceText( context.Start.Line, context.Start.Column, context.GetText(), PortVariableName(variableName), true); } return(base.VisitVariable(context)); }
/// <summary> /// Visits the variable. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override Type VisitVariable(TSQLParser.VariableContext context) { if (_variables == null) { return(typeof(void)); } var variableName = context.Unwrap(); var variableDecl = _variables.Get(variableName); if (variableDecl == null) { return(typeof(void)); } if (variableDecl.TABLE() != null) { return(typeof(IDataRecord)); } return(VisitType(variableDecl.type())); }
/// <summary> /// Determines whether the variable context represents the special rowcount variable. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public static bool IsRowCountVariable(this TSQLParser.VariableContext context) { return(IsSpecialVariable(context) && string.Equals(context.Unwrap(), "@@rowcount", StringComparison.InvariantCultureIgnoreCase)); }
/// <summary> /// Determines whether [is special variable] [the specified context]. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public static bool IsSpecialVariable(this TSQLParser.VariableContext context) { return (context.AT() != null && context.AT().Length == 2); }