public override SqlExpression VisitTrimFunction(PlSqlParser.TrimFunctionContext context) { var arg1 = SqlParseExpression.Build(context.concatenationWrapper()); var part = "both"; if (context.LEADING() != null) { part = "leading"; } else if (context.TRAILING() != null) { part = "trailing"; } else if (context.BOTH() != null) { part = "both"; } var toTrim = " "; if (context.quoted_string() != null) { toTrim = SqlParseInputString.AsNotQuoted(context.quoted_string()); } var arg2 = SqlExpression.Constant(SqlObject.String(part)); var arg3 = SqlExpression.Constant(SqlObject.String(toTrim)); return(SqlExpression.Function("SQL_TRIM", new SqlExpression[] { arg1, arg2, arg3 })); }
public override SqlStatement VisitCreateUserStatement(PlSqlParser.CreateUserStatementContext context) { var userName = context.userName().GetText(); string arg; IUserIdentificationInfo id; if (context.byPassword() != null) { arg = SqlParseInputString.AsNotQuoted(context.byPassword().CHAR_STRING().GetText()); id = new PasswordIdentificationInfo(arg); } else if (context.externalId() != null) { arg = SqlParseInputString.AsNotQuoted(context.externalId().CHAR_STRING().GetText()); throw new NotSupportedException("EXTERNAL identification not supported yet"); } else if (context.globalId() != null) { arg = SqlParseInputString.AsNotQuoted(context.globalId().CHAR_STRING().GetText()); throw new NotSupportedException("GLOBAL identification not supported yet"); } else { throw new ParseCanceledException("Invalid identification option"); } AddStatement(context, new CreateUserStatement(userName, id)); return(base.VisitCreateUserStatement(context)); }
public override SqlExpression VisitTimeStampFunction(PlSqlParser.TimeStampFunctionContext context) { SqlExpression arg; if (context.bind_variable() != null) { arg = SqlExpression.Variable(SqlParseName.Variable(context.bind_variable())); } else if (context.argString != null) { arg = SqlExpression.Constant(SqlObject.String(SqlParseInputString.AsNotQuoted(context.argString))); } else { throw new ParseCanceledException("Invalid argument in a TIMESTAMP implicit function"); } SqlExpression tzArg = null; if (context.tzString != null) { tzArg = SqlExpression.Constant(SqlObject.String(SqlParseInputString.AsNotQuoted(context.tzString))); } var args = tzArg != null ? new SqlExpression[] { arg, tzArg } : new SqlExpression[] { arg }; return(SqlExpression.Function("TOTIMESTAMP", args)); }
public static string Simple(PlSqlParser.IdContext context) { if (context == null) { return(null); } return(SqlParseInputString.AsNotQuoted(context.GetText())); }
public override SqlExpression VisitDateImplicitConvert(PlSqlParser.DateImplicitConvertContext context) { var s = SqlParseInputString.AsNotQuoted(context.quoted_string()); return(SqlExpression.Function("CAST", new SqlExpression[] { SqlExpression.Constant(SqlObject.String(s)), SqlExpression.Constant(SqlObject.String("DATE")) })); }
public static ObjectName Object(PlSqlParser.ObjectNameContext context) { if (context == null) { return(null); } var parts = context.id().Select(x => x.GetText()).ToArray(); var realParts = new List <string>(); foreach (var part in parts) { if (!String.IsNullOrEmpty(part)) { var sp = part.Split('.'); foreach (var s in sp) { realParts.Add(s); } } } parts = realParts.ToArray(); ObjectName name = null; for (int i = 0; i < parts.Length; i++) { var part = SqlParseInputString.AsNotQuoted(parts[i]); if (name == null) { name = new ObjectName(part); } else { name = new ObjectName(name, part); } } return(name); }
public override SqlExpression VisitConstantString(PlSqlParser.ConstantStringContext context) { var value = SqlParseInputString.AsNotQuoted(context.quoted_string()); return(SqlExpression.Constant(SqlObject.String(value))); }
public override SqlTypeResolveInfo VisitStringType(PlSqlParser.StringTypeContext context) { int?size = null; if (context.numeric() != null) { size = SqlParseNumber.PositiveInteger(context.numeric()); } else if (context.MAX() != null) { size = SqlCharacterType.DefaultMaxSize; } SqlTypeCode typeCode; if (context.CHAR() != null) { typeCode = SqlTypeCode.Char; } else if (context.VARCHAR() != null) { typeCode = SqlTypeCode.VarChar; } else if (context.STRING() != null) { typeCode = SqlTypeCode.String; } else if (context.CLOB() != null) { typeCode = SqlTypeCode.Clob; } else if (!context.longVarchar().IsEmpty) { typeCode = SqlTypeCode.LongVarChar; } else { throw new ParseCanceledException("Invalid string type"); } string locale = null; if (context.LOCALE() != null) { locale = SqlParseInputString.AsNotQuoted(context.locale.Text); } var meta = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); if (size != null) { meta.Add("MaxSize", size); meta.Add("Size", size); } if (locale != null) { meta.Add("Locale", locale); } return(new SqlTypeResolveInfo(typeCode.ToString().ToUpperInvariant(), meta)); }