public void Can_get_and_set_properties() { var parameterModel = new ParameterModel(PrimitiveTypeKind.Guid) { Name = "C", IsFixedLength = true, IsUnicode = true, MaxLength = 42, Precision = 23, Scale = 1, StoreType = "goobar" }; Assert.Equal("C", parameterModel.Name); Assert.Equal(PrimitiveTypeKind.Guid, parameterModel.Type); Assert.True(parameterModel.IsFixedLength.Value); Assert.True(parameterModel.IsUnicode.Value); Assert.Equal(42, parameterModel.MaxLength); Assert.Equal((byte)23, parameterModel.Precision); Assert.Equal((byte)1, parameterModel.Scale); Assert.Equal("goobar", parameterModel.StoreType); }
protected virtual string Generate(ParameterModel parameter) { var result = new StringBuilder(); result.Append(parameter.IsOutParameter ? "OUT" : "IN"); result.Append(" "); result.Append(Quote(parameter.Name)); result.Append(" "); result.Append(BuildPropertyType(parameter)); return result.ToString(); }
private static ParameterModel BuildParameter( PrimitiveTypeKind primitiveTypeKind, object defaultValue, string defaultValueSql = null, int? maxLength = null, byte? precision = null, byte? scale = null, bool? unicode = null, bool? fixedLength = null, string name = null, string storeType = null, bool outParameter = false) { var parameter = new ParameterModel(primitiveTypeKind) { MaxLength = maxLength, Precision = precision, Scale = scale, IsUnicode = unicode, IsFixedLength = fixedLength, DefaultValue = defaultValue, DefaultValueSql = defaultValueSql, Name = name, StoreType = storeType, IsOutParameter = outParameter }; return parameter; }
protected virtual void Generate(ParameterModel parameterModel, IndentedTextWriter writer, bool emitName = false) { Check.NotNull(parameterModel, "parameterModel"); Check.NotNull(writer, "writer"); writer.Write(" p."); writer.Write(TranslateColumnType(parameterModel.Type)); writer.Write("("); var args = new List<string>(); if (emitName) { args.Add("name := " + Quote(parameterModel.Name)); } if (parameterModel.MaxLength != null) { args.Add("maxLength := " + parameterModel.MaxLength); } if (parameterModel.Precision != null) { args.Add("precision := " + parameterModel.Precision); } if (parameterModel.Scale != null) { args.Add("scale := " + parameterModel.Scale); } if (parameterModel.IsFixedLength != null) { args.Add("fixedLength := " + parameterModel.IsFixedLength.ToString().ToLowerInvariant()); } if (parameterModel.IsUnicode != null) { args.Add("unicode := " + parameterModel.IsUnicode.ToString().ToLowerInvariant()); } if (parameterModel.DefaultValue != null) { args.Add("defaultValue := " + Generate((dynamic)parameterModel.DefaultValue)); } if (!string.IsNullOrWhiteSpace(parameterModel.DefaultValueSql)) { args.Add("defaultValueSql := " + Quote(parameterModel.DefaultValueSql)); } if (!string.IsNullOrWhiteSpace(parameterModel.StoreType)) { args.Add("storeType := " + Quote(parameterModel.StoreType)); } if (parameterModel.IsOutParameter) { args.Add("outParameter := True"); } writer.Write(args.Join()); writer.Write(")"); }
private void Generate(ParameterModel parameterModel, IndentedTextWriter writer) { DebugCheck.NotNull(parameterModel); DebugCheck.NotNull(writer); writer.Write("@"); writer.Write(parameterModel.Name); writer.Write(" "); writer.Write(BuildPropertyType(parameterModel)); if (parameterModel.IsOutParameter) { writer.Write(" OUT"); } if (parameterModel.DefaultValue != null) { writer.Write(" = "); writer.Write(Generate((dynamic)parameterModel.DefaultValue)); } else if (!string.IsNullOrWhiteSpace(parameterModel.DefaultValueSql)) { writer.Write(" = "); writer.Write(parameterModel.DefaultValueSql); } }
private string BuildParamType(ParameterModel param) { string type = MySqlProviderServices.Instance.GetColumnType(_providerManifest.GetStoreType(param.TypeUsage)); StringBuilder sb = new StringBuilder(); sb.Append(type); if (new string[] { "char", "varchar" }.Contains(type.ToLower())) { if (param.MaxLength.HasValue) { sb.AppendFormat("({0}) ", param.MaxLength.Value); } } if (param.Precision.HasValue && param.Scale.HasValue) { sb.AppendFormat("( {0}, {1} ) ", param.Precision.Value, param.Scale.Value); } return sb.ToString(); }
protected string Generate(ParameterModel parameter) { var builder = new StringBuilder(); builder.Append(Quote(parameter.Name)); builder.Append(" "); builder.Append(BuildPropertyType(parameter)); return builder.ToString(); }
private static ParameterModel BuildParameterModel( FunctionParameter functionParameter, ModelMetadata modelMetadata) { DebugCheck.NotNull(functionParameter); DebugCheck.NotNull(modelMetadata); var edmTypeUsage = functionParameter.TypeUsage.GetModelTypeUsage(); var defaultStoreTypeName = modelMetadata.ProviderManifest.GetStoreType(edmTypeUsage).EdmType.Name; var parameterModel = new ParameterModel(((PrimitiveType)edmTypeUsage.EdmType).PrimitiveTypeKind, edmTypeUsage) { Name = functionParameter.Name, IsOutParameter = functionParameter.Mode == ParameterMode.Out, StoreType = !functionParameter.TypeName.EqualsIgnoreCase(defaultStoreTypeName) ? functionParameter.TypeName : null }; Facet facet; if (edmTypeUsage.Facets.TryGetValue(DbProviderManifest.MaxLengthFacetName, true, out facet) && facet.Value != null) { parameterModel.MaxLength = facet.Value as int?; // could be MAX sentinel } if (edmTypeUsage.Facets.TryGetValue(DbProviderManifest.PrecisionFacetName, true, out facet) && facet.Value != null) { parameterModel.Precision = (byte?)facet.Value; } if (edmTypeUsage.Facets.TryGetValue(DbProviderManifest.ScaleFacetName, true, out facet) && facet.Value != null) { parameterModel.Scale = (byte?)facet.Value; } if (edmTypeUsage.Facets.TryGetValue(DbProviderManifest.FixedLengthFacetName, true, out facet) && facet.Value != null && (bool)facet.Value) { parameterModel.IsFixedLength = true; } if (edmTypeUsage.Facets.TryGetValue(DbProviderManifest.UnicodeFacetName, true, out facet) && facet.Value != null && !(bool)facet.Value) { parameterModel.IsUnicode = false; } return parameterModel; }