18 using System.Collections.Generic;
26 namespace Deveel.Data.Sql.Statements {
29 var index = column.IndexOf(
'.');
32 var columnPrefix = column.Substring(0, index);
33 if (!columnPrefix.Equals(tableDomain))
34 throw new InvalidOperationException(String.Format(
"Column '{0}' is not within the expected table'{1}'",
35 column, tableDomain));
37 column = column.Substring(index + 1);
43 public IEnumerable<string>
StripColumnList(
string tableDomain, IEnumerable<string> columnList) {
44 return columnList.Select(x => StripTableName(tableDomain, x));
47 public abstract string ResolveColumnName(
string columnName);
51 return expChecker.Visit(expression);
54 public IEnumerable<string>
CheckColumns(IEnumerable<string> columnNames) {
55 var result =
new List<string>();
57 foreach (var columnName
in columnNames) {
58 var resolved = ResolveColumnName(columnName);
60 throw new InvalidOperationException(String.Format(
"Column '{0}' not found in table.", columnName));
65 return result.ToArray();
69 var table = context.
Query.GetTable(tableName);
71 throw new InvalidOperationException(String.Format(
"Table '{0}' not found in the context.", tableName));
73 var tableInfo = table.TableInfo;
74 var ignoreCase = context.
Query.IgnoreIdentifiersCase();
79 #region DefaultChecker
86 this.tableInfo = tableInfo;
87 this.ignoreCase = ignoreCase;
91 var comparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
92 string foundColumn = null;
94 foreach (var columnInfo
in tableInfo) {
95 if (foundColumn != null)
96 throw new InvalidOperationException(String.Format(
"Column name '{0}' caused an ambiguous match in table.", columnName));
98 if (String.Equals(columnInfo.ColumnName, columnName, comparison))
99 foundColumn = columnInfo.ColumnName;
108 #region ExpressionChecker
114 this.checker = checker;
119 var origColumn = refName.
Name;
120 var resolvedColumn = checker.ResolveColumnName(origColumn);
121 if (resolvedColumn == null)
122 throw new InvalidOperationException(String.Format(
"Column '{0} not found in table.", origColumn));
124 if (!origColumn.Equals(resolvedColumn))
125 refName =
new ObjectName(refName.Parent, resolvedColumn);
131 throw new InvalidOperationException(
"Sub-queries are not permitted in a CHECK expression.");
ObjectName ReferenceName
Gets the name of the object referenced by the expression.
An expression that references an object within a context.
IEnumerable< string > CheckColumns(IEnumerable< string > columnNames)
string StripTableName(string tableDomain, string column)
Describes the name of an object within a database.
override string ResolveColumnName(string columnName)
override SqlExpression VisitQuery(SqlQueryExpression query)
readonly ColumnChecker checker
DefaultChecker(TableInfo tableInfo, bool ignoreCase)
ExpressionChecker(ColumnChecker checker)
IEnumerable< string > StripColumnList(string tableDomain, IEnumerable< string > columnList)
static ColumnChecker Default(IRequest context, ObjectName tableName)
string Name
Gets the name of the object being referenced.
static SqlReferenceExpression Reference(ObjectName objectName)
SqlExpression CheckExpression(SqlExpression expression)
Defines the base class for instances that represent SQL expression tree nodes.
override SqlExpression VisitReference(SqlReferenceExpression reference)
Defines the metadata properties of a table existing within a database.
A visitor for SqlExpression objects.
readonly TableInfo tableInfo