Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DLinq / Dlinq / SqlClient / Query / SqlSupersetValidator.cs / 1 / SqlSupersetValidator.cs
using System; using System.Collections.Generic; using System.Text; namespace System.Data.Linq.SqlClient { ////// Validates the integrity of super-SQL trees. /// internal class SqlSupersetValidator { Listvalidators = new List (); /// /// Add a validator to the collection of validators to run. /// internal void AddValidator(SqlVisitor validator) { this.validators.Add(validator); } ////// Execute each current validator. /// internal void Validate(SqlNode node) { foreach (SqlVisitor validator in this.validators) { validator.Visit(node); } } } ////// Column ClrType must agree with the expression that it points to. /// internal class ColumnTypeValidator : SqlVisitor { internal override SqlRow VisitRow(SqlRow row) { for (int i = 0, n = row.Columns.Count; i < n; i++) { SqlColumn col = row.Columns[i]; SqlExpression expr = this.VisitExpression(col.Expression); if (expr != null) { if (TypeSystem.GetNonNullableType(col.ClrType) != TypeSystem.GetNonNullableType(expr.ClrType)) { throw Error.ColumnClrTypeDoesNotAgreeWithExpressionsClrType(); } } } return row; } } ////// A validator that ensures literal values are reasonable. /// internal class LiteralValidator : SqlVisitor { internal override SqlExpression VisitValue(SqlValue value) { if (!value.IsClientSpecified && value.ClrType.IsClass && value.ClrType != typeof(string) && value.ClrType != typeof(Type) && value.Value != null) { throw Error.ClassLiteralsNotAllowed(value.ClrType); } return value; } internal override SqlExpression VisitBinaryOperator(SqlBinary bo) { bo.Left = this.VisitExpression(bo.Left); return bo; } } ////// A validator which enforces rationalized boolean expressions. /// internal class ExpectRationalizedBooleans : SqlBooleanMismatchVisitor { internal ExpectRationalizedBooleans() { } internal override SqlExpression ConvertValueToPredicate(SqlExpression bitExpression) { throw Error.ExpectedPredicateFoundBit(); } internal override SqlExpression ConvertPredicateToValue(SqlExpression predicateExpression) { throw Error.ExpectedBitFoundPredicate(); } } ////// A validator which enforces that no more SqlMethodCall nodes exist in the tree. /// internal class ExpectNoMethodCalls : SqlVisitor { internal override SqlExpression VisitMethodCall(SqlMethodCall mc) { // eventually we may support this type of stuff given the SQL CLR, but for now it is illegal throw Error.MethodHasNoSupportConversionToSql(mc.Method.Name); } // check everything except selection expressions (which will be client or ignored) internal override SqlSelect VisitSelect(SqlSelect select) { select.From = this.VisitSource(select.From); select.Where = this.VisitExpression(select.Where); for (int i = 0, n = select.GroupBy.Count; i < n; i++) { select.GroupBy[i] = this.VisitExpression(select.GroupBy[i]); } select.Having = this.VisitExpression(select.Having); for (int i = 0, n = select.OrderBy.Count; i < n; i++) { select.OrderBy[i].Expression = this.VisitExpression(select.OrderBy[i].Expression); } select.Top = this.VisitExpression(select.Top); //select.Selection = this.VisitExpression(select.Selection); select.Row = (SqlRow)this.Visit(select.Row); return select; } } internal class ExpectNoFloatingColumns : SqlVisitor { internal override SqlRow VisitRow(SqlRow row) { foreach (SqlColumn c in row.Columns) { this.Visit(c.Expression); } return row; } internal override SqlTable VisitTable(SqlTable tab) { foreach (SqlColumn c in tab.Columns) { this.Visit(c.Expression); } return tab; } internal override SqlExpression VisitColumn(SqlColumn col) { throw Error.UnexpectedFloatingColumn(); } } internal class ExpectNoAliasRefs : SqlVisitor { internal override SqlExpression VisitAliasRef(SqlAliasRef aref) { throw Error.UnexpectedNode(aref.NodeType); } } internal class ExpectNoSharedExpressions : SqlVisitor { internal override SqlExpression VisitSharedExpression(SqlSharedExpression shared) { throw Error.UnexpectedSharedExpression(); } internal override SqlExpression VisitSharedExpressionRef(SqlSharedExpressionRef sref) { throw Error.UnexpectedSharedExpressionReference(); } } ////// Determines if there is a boolean NText/Text/Image comparison and if so throws an exception /// because this is not valid in SQLServer. /// internal class ValidateNoInvalidComparison : SqlVisitor { internal override SqlExpression VisitBinaryOperator(SqlBinary bo) { if (bo.NodeType == SqlNodeType.EQ || bo.NodeType == SqlNodeType.NE || bo.NodeType == SqlNodeType.EQ2V || bo.NodeType == SqlNodeType.NE2V || bo.NodeType == SqlNodeType.GT || bo.NodeType == SqlNodeType.GE || bo.NodeType == SqlNodeType.LT || bo.NodeType == SqlNodeType.LE ) { if (!bo.Left.SqlType.SupportsComparison || !bo.Right.SqlType.SupportsComparison){ throw Error.UnhandledStringTypeComparison(); } } bo.Left = this.VisitExpression(bo.Left); bo.Right = this.VisitExpression(bo.Right); return bo; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Text; namespace System.Data.Linq.SqlClient { ////// Validates the integrity of super-SQL trees. /// internal class SqlSupersetValidator { Listvalidators = new List (); /// /// Add a validator to the collection of validators to run. /// internal void AddValidator(SqlVisitor validator) { this.validators.Add(validator); } ////// Execute each current validator. /// internal void Validate(SqlNode node) { foreach (SqlVisitor validator in this.validators) { validator.Visit(node); } } } ////// Column ClrType must agree with the expression that it points to. /// internal class ColumnTypeValidator : SqlVisitor { internal override SqlRow VisitRow(SqlRow row) { for (int i = 0, n = row.Columns.Count; i < n; i++) { SqlColumn col = row.Columns[i]; SqlExpression expr = this.VisitExpression(col.Expression); if (expr != null) { if (TypeSystem.GetNonNullableType(col.ClrType) != TypeSystem.GetNonNullableType(expr.ClrType)) { throw Error.ColumnClrTypeDoesNotAgreeWithExpressionsClrType(); } } } return row; } } ////// A validator that ensures literal values are reasonable. /// internal class LiteralValidator : SqlVisitor { internal override SqlExpression VisitValue(SqlValue value) { if (!value.IsClientSpecified && value.ClrType.IsClass && value.ClrType != typeof(string) && value.ClrType != typeof(Type) && value.Value != null) { throw Error.ClassLiteralsNotAllowed(value.ClrType); } return value; } internal override SqlExpression VisitBinaryOperator(SqlBinary bo) { bo.Left = this.VisitExpression(bo.Left); return bo; } } ////// A validator which enforces rationalized boolean expressions. /// internal class ExpectRationalizedBooleans : SqlBooleanMismatchVisitor { internal ExpectRationalizedBooleans() { } internal override SqlExpression ConvertValueToPredicate(SqlExpression bitExpression) { throw Error.ExpectedPredicateFoundBit(); } internal override SqlExpression ConvertPredicateToValue(SqlExpression predicateExpression) { throw Error.ExpectedBitFoundPredicate(); } } ////// A validator which enforces that no more SqlMethodCall nodes exist in the tree. /// internal class ExpectNoMethodCalls : SqlVisitor { internal override SqlExpression VisitMethodCall(SqlMethodCall mc) { // eventually we may support this type of stuff given the SQL CLR, but for now it is illegal throw Error.MethodHasNoSupportConversionToSql(mc.Method.Name); } // check everything except selection expressions (which will be client or ignored) internal override SqlSelect VisitSelect(SqlSelect select) { select.From = this.VisitSource(select.From); select.Where = this.VisitExpression(select.Where); for (int i = 0, n = select.GroupBy.Count; i < n; i++) { select.GroupBy[i] = this.VisitExpression(select.GroupBy[i]); } select.Having = this.VisitExpression(select.Having); for (int i = 0, n = select.OrderBy.Count; i < n; i++) { select.OrderBy[i].Expression = this.VisitExpression(select.OrderBy[i].Expression); } select.Top = this.VisitExpression(select.Top); //select.Selection = this.VisitExpression(select.Selection); select.Row = (SqlRow)this.Visit(select.Row); return select; } } internal class ExpectNoFloatingColumns : SqlVisitor { internal override SqlRow VisitRow(SqlRow row) { foreach (SqlColumn c in row.Columns) { this.Visit(c.Expression); } return row; } internal override SqlTable VisitTable(SqlTable tab) { foreach (SqlColumn c in tab.Columns) { this.Visit(c.Expression); } return tab; } internal override SqlExpression VisitColumn(SqlColumn col) { throw Error.UnexpectedFloatingColumn(); } } internal class ExpectNoAliasRefs : SqlVisitor { internal override SqlExpression VisitAliasRef(SqlAliasRef aref) { throw Error.UnexpectedNode(aref.NodeType); } } internal class ExpectNoSharedExpressions : SqlVisitor { internal override SqlExpression VisitSharedExpression(SqlSharedExpression shared) { throw Error.UnexpectedSharedExpression(); } internal override SqlExpression VisitSharedExpressionRef(SqlSharedExpressionRef sref) { throw Error.UnexpectedSharedExpressionReference(); } } ////// Determines if there is a boolean NText/Text/Image comparison and if so throws an exception /// because this is not valid in SQLServer. /// internal class ValidateNoInvalidComparison : SqlVisitor { internal override SqlExpression VisitBinaryOperator(SqlBinary bo) { if (bo.NodeType == SqlNodeType.EQ || bo.NodeType == SqlNodeType.NE || bo.NodeType == SqlNodeType.EQ2V || bo.NodeType == SqlNodeType.NE2V || bo.NodeType == SqlNodeType.GT || bo.NodeType == SqlNodeType.GE || bo.NodeType == SqlNodeType.LT || bo.NodeType == SqlNodeType.LE ) { if (!bo.Left.SqlType.SupportsComparison || !bo.Right.SqlType.SupportsComparison){ throw Error.UnhandledStringTypeComparison(); } } bo.Left = this.VisitExpression(bo.Left); bo.Right = this.VisitExpression(bo.Right); return bo; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ChooseAction.cs
- WindowVisualStateTracker.cs
- ConfigurationProperty.cs
- ListViewEditEventArgs.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- DBBindings.cs
- Transform.cs
- SmtpTransport.cs
- LeafCellTreeNode.cs
- ResizeBehavior.cs
- SelectionHighlightInfo.cs
- SqlReferenceCollection.cs
- NamespaceList.cs
- ResourceDescriptionAttribute.cs
- COM2IManagedPerPropertyBrowsingHandler.cs
- ConfigXmlSignificantWhitespace.cs
- _ProxyChain.cs
- LambdaCompiler.Unary.cs
- XmlLanguageConverter.cs
- InstanceOwnerException.cs
- Registry.cs
- InitializationEventAttribute.cs
- _DigestClient.cs
- JapaneseLunisolarCalendar.cs
- MimeBasePart.cs
- ScriptServiceAttribute.cs
- SkinBuilder.cs
- DynamicDiscoveryDocument.cs
- StorageMappingItemCollection.cs
- ReflectionServiceProvider.cs
- RuleSettingsCollection.cs
- IsolatedStorageFilePermission.cs
- AmbientProperties.cs
- TreeViewImageIndexConverter.cs
- DesignerDataParameter.cs
- Parallel.cs
- HtmlForm.cs
- XmlUtil.cs
- DataServiceEntityAttribute.cs
- AbstractSvcMapFileLoader.cs
- MailAddressParser.cs
- ListViewContainer.cs
- MemberDomainMap.cs
- BamlVersionHeader.cs
- TabItemWrapperAutomationPeer.cs
- SynchronizationContext.cs
- SiblingIterators.cs
- AddressHeaderCollection.cs
- EntityDataSourceSelectedEventArgs.cs
- HtmlTextArea.cs
- ButtonChrome.cs
- RtfToken.cs
- WebSysDefaultValueAttribute.cs
- NotSupportedException.cs
- BooleanKeyFrameCollection.cs
- PasswordRecovery.cs
- QilSortKey.cs
- TableRowCollection.cs
- ConfigurationManagerInternalFactory.cs
- MatrixStack.cs
- Zone.cs
- InternalDispatchObject.cs
- MappableObjectManager.cs
- ColumnHeaderConverter.cs
- FieldNameLookup.cs
- HtmlToClrEventProxy.cs
- XPathNodeIterator.cs
- metrodevice.cs
- Transform.cs
- ParseNumbers.cs
- HideDisabledControlAdapter.cs
- ProtectedConfigurationSection.cs
- XmlSchemaSimpleContent.cs
- WorkflowControlClient.cs
- NullableBoolConverter.cs
- NamespaceDisplay.xaml.cs
- BamlLocalizabilityResolver.cs
- PrePrepareMethodAttribute.cs
- XPathConvert.cs
- IIS7WorkerRequest.cs
- ProjectionPlanCompiler.cs
- TableStyle.cs
- DragDropManager.cs
- SqlOuterApplyReducer.cs
- LayoutManager.cs
- SqlReferenceCollection.cs
- TextEditorDragDrop.cs
- SessionPageStateSection.cs
- EditorPart.cs
- PropertyItemInternal.cs
- safesecurityhelperavalon.cs
- MultiDataTrigger.cs
- WebEvents.cs
- ConnectionInterfaceCollection.cs
- FreezableOperations.cs
- Site.cs
- XPathDocumentNavigator.cs
- EdgeModeValidation.cs
- PropertyFilterAttribute.cs
- HwndHostAutomationPeer.cs