public virtual DatabaseTypeRequest GetDataTypeRequestForSQLDBType(string sqlType) { var cSharpType = GetCSharpTypeForSQLDBType(sqlType); var digits = GetDigitsBeforeAndAfterDecimalPointIfDecimal(sqlType); int lengthIfString = GetLengthIfString(sqlType); //lengthIfString should still be populated even for digits etc because it might be that we have to fallback from "1.2" which is decimal(2,1) to varchar(3) if we see "F" appearing if (digits != null) { lengthIfString = Math.Max(lengthIfString, digits.ToStringLength()); } if (cSharpType == typeof(DateTime)) { lengthIfString = GetStringLengthForDateTime(); } if (cSharpType == typeof(TimeSpan)) { lengthIfString = GetStringLengthForTimeSpan(); } var request = new DatabaseTypeRequest(cSharpType, lengthIfString, digits); if (cSharpType == typeof(string)) { request.Unicode = IsUnicode(sqlType); } return(request); }
public string TranslateSQLDBType(string sqlType, ITypeTranslater destinationTypeTranslater) { //e.g. data_type is datetime2 (i.e. Sql Server), this returns System.DateTime DatabaseTypeRequest requested = GetDataTypeRequestForSQLDBType(sqlType); //this then returns datetime (e.g. mysql) return(destinationTypeTranslater.GetSQLDBTypeForCSharpType(requested)); }
/// <summary> /// Creates a new computer primed with the size of the given <paramref name="request"/>. /// </summary> /// <param name="request"></param> public DataTypeComputer(DatabaseTypeRequest request) : this(request.MaxWidthForStrings.HasValue? request.MaxWidthForStrings.Value:-1) { CurrentEstimate = request.CSharpType; if (request.DecimalPlacesBeforeAndAfter != null) { DecimalSize = request.DecimalPlacesBeforeAndAfter; } ThrowIfNotSupported(CurrentEstimate); }
public static DatabaseTypeRequest Max(DatabaseTypeRequest first, DatabaseTypeRequest second) { //if types differ if (PreferenceOrder.IndexOf(first.CSharpType) < PreferenceOrder.IndexOf(second.CSharpType)) { return(second); } if (PreferenceOrder.IndexOf(first.CSharpType) > PreferenceOrder.IndexOf(second.CSharpType)) { return(first); } if (!(first.CSharpType == second.CSharpType)) { throw new NotSupportedException("Cannot Max DatabaseTypeRequests because they were of differing Types and neither Type appeared in the PreferenceOrder (Types were '" + first.CSharpType + "' and '" + second.CSharpType + "')"); } int?newMaxWidthIfStrings = first.MaxWidthForStrings; //if first doesn't have a max string width if (newMaxWidthIfStrings == null) { newMaxWidthIfStrings = second.MaxWidthForStrings; //use the second } else if (second.MaxWidthForStrings != null) { newMaxWidthIfStrings = Math.Max(newMaxWidthIfStrings.Value, second.MaxWidthForStrings.Value); //else use the max of the two } //types are the same return(new DatabaseTypeRequest( first.CSharpType, newMaxWidthIfStrings, DecimalSize.Combine(first.DecimalPlacesBeforeAndAfter, second.DecimalPlacesBeforeAndAfter) )); }
protected bool Equals(DatabaseTypeRequest other) { return(Equals(CSharpType, other.CSharpType) && MaxWidthForStrings == other.MaxWidthForStrings && Equals(DecimalPlacesBeforeAndAfter, other.DecimalPlacesBeforeAndAfter)); }
/// <summary> /// Creates a new computer primed with the size of the given <paramref name="request"/>. Uses the provided /// <paramref name="extraLengthPerNonAsciiCharacter"/> /// </summary> /// <param name="request"></param> /// <param name="extraLengthPerNonAsciiCharacter"></param> public DataTypeComputer(DatabaseTypeRequest request, int extraLengthPerNonAsciiCharacter) : this(request) { ExtraLengthPerNonAsciiCharacter = extraLengthPerNonAsciiCharacter; }
public string GetSQLDBTypeForCSharpType(DatabaseTypeRequest request) { var t = request.CSharpType; if (t == typeof(bool) || t == typeof(bool?)) { return(GetBoolDataType()); } if (t == typeof(byte)) { return(GetByteDataType()); } if (t == typeof(short) || t == typeof(Int16) || t == typeof(ushort) || t == typeof(short?) || t == typeof(ushort?)) { return(GetSmallIntDataType()); } if (t == typeof(int) || t == typeof(Int32) || t == typeof(uint) || t == typeof(int?) || t == typeof(uint?)) { return(GetIntDataType()); } if (t == typeof(long) || t == typeof(ulong) || t == typeof(long?) || t == typeof(ulong?)) { return(GetBigIntDataType()); } if (t == typeof(float) || t == typeof(float?) || t == typeof(double) || t == typeof(double?) || t == typeof(decimal) || t == typeof(decimal?)) { return(GetFloatingPointDataType(request.Size)); } if (t == typeof(string)) { if (request.Unicode) { return(GetUnicodeStringDataType(request.Width)); } else { return(GetStringDataType(request.Width)); } } if (t == typeof(DateTime) || t == typeof(DateTime?)) { return(GetDateDateTimeDataType()); } if (t == typeof(TimeSpan) || t == typeof(TimeSpan?)) { return(GetTimeDataType()); } if (t == typeof(byte[])) { return(GetByteArrayDataType()); } if (t == typeof(Guid)) { return(GetGuidDataType()); } throw new TypeNotMappedException(string.Format(FAnsiStrings.TypeTranslater_GetSQLDBTypeForCSharpType_Unsure_what_SQL_type_to_use_for_CSharp_Type___0_____TypeTranslater_was___1__, t.Name, GetType().Name)); }
public string GetSQLDBTypeForCSharpType(DatabaseTypeRequest request) { var t = request.CSharpType; if (t == typeof(bool) || t == typeof(bool?)) { return(GetBoolDataType()); } if (t == typeof(byte)) { return(GetByteDataType()); } if (t == typeof(short) || t == typeof(Int16) || t == typeof(ushort) || t == typeof(short?) || t == typeof(ushort?)) { return(GetSmallIntDataType()); } if (t == typeof(int) || t == typeof(Int32) || t == typeof(uint) || t == typeof(int?) || t == typeof(uint?)) { return(GetIntDataType()); } if (t == typeof(long) || t == typeof(ulong) || t == typeof(long?) || t == typeof(ulong?)) { return(GetBigIntDataType()); } if (t == typeof(float) || t == typeof(float?) || t == typeof(double) || t == typeof(double?) || t == typeof(decimal) || t == typeof(decimal?)) { return(GetFloatingPointDataType(request.DecimalPlacesBeforeAndAfter)); } if (t == typeof(string)) { return(GetStringDataType(request.MaxWidthForStrings)); } if (t == typeof(DateTime) || t == typeof(DateTime?)) { return(GetDateDateTimeDataType()); } if (t == typeof(TimeSpan) || t == typeof(TimeSpan?)) { return(GetTimeDataType()); } if (t == typeof(byte[])) { return(GetByteArrayDataType()); } if (t == typeof(Guid)) { return(GetGuidDataType()); } throw new NotSupportedException("Unsure what SQL Database type to use for Property Type " + t.Name); }