Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 3 repositories · View In Graph Contained in tip and canonical

Added numericScale to ModificationField.

Changeset aafd23de47e1

Parent 2c87f5482a72

by Profile picture of William GrossWilliam Gross

Changes to 5 files · Browse files at aafd23de47e1 Showing diff from parent 2c87f5482a72 Diff from another changeset...

 
25
26
27
28
 
29
30
31
 
25
26
27
 
28
29
30
31
@@ -25,7 +25,7 @@
  var dbTypeString = cn.DatabaseInfo.GetDbTypeString( row[ "ProviderDbType" ] );   var allowsNull = (bool)row[ "IsNullable" ];   - valueContainer = new ValueContainer( name, dataType, dbTypeString, size, allowsNull, cn.DatabaseInfo ); + valueContainer = new ValueContainer( name, dataType, dbTypeString, size, null, allowsNull, cn.DatabaseInfo );   this.direction = direction;   }  
 
21
22
23
 
24
25
26
27
28
29
 
30
31
32
 
33
34
35
36
37
38
39
40
 
41
42
 
43
44
45
 
55
56
57
 
 
 
58
59
60
 
88
89
90
91
92
 
 
 
93
94
95
 
21
22
23
24
25
26
27
28
29
 
30
31
32
33
34
35
 
 
 
36
37
38
 
39
40
 
41
42
43
44
 
54
55
56
57
58
59
60
61
62
 
90
91
92
 
 
93
94
95
96
97
98
@@ -21,25 +21,24 @@
  private readonly string dbTypeString;     private readonly int size; + private readonly short? numericScale;   private readonly bool allowsNull;     // We'll remove this when we're ready to migrate Oracle systems to Pascal-cased column names.   private readonly string pascalCasedNameExceptForOracle;   - public ValueContainer( string name, Type dataType, string dbTypeString, int size, bool allowsNull, DatabaseInfo databaseInfo ) { + public ValueContainer( string name, Type dataType, string dbTypeString, int size, short? numericScale, bool allowsNull, DatabaseInfo databaseInfo ) {   this.name = name;   pascalCasedName = databaseInfo is OracleInfo ? name.OracleToEnglish().EnglishToPascal() : name;   pascalCasedNameExceptForOracle = databaseInfo is OracleInfo ? name : pascalCasedName; + nullValueExpression = databaseInfo is OracleInfo && new[] { "Clob", "NClob" }.Contains( dbTypeString ) ? "\"\"" : "";   unconvertedDataType = dataType; - this.dbTypeString = dbTypeString; - nullValueExpression = databaseInfo is OracleInfo && new[] { "Clob", "NClob" }.Contains( dbTypeString ) ? "\"\"" : ""; - this.size = size;     // MySQL LONGTEXT returns -1 for size.   if( databaseInfo is MySqlInfo && dbTypeString == "Text" && size == -1 ) - this.size = int.MaxValue; + size = int.MaxValue;   - if( databaseInfo is MySqlInfo && dbTypeString == "Bit" && this.size == 1 ) { + if( databaseInfo is MySqlInfo && dbTypeString == "Bit" && size == 1 ) {   if( unconvertedDataType != typeof( ulong ) )   throw new ApplicationException( "The unconverted data type was not ulong." );   @@ -55,6 +54,9 @@
  outgoingValueConversionExpressionGetter = valueExpression => valueExpression;   }   + this.dbTypeString = dbTypeString; + this.size = size; + this.numericScale = numericScale;   this.allowsNull = allowsNull;   }   @@ -88,8 +90,9 @@
  return incomingValueConverter( value );   }   - public int Size { get { return size; } } - public bool AllowsNull { get { return allowsNull; } } + public int Size => size; + public short? NumericScale => numericScale; + public bool AllowsNull => allowsNull;     public string GetParameterValueExpression( string valueExpression ) {   var conversionExpression = outgoingValueConversionExpressionGetter( valueExpression );
 
44
45
46
 
47
48
49
50
 
51
 
 
 
52
53
 
54
55
56
 
103
104
105
106
 
 
107
108
109
 
126
127
128
 
129
130
131
 
44
45
46
47
48
49
50
 
51
52
53
54
55
56
57
58
59
60
61
 
108
109
110
 
111
112
113
114
115
 
132
133
134
135
136
137
138
@@ -44,13 +44,18 @@
  if( databaseInfo is MySqlInfo )   ordinal -= 1;   + var dbTypeString = databaseInfo.GetDbTypeString( schemaTableRow[ "ProviderType" ] );   valueContainer = new ValueContainer(   (string)schemaTableRow[ "ColumnName" ],   (Type)schemaTableRow[ "DataType" ], - databaseInfo.GetDbTypeString( schemaTableRow[ "ProviderType" ] ), + dbTypeString,   (int)schemaTableRow[ "ColumnSize" ], + databaseInfo is SqlServerInfo && dbTypeString == "Decimal" ? (short)schemaTableRow[ "NumericScale" ] : + databaseInfo is MySqlInfo && dbTypeString == "NewDecimal" ? (short)(int)schemaTableRow[ "NumericScale" ] : + databaseInfo is OracleInfo && dbTypeString == "Decimal" ? (short)schemaTableRow[ "NumericScale" ] : (short?)null,   (bool)schemaTableRow[ "AllowDBNull" ],   databaseInfo ); +   isIdentity = ( databaseInfo is SqlServerInfo && (bool)schemaTableRow[ "IsIdentity" ] ) ||   ( databaseInfo is MySqlInfo && (bool)schemaTableRow[ "IsAutoIncrement" ] );   isRowVersion = databaseInfo is SqlServerInfo && (bool)schemaTableRow[ "IsRowVersion" ]; @@ -103,7 +108,8 @@
  }     internal string GetDataReaderValueExpression( string readerName, int? ordinalOverride = null ) { - var getValueExpression = valueContainer.GetIncomingValueConversionExpression( "{0}.GetValue( {1} )".FormatWith( readerName, ordinalOverride ?? ordinal ) ); + var getValueExpression = + valueContainer.GetIncomingValueConversionExpression( "{0}.GetValue( {1} )".FormatWith( readerName, ordinalOverride ?? ordinal ) );   return valueContainer.AllowsNull   ? "{0}.IsDBNull( {1} ) ? {2} : {3}".FormatWith(   readerName, @@ -126,6 +132,7 @@
  valueContainer.NullableDataTypeName,   "",   valueContainer.Size, + valueContainer.NumericScale,   privateFieldNameOverride: privateFieldName );   }   }
 
11
12
13
 
14
15
16
17
18
 
 
19
20
21
 
24
25
26
 
27
28
29
 
39
40
41
 
42
43
44
 
11
12
13
14
15
16
17
 
 
18
19
20
21
22
 
25
26
27
28
29
30
31
 
41
42
43
44
45
46
47
@@ -11,11 +11,12 @@
  private readonly string nullableTypeName;   private readonly string enumerableElementTypeName;   private readonly int? size; + private readonly short? numericScale;   private readonly string privateFieldNameOverride;     internal ModificationField( - string name, string pascalCasedName, string camelCasedName, Type type, string typeName, string nullableTypeName, string enumerableElementTypeName, int? size, - string privateFieldNameOverride = "" ) { + string name, string pascalCasedName, string camelCasedName, Type type, string typeName, string nullableTypeName, string enumerableElementTypeName, + int? size, short? numericScale, string privateFieldNameOverride = "" ) {   this.name = name;   this.pascalCasedName = pascalCasedName;   this.camelCasedName = camelCasedName; @@ -24,6 +25,7 @@
  this.nullableTypeName = nullableTypeName;   this.enumerableElementTypeName = enumerableElementTypeName;   this.size = size; + this.numericScale = numericScale;   this.privateFieldNameOverride = privateFieldNameOverride;   }   @@ -39,6 +41,7 @@
  internal string NullableTypeName => nullableTypeName;   internal string EnumerableElementTypeName => enumerableElementTypeName;   internal int? Size => size; + internal short? NumericScale => numericScale;     internal string PrivateFieldName => privateFieldNameOverride.Any() ? privateFieldNameOverride : camelCasedName;   }
 
38
39
40
41
 
 
42
43
44
 
60
61
62
63
64
 
 
 
65
66
67
 
131
132
133
134
 
135
136
137
 
 
38
39
40
 
41
42
43
44
45
 
61
62
63
 
 
64
65
66
67
68
69
 
133
134
135
 
136
137
138
139
 
@@ -38,7 +38,8 @@
  rawTypeNamesToTypes.Add( typeName, type );   }   - if( !isSupportedValueType( type ) && !isSupportedNullableType( type, isSupportedValueType ) && type != typeof( string ) && !isSupportedEnumerable( type ) ) + if( !isSupportedValueType( type ) && !isSupportedNullableType( type, isSupportedValueType ) && type != typeof( string ) && + !isSupportedEnumerable( type ) )   throw new UserCorrectableException( "The type \"" + typeName + "\" is not supported." );     normalizedTypeName = getNormalizedTypeName( type ); @@ -60,8 +61,9 @@
    private static bool isSupportedValueType( Type type ) {   return isSupportedIntegralType( type ) || new[] - { typeof( float ), typeof( double ), typeof( decimal ), typeof( bool ), typeof( DateTime ), typeof( DateTimeOffset ), typeof( TimeSpan ) }.Contains( - type ) || type.IsEnum; + { + typeof( float ), typeof( double ), typeof( decimal ), typeof( bool ), typeof( DateTime ), typeof( DateTimeOffset ), typeof( TimeSpan ) + }.Contains( type ) || type.IsEnum;   }     private static bool isSupportedIntegralType( Type type ) { @@ -131,7 +133,7 @@
  if( type.IsValueType && Nullable.GetUnderlyingType( type ) == null )   nullableTypeName += "?";   - return new ModificationField( PropertyName, PropertyName, name, type, normalizedTypeName, nullableTypeName, normalizedElementTypeName, null ); + return new ModificationField( PropertyName, PropertyName, name, type, normalizedTypeName, nullableTypeName, normalizedElementTypeName, null, null );   }   }  } \ No newline at end of file