You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Data/Sql/TSqlLanguage.cs

53 lines
1.3 KiB

2 years ago
using Connected.Expressions;
using Connected.Expressions.Languages;
using Connected.Expressions.Translation;
using Connected.Expressions.TypeSystem;
namespace Connected.Data.Sql;
internal sealed class TSqlLanguage : QueryLanguage
{
private static TSqlLanguage? _default;
static TSqlLanguage()
{
SplitChars = new char[] { '.' };
}
public TSqlLanguage()
{
TypeSystem = new SqlTypeSystem();
}
public override QueryTypeSystem TypeSystem { get; }
private static char[] SplitChars { get; }
public override bool AllowsMultipleCommands => true;
public override bool AllowSubqueryInSelectWithoutFrom => true;
public override bool AllowDistinctInAggregates => true;
public static TSqlLanguage Default
{
get
{
if (_default is null)
Interlocked.CompareExchange(ref _default, new TSqlLanguage(), null);
return _default;
}
}
public override string Quote(string name)
{
if (name.StartsWith("[") && name.EndsWith("]"))
return name;
else if (name.Contains('.'))
return $"[{string.Join("].[", name.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries))}]";
else
return $"[{name}]";
}
public override Linguist CreateLinguist(ExpressionCompilationContext context, Translator translator)
{
return new TSqlLinguist(context, this, translator);
}
}