private static bool ReadSub1Number(LexemCollection collection, out int i1) { i1 = 0; var lex = collection.GetNext(); if (lex != null && lex.IsSkobraOpen()) { collection.GotoNextMust(); lex = collection.GotoNextMust(); if (lex.LexemType == LexType.Number) { i1 = int.Parse(lex.LexemText); } else if (lex.LexemType == LexType.Command) { if (lex.LexemText.ToLower() == "max") { i1 = 0; } } else { collection.ErrorUnexpected(collection.CurrentOrLast()); } lex = collection.GotoNextMust(); if (lex == null || !lex.IsSkobraClose()) { collection.ErrorUnexpected(collection.CurrentOrLast()); } return(true); } return(false); }
private static bool ReadSub2Number(LexemCollection collection, out int i1, out int i2) { i1 = 0; i2 = 0; var lex = collection.GetNext(); if (lex != null && lex.IsSkobraOpen()) { collection.GotoNextMust(); lex = collection.GotoNextMust(); if (lex.LexemType == LexType.Number) { i1 = int.Parse(lex.LexemText); } else { collection.ErrorUnexpected(collection.CurrentOrLast()); } lex = collection.GotoNextMust(); if (lex == null) { collection.ErrorUnexpected(collection.CurrentOrLast()); } if (lex.LexemType == LexType.Zpt) { lex = collection.GotoNextMust(); if (lex.LexemType != LexType.Number) { collection.ErrorUnexpected(collection.CurrentOrLast()); } i2 = int.Parse(lex.LexemText); lex = collection.GotoNextMust(); } if (lex == null || !lex.IsSkobraClose()) { collection.ErrorUnexpected(collection.CurrentOrLast()); } return(true); } return(false); }
/// <summary> /// Читаем название колонки в текущей лексеме. Может быть name, "name", [name] /// </summary> /// <param name="collection"></param> /// <returns></returns> public static string ReadColumnNameOnly(LexemCollection collection) { if (collection.CurrentLexem() == null) { collection.Error("Alias not found", collection.CurrentOrLast()); } if (collection.CurrentLexem().LexemType == LexType.Command) { var r = collection.CurrentLexem().LexemText; return(r); } if (collection.CurrentLexem().LexemType == LexType.Text) { var strs = ParserUtils.ParseStringQuote(collection.CurrentLexem().LexemText); if (strs.Length != 1) { collection.Error("Composite column name", collection.CurrentLexem()); } return(strs[0]); } collection.Error("Column not found", collection.CurrentLexem()); return(null); }
public static ExactType?Parse(LexemCollection collection) { ExactType res; var lex = collection.CurrentLexem(); if (lex.LexemType != LexType.Command) { collection.Error("Unknow data type", collection.CurrentLexem()); } string s = lex.LexemText.ToLower(); DbColumnType tp = DbColumnType.Unknow; int param1 = 0; int param2 = 0; switch (s) { case "datetime": tp = DbColumnType.DateTime; ReadSub1Number(collection, out param1); //ignore break; case "timestamp": tp = DbColumnType.DateTime; if (ParserUtils.ParseCommandPhrase(collection, "timestamp without time zone", true, false)) { tp = DbColumnType.DateTime; } if (ParserUtils.ParseCommandPhrase(collection, "timestamp with time zone", true, false)) { tp = DbColumnType.DateTimeWithTimeZone; } ReadSub1Number(collection, out param1); //ignore break; case "date": tp = DbColumnType.Date; ReadSub1Number(collection, out param1); //ignore break; case "time": tp = DbColumnType.Time; if (ParserUtils.ParseCommandPhrase(collection, "time without time zone", true, false)) { tp = DbColumnType.Time; } if (ParserUtils.ParseCommandPhrase(collection, "time with time zone", true, false)) { tp = DbColumnType.TimeWithTimeZome; } ReadSub1Number(collection, out param1); //ignore break; case "int8": case "byte": case "tinyint": tp = DbColumnType.Byte; break; case "int16": case "smallint": tp = DbColumnType.SmallInt; break; case "int32": case "integer": case "int": tp = DbColumnType.Integer; break; case "float": case "real": tp = DbColumnType.Real; ReadSub1Number(collection, out param1); //ignore break; case "double": ParserUtils.ParseCommandPhrase(collection, "double precision"); tp = DbColumnType.Double; break; case "bigint": case "int64": tp = DbColumnType.BigInt; break; case "decimal": case "numeric": tp = DbColumnType.Numeric; ReadSub2Number(collection, out param1, out param2); break; case "nvarchar": case "varchar": tp = DbColumnType.VarChar; if (ReadSub1Number(collection, out param1)) { if (param1 == 0) { tp = DbColumnType.Text; } } break; case "nchar": case "char": tp = DbColumnType.VarChar; if (!ReadSub1Number(collection, out param1)) { collection.ErrorUnexpected(collection.CurrentOrLast()); } break; case "character": tp = DbColumnType.Char; if (ParserUtils.ParseCommandPhrase(collection, "character varying")) { tp = DbColumnType.VarChar; } if (!ReadSub1Number(collection, out param1)) { collection.ErrorUnexpected(collection.CurrentOrLast()); } break; case "text": tp = DbColumnType.Text; break; case "blob": tp = DbColumnType.Blob; break; case "bit": case "bool": case "boolean": tp = DbColumnType.Boolean; break; case "geometry": tp = DbColumnType.Geometry; break; case "geography": tp = DbColumnType.Geography; break; default: return(null); } res = ExactType.Create(tp); if (tp == DbColumnType.Numeric) { res.Precision = param1; res.Scale = param2; } if (tp == DbColumnType.Char || tp == DbColumnType.VarChar) { res.MaxTextLength = param1; } return(res); }