private void ValidateGuidDefaultValue(ScalarType scalar) { if (!scalar.TryParse(_default, out _defaultObject)) { _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultGuid(_default)); } }
private void ValidateIntegralDefaultValue(ScalarType scalar, long minValue, long maxValue) { if (!scalar.TryParse(_default, out _defaultObject)) { _element.AddError( ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultIntegral(_default, minValue, maxValue)); } }
private void ValidateDecimalDefaultValue(ScalarType scalar) { if (scalar.TryParse(_default, out _defaultObject)) { return; } _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDecimal(_default, 38, 38)); }
private void ValidateFloatingPointDefaultValue(ScalarType scalar, double minValue, double maxValue) { if (!scalar.TryParse(_default, out _defaultObject)) { _element.AddError( ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultFloatingPoint(_default, minValue, maxValue)); } }
private void ValidateDateTimeOffsetDefaultValue(ScalarType scalar) { if (!scalar.TryParse(_default, out _defaultObject)) { _element.AddError( ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDateTimeOffset( _default, ScalarType.DateTimeOffsetFormat.Replace(@"\", ""))); } }
private void ValidateBinaryDefaultValue(ScalarType scalar) { if (scalar.TryParse(_default, out _defaultObject)) { return; } var errorMessage = Strings.InvalidDefaultBinaryWithNoMaxLength(_default); _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, errorMessage); }
private void ValidateScalarMemberDefaultValue(ScalarType scalar) { Debug.Assert(_default != null); if (scalar != null) { switch (scalar.TypeKind) { case PrimitiveTypeKind.Binary: // required format 0xhexdegits, no more than 2*maxSize digits ValidateBinaryDefaultValue(scalar); return; case PrimitiveTypeKind.Boolean: // required true or false (case sensitive?) ValidateBooleanDefaultValue(scalar); return; case PrimitiveTypeKind.Byte: // integer between byte.MinValue and byteMaxValue; ValidateIntegralDefaultValue(scalar, byte.MinValue, byte.MaxValue); return; case PrimitiveTypeKind.DateTime: // valid datetime parsable using the format in _dateTimeFormat in the SqlDateTime range ValidateDateTimeDefaultValue(scalar); return; case PrimitiveTypeKind.Time: // valid time parsable using the format in _timeFormat in the SqlTime range ValidateTimeDefaultValue(scalar); return; case PrimitiveTypeKind.DateTimeOffset: // valid time parsable using the format in _datetimeoffsetFormat in the SqlDateTimeOffset range ValidateDateTimeOffsetDefaultValue(scalar); return; case PrimitiveTypeKind.Decimal: // valid decimal value (optionally with M) with scale and precision in range ValidateDecimalDefaultValue(scalar); return; case PrimitiveTypeKind.Double: // valid double constant ValidateFloatingPointDefaultValue(scalar, double.MinValue, double.MaxValue); return; case PrimitiveTypeKind.Guid: // valid string parsable by Guid.ctor ValidateGuidDefaultValue(scalar); return; case PrimitiveTypeKind.Int16: // integer between short.MinValue and short.MaxValue ValidateIntegralDefaultValue(scalar, short.MinValue, short.MaxValue); return; case PrimitiveTypeKind.Int32: // integer between int.MinValue and int.MaxValue ValidateIntegralDefaultValue(scalar, int.MinValue, int.MaxValue); return; case PrimitiveTypeKind.Int64: // integer between long.MinValue and long.MaxValue ValidateIntegralDefaultValue(scalar, long.MinValue, long.MaxValue); return; case PrimitiveTypeKind.Single: // valid single value ValidateFloatingPointDefaultValue(scalar, float.MinValue, float.MaxValue); return; case PrimitiveTypeKind.String: // the default is already a string, no parsing check necessary _defaultObject = _default; return; default: _element.AddError(ErrorCode.DefaultNotAllowed, EdmSchemaErrorSeverity.Error, Strings.DefaultNotAllowed); return; } } }
/// <summary> /// effects: adds errors to _element if there are any; creates a TypeUsage instance using the /// facet values aggregated by this builder and the given scalar type /// </summary> /// <param name="scalar"> Scalar type for the type usage </param> internal void ValidateAndSetTypeUsage(ScalarType scalar, bool complainOnMissingFacet) { Trace.Assert(_element != null); Trace.Assert(scalar != null); Dictionary <string, Facet> calculatedFacets; // Forward compat FUTURE SYSTEM.SPATIAL // for now we treat all Geographic types the same, and likewise for geometry. // to allow us to later introduce the full heirarchy without breaking back compat // we require spatial types to have the IsStrict facet with a false value. // Set this facet to false if the schema has the UseStrongSpatialTypes attribute with the a false. if (Helper.IsSpatialType(scalar.Type) && !_facetValues.ContainsKey(DbProviderManifest.IsStrictFacetName) && !_element.Schema.UseStrongSpatialTypes) { _facetValues.Add(DbProviderManifest.IsStrictFacetName, false /* only possible value */); } var noErrors = TryGetFacets(scalar.Type, complainOnMissingFacet, out calculatedFacets); if (noErrors) { // Only validate the values if there are no errros encountered in the above functions. // If there are errors encountered (like for e.g. precision switch (scalar.TypeKind) { case PrimitiveTypeKind.Binary: ValidateAndSetBinaryFacets(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.String: ValidateAndSetStringFacets(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.Decimal: ValidateAndSetDecimalFacets(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.DateTime: case PrimitiveTypeKind.Time: case PrimitiveTypeKind.DateTimeOffset: ValidatePrecisionFacetsForDateTimeFamily(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.Int16: case PrimitiveTypeKind.Int32: case PrimitiveTypeKind.Int64: case PrimitiveTypeKind.Boolean: case PrimitiveTypeKind.Byte: case PrimitiveTypeKind.SByte: case PrimitiveTypeKind.Double: case PrimitiveTypeKind.Guid: case PrimitiveTypeKind.Single: break; case PrimitiveTypeKind.Geography: case PrimitiveTypeKind.GeographyPoint: case PrimitiveTypeKind.GeographyLineString: case PrimitiveTypeKind.GeographyPolygon: case PrimitiveTypeKind.GeographyMultiPoint: case PrimitiveTypeKind.GeographyMultiLineString: case PrimitiveTypeKind.GeographyMultiPolygon: case PrimitiveTypeKind.GeographyCollection: case PrimitiveTypeKind.Geometry: case PrimitiveTypeKind.GeometryPoint: case PrimitiveTypeKind.GeometryLineString: case PrimitiveTypeKind.GeometryPolygon: case PrimitiveTypeKind.GeometryMultiPoint: case PrimitiveTypeKind.GeometryMultiLineString: case PrimitiveTypeKind.GeometryMultiPolygon: case PrimitiveTypeKind.GeometryCollection: ValidateSpatialFacets(scalar.Type, calculatedFacets); break; default: Debug.Fail("Did you miss a value"); break; } } _typeUsage = TypeUsage.Create(scalar.Type, calculatedFacets.Values); }
/// <summary> /// effects: adds errors to _element if there are any; creates a TypeUsage instance using the /// facet values aggregated by this builder and the given scalar type /// </summary> /// <param name="scalar"> Scalar type for the type usage </param> internal void ValidateAndSetTypeUsage(ScalarType scalar, bool complainOnMissingFacet) { Trace.Assert(_element != null); Trace.Assert(scalar != null); Dictionary<string, Facet> calculatedFacets; // Forward compat FUTURE SYSTEM.SPATIAL // for now we treat all Geographic types the same, and likewise for geometry. // to allow us to later introduce the full heirarchy without breaking back compat // we require spatial types to have the IsStrict facet with a false value. // Set this facet to false if the schema has the UseStrongSpatialTypes attribute with the a false. if (Helper.IsSpatialType(scalar.Type) && !_facetValues.ContainsKey(DbProviderManifest.IsStrictFacetName) && !_element.Schema.UseStrongSpatialTypes) { _facetValues.Add(DbProviderManifest.IsStrictFacetName, false /* only possible value */); } var noErrors = TryGetFacets(scalar.Type, complainOnMissingFacet, out calculatedFacets); if (noErrors) { // Only validate the values if there are no errros encountered in the above functions. // If there are errors encountered (like for e.g. precision switch (scalar.TypeKind) { case PrimitiveTypeKind.Binary: ValidateAndSetBinaryFacets(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.String: ValidateAndSetStringFacets(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.Decimal: ValidateAndSetDecimalFacets(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.DateTime: case PrimitiveTypeKind.Time: case PrimitiveTypeKind.DateTimeOffset: ValidatePrecisionFacetsForDateTimeFamily(scalar.Type, calculatedFacets); break; case PrimitiveTypeKind.Int16: case PrimitiveTypeKind.Int32: case PrimitiveTypeKind.Int64: case PrimitiveTypeKind.Boolean: case PrimitiveTypeKind.Byte: case PrimitiveTypeKind.SByte: case PrimitiveTypeKind.Double: case PrimitiveTypeKind.Guid: case PrimitiveTypeKind.Single: break; case PrimitiveTypeKind.Geography: case PrimitiveTypeKind.GeographyPoint: case PrimitiveTypeKind.GeographyLineString: case PrimitiveTypeKind.GeographyPolygon: case PrimitiveTypeKind.GeographyMultiPoint: case PrimitiveTypeKind.GeographyMultiLineString: case PrimitiveTypeKind.GeographyMultiPolygon: case PrimitiveTypeKind.GeographyCollection: case PrimitiveTypeKind.Geometry: case PrimitiveTypeKind.GeometryPoint: case PrimitiveTypeKind.GeometryLineString: case PrimitiveTypeKind.GeometryPolygon: case PrimitiveTypeKind.GeometryMultiPoint: case PrimitiveTypeKind.GeometryMultiLineString: case PrimitiveTypeKind.GeometryMultiPolygon: case PrimitiveTypeKind.GeometryCollection: ValidateSpatialFacets(scalar.Type, calculatedFacets); break; default: Debug.Fail("Did you miss a value"); break; } } _typeUsage = TypeUsage.Create(scalar.Type, calculatedFacets.Values); }
internal void ValidateAndSetTypeUsage(ScalarType scalar) { _typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false); }