|
1 | | -using SqlServerSimulator.Parser; |
2 | | -using SqlServerSimulator.Parser.Tokens; |
| 1 | +using SqlServerSimulator.Parser.Tokens; |
3 | 2 | using System.Data; |
4 | 3 | using System.Globalization; |
5 | 4 |
|
@@ -31,17 +30,36 @@ private protected DataType() |
31 | 30 |
|
32 | 31 | public static readonly DataType BuiltInDbSystemName = new DbSystemName(); |
33 | 32 |
|
34 | | - public static DataType GetByName(Name name) |
| 33 | + /// <summary> |
| 34 | + /// Looks up the <see cref="DataType"/> for the provided type name. |
| 35 | + /// </summary> |
| 36 | + /// <param name="name">The name of the type.</param> |
| 37 | + /// <param name="index">The 1-based index of the type, used for an error message.</param> |
| 38 | + /// <returns>The matching data type.</returns> |
| 39 | + /// <exception cref="SimulatedSqlException">Column, parameter, or variable #<paramref name="index"/>: Cannot find data type <paramref name="name"/>.</exception> |
| 40 | + public static DataType GetByName(Name name, int index) |
35 | 41 | { |
36 | | - var keyword = name.Parse(); |
37 | | - return keyword switch |
| 42 | + Span<char> upper = stackalloc char[name.Value.Length]; |
| 43 | + return name.Value.ToUpperInvariant(upper) switch |
38 | 44 | { |
39 | | - Keyword.Bit => BuiltInDbBoolean, |
40 | | - Keyword.TinyInt => BuiltInDbByte, |
41 | | - Keyword.SmallInt => BuiltInDbInt16, |
42 | | - Keyword.Int => BuiltInDbInt32, |
43 | | - _ => throw new NotSupportedException($"Simulated data type parser doesn't recognize {keyword}"), |
44 | | - }; |
| 45 | + 3 => upper switch |
| 46 | + { |
| 47 | + "BIT" => BuiltInDbBoolean, |
| 48 | + "INT" => BuiltInDbInt32, |
| 49 | + _ => null |
| 50 | + }, |
| 51 | + 7 => upper switch |
| 52 | + { |
| 53 | + "TINYINT" => BuiltInDbByte, |
| 54 | + _ => null |
| 55 | + }, |
| 56 | + 8 => upper switch |
| 57 | + { |
| 58 | + "SMALLINT" => BuiltInDbInt16, |
| 59 | + _ => null |
| 60 | + }, |
| 61 | + _ => null, |
| 62 | + } ?? throw SimulatedSqlException.CannotFindDataType(name.Value, index); |
45 | 63 | } |
46 | 64 |
|
47 | 65 | public static DataType GetByDbType(DbType dbType) => dbType switch |
|
0 commit comments