internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			SqlColumn mapped;
			if(this.map.TryGetValue(cref.Column, out mapped))
			{
				return new SqlColumnRef(mapped);
			}
			return cref;
		}
예제 #2
0
			internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
			{
				SqlColumnRef result = this.BubbleUp(cref);
				if(result == null)
				{
					throw Error.ColumnReferencedIsNotInScope(GetColumnName(cref.Column));
				}
				return result;
			}
예제 #3
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			SqlExpression result = base.VisitColumnRef(cref);
			if(result == cref)
			{ // must be external
				return ExtractParameter(result);
			}
			return result;
		}
예제 #4
0
			internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
			{
				SqlExpression literal = this.GetLiteralValue(cref);
				if(literal != null)
				{
					return literal;
				}
				return cref;
			}
			internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
			{
				if(!this.columns.Contains(cref.Column))
				{
					this.columns.Add(cref.Column);
					if(cref.Column.Expression != null)
					{
						this.Visit(cref.Column.Expression);
					}
				}
				return cref;
			}
			internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
			{
				if(this.parent.aliases.Contains(cref.Column.Alias))
				{
					this.parent.referencesAny = true;
				}
				else if(cref.Column.Expression != null)
				{
					this.Visit(cref.Column.Expression);
				}
				return cref;
			}
예제 #7
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			SqlColumn c = this.FindColumn(this.row.Columns, cref.Column);
			if(c == null)
			{
				return MakeFlattenedColumn(cref, null);
			}
			else
			{
				return new SqlColumnRef(c);
			}
		}
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref) {
			SqlExpression result = base.VisitColumnRef(cref);
			if (result != null && result == cref) {
				// reference to outer scope, don't propogate references to expressions or aliases
				SqlColumn col = cref.Column;
				SqlColumn newcol = new SqlColumn(col.ClrType, col.SqlType, col.Name, col.MetaMember, null, col.SourceExpression);
				newcol.Ordinal = col.Ordinal;
				result = new SqlColumnRef(newcol);
				newcol.ClearSourceExpression();
			}
			return result;
		}
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			if(this.aliasesToCheck.Contains(cref.Column.Alias))
			{
				this.hasDependency = true;
			}
			else if(cref.Column.Expression != null)
			{
				this.Visit(cref.Column.Expression);
			}
			return cref;
		}
예제 #10
0
			private SqlColumnRef BubbleUp(SqlColumnRef cref)
			{
				for(SqlScope s = this.CurrentScope; s != null; s = s.ContainingScope)
				{
					if(s.Source != null)
					{
						SqlColumn found = this.bubbler.BubbleUp(cref.Column, s.Source);
						if(found != null)
						{
							if(found != cref.Column)
								return new SqlColumnRef(found);
							return cref;
						}
					}
				}
				return null;
			}
예제 #11
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			if(cref.Column.Alias != null && _removedMap.ContainsKey(cref.Column.Alias))
			{
				SqlColumnRef c = cref.Column.Expression as SqlColumnRef;
				if(c != null)
				{
					//The following code checks for cases where there are differences between the type returned
					//by a ColumnRef and the column that refers to it.  This situation can occur when conversions
					//are optimized out of the SQL node tree.  As mentioned in the SetClrType comments this is not 
					//an operation that can have adverse effects and should only be used in limited cases, such as
					//this one.
					if(c.ClrType != cref.ClrType)
					{
						c.SetClrType(cref.ClrType);
						return this.VisitColumnRef(c);
					}
				}
				return c;
			}
			return cref;
		}
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			VisitAliasConsumed(cref.Column.Alias);
			return cref;
		}
예제 #13
0
			internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
			{
				SqlColumnRef mapped;
				return this.map.TryGetValue(cref.Column, out mapped) ? mapped : cref;
			}
예제 #14
0
		private SqlSelect GenerateSkipTake(SqlSelect sequence, SqlExpression skipExp, SqlExpression takeExp)
		{
			SqlSelect select = this.LockSelect(sequence);

			// no skip?
			if(skipExp == null)
			{
				if(takeExp != null)
				{
					select.Top = takeExp;
				}
				return select;
			}

			SqlAlias alias = new SqlAlias(select);
			SqlAliasRef aref = new SqlAliasRef(alias);

			if(this.UseConverterStrategy(ConverterStrategy.SkipWithRowNumber))
			{
				// use ROW_NUMBER() (preferred)
				SqlColumn rowNumber = new SqlColumn("ROW_NUMBER", _nodeFactory.RowNumber(new List<SqlOrderExpression>(), _dominatingExpression));
				SqlColumnRef rowNumberRef = new SqlColumnRef(rowNumber);

				select.Row.Columns.Add(rowNumber);

				SqlSelect final = new SqlSelect(aref, alias, _dominatingExpression);

				if(takeExp != null)
				{
					// use BETWEEN for skip+take combo (much faster)
					final.Where = _nodeFactory.Between(
						rowNumberRef,
						_nodeFactory.Add(skipExp, 1),
						_nodeFactory.Binary(SqlNodeType.Add, (SqlExpression)SqlDuplicator.Copy(skipExp), takeExp),
						_dominatingExpression
						);
				}
				else
				{
					final.Where = _nodeFactory.Binary(SqlNodeType.GT, rowNumberRef, skipExp);
				}

				return final;
			}
			else
			{
				// Ensure that the sequence contains elements that can be skipped
				if(!CanSkipOnSelection(select.Selection))
				{
					throw Error.SkipNotSupportedForSequenceTypes();
				}

				// use NOT EXISTS

				// Supported cases:
				//  - Entities
				//  - Projections that contain all PK columns
				//
				// .. where there sequence can be traced back to a:
				//  - Single-table query
				//  - Distinct
				//  - Except
				//  - Intersect
				//  - Union, where union.All == false

				// Not supported: joins

				// Sequence should also be ordered, but we can't test for it at this 
				// point in processing, and we won't know that we need to test it, later.

				SingleTableQueryVisitor stqv = new SingleTableQueryVisitor();
				stqv.Visit(select);
				if(!stqv.IsValid)
				{
					throw Error.SkipRequiresSingleTableQueryWithPKs();
				}

				SqlSelect dupsel = (SqlSelect)SqlDuplicator.Copy(select);
				dupsel.Top = skipExp;

				SqlAlias dupAlias = new SqlAlias(dupsel);
				SqlAliasRef dupRef = new SqlAliasRef(dupAlias);

				SqlSelect eqsel = new SqlSelect(dupRef, dupAlias, _dominatingExpression);
				eqsel.Where = _nodeFactory.Binary(SqlNodeType.EQ2V, aref, dupRef);
				SqlSubSelect ss = _nodeFactory.SubSelect(SqlNodeType.Exists, eqsel);

				SqlSelect final = new SqlSelect(aref, alias, _dominatingExpression);
				final.Where = _nodeFactory.Unary(SqlNodeType.Not, ss, _dominatingExpression);
				final.Top = takeExp;

				return final;
			}
		}
예제 #15
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			return cref;
		}
예제 #16
0
 internal override SqlExpression VisitColumnRef(SqlColumnRef cref) {
     this.VisitColumn(cref.Column); // Travel through column references
     return cref;
 }
예제 #17
0
		private Type GenerateColumnReference(SqlColumnRef cref)
		{
			this.GenerateColumnAccess(cref.ClrType, cref.SqlType, cref.Column.Ordinal, null);
			return cref.ClrType;
		}
예제 #18
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			if(this.ingoreExternalRefs && !this.nodeMap.ContainsKey(cref.Column))
			{
				return cref;
			}
			return new SqlColumnRef((SqlColumn)this.Visit(cref.Column));
		}
예제 #19
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			if(expressionSink != null)
			{
				expressionSink.ReferencedExpressions.Add(cref.Column);
			}
			return cref;
		}
예제 #20
0
		private static SqlColumn GetBaseColumn(SqlColumnRef cref)
		{
			while(cref != null && cref.Column.Expression != null)
			{
				SqlColumnRef cr = cref.Column.Expression as SqlColumnRef;
				if(cr != null)
				{
					cref = cr;
					continue;
				}
				break;
			}
			return cref.Column;
		}
예제 #21
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			string aliasName = null;
			SqlColumn c = cref.Column;
			SqlAlias alias = c.Alias;
			if(alias == null)
			{
				_aliasMap.TryGetValue(c, out alias);
			}
			if(alias != null)
			{
				if(alias.Name == null)
				{
					if(!_names.TryGetValue(alias, out aliasName))
					{
						aliasName = "A" + _names.Count;
						_names[c.Alias] = aliasName;
					}
				}
				else
				{
					aliasName = c.Alias.Name;
				}
			}
			if(!_suppressedAliases.Contains(c.Alias) && aliasName != null && aliasName.Length != 0)
			{
				this.WriteName(aliasName);
				_commandStringBuilder.Append(".");
			}
			string name = c.Name;
			string inferredName = this.InferName(c.Expression, null);
			if(name == null)
				name = inferredName;
			if(name == null)
			{
				if(!_names.TryGetValue(c, out name))
				{
					name = "C" + _names.Count;
					_names[c] = name;
				}
			}
			this.WriteName(name);
			return cref;
		}
예제 #22
0
 internal virtual SqlExpression VisitColumnRef(SqlColumnRef cref) {
     return cref;
 }
예제 #23
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			_referenceMap[cref.Column] = cref.Column;
			return cref;
		}
예제 #24
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			if(cref.Column.Name == null && this.lastName != null)
			{
				cref.Column.Name = this.lastName;
			}
			return cref;
		}
예제 #25
0
        public override bool Equals(object obj)
        {
            SqlColumnRef cref = obj as SqlColumnRef;

            return(cref != null && cref.Column == this.column);
        }
예제 #26
0
		internal override SqlExpression VisitColumnRef(SqlColumnRef cref)
		{
			Visit(cref.Column);

			return base.VisitColumnRef(cref);
		}