public override Result VisitPlainText([NotNull] PlainTextContext context) { var sqlText = SqlTextUtil.Parse(context.GetToken(SQLText, 0).GetText()); var csharpText = SqlTextUtil.ToCSharpString(sqlText); _writer.WriteIndentLine($"sb.Append({csharpText});"); return(Result.Ok()); }
private Result WriteMacroParameters(MacroParameterContext[] parameterCtxs) { for (var i = 0; i < parameterCtxs.Length; ++i) { var parameter = parameterCtxs[i]; if (parameter.nsSyntax() != null) { _writer.Write( SqlTextUtil.ToCSharpString(parameter.nsSyntax().GetText())); } else if (parameter.STRING() != null) { var result = StringUtil.Parse(parameter.STRING().GetText()); if (result.IsFailure) { return(result); } _writer.Write(SqlTextUtil.ToCSharpString(result.Value)); } else if (parameter.NUMBER() != null) { // sdmap number are compatible with C# double _writer.Write(parameter.NUMBER().GetText()); } else if (parameter.DATE() != null) { var result = DateUtil.Parse(parameter.DATE().GetText()); if (result.IsFailure) { return(result); } var date = result.Value; _writer.Write( $"new DateTime({date.Year}, {date.Month}, {date.Day})"); } else if (parameter.Bool() != null) { // sdmap bool are compatible with C# bool _writer.Write(parameter.Bool().GetText()); } else if (parameter.unnamedSql() != null) { var parseTree = parameter.unnamedSql(); var id = NameUtil.GetFunctionName(parseTree); if (!_unnamedSqls.ContainsKey(id)) { _unnamedSqls[id] = (writer) => { return(Visit(parseTree.coreSql())); }; } _writer.Write($"{id}()"); } // every parameter should follow by a "," separator, // except last parameter. if (i < parameterCtxs.Length - 1) { _writer.Write(", "); } } _writer.WriteLine(");"); return(Result.Ok()); }