You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
5.7 KiB

2 years ago
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace SqlSugar
  4. {
  5. public class OracleDbBind : DbBindProvider
  6. {
  7. public override string GetPropertyTypeName(string dbTypeName)
  8. {
  9. dbTypeName = dbTypeName.ToLower();
  10. var propertyTypes = MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName || it.Key.ToLower() == dbTypeName);
  11. if (dbTypeName == "int32")
  12. {
  13. return "int";
  14. }
  15. else if (dbTypeName == "int64")
  16. {
  17. return "long";
  18. }
  19. else if (dbTypeName == "int16")
  20. {
  21. return "short";
  22. }
  23. else if (propertyTypes == null)
  24. {
  25. return "other";
  26. }
  27. else if (dbTypeName == "xml" || dbTypeName == "string")
  28. {
  29. return "string";
  30. }
  31. if (dbTypeName == "byte[]")
  32. {
  33. return "byte[]";
  34. }
  35. else if (propertyTypes == null || propertyTypes.Count() == 0)
  36. {
  37. Check.ThrowNotSupportedException(string.Format(" \"{0}\" Type NotSupported, DbBindProvider.GetPropertyTypeName error.", dbTypeName));
  38. return null;
  39. }
  40. else if (propertyTypes.First().Value == CSharpDataType.byteArray)
  41. {
  42. return "byte[]";
  43. }
  44. else
  45. {
  46. return propertyTypes.First().Value.ToString();
  47. }
  48. }
  49. public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
  50. {
  51. get
  52. {
  53. var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
  54. if (extService != null && extService.AppendDataReaderTypeMappings.HasValue())
  55. {
  56. return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
  57. }
  58. else
  59. {
  60. return MappingTypesConst;
  61. }
  62. }
  63. }
  64. public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>
  65. {
  66. new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
  67. new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
  68. new KeyValuePair<string, CSharpDataType>("interval year to month",CSharpDataType.@int),
  69. new KeyValuePair<string, CSharpDataType>("interval day to second",CSharpDataType.@int),
  70. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@int),
  71. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@float),
  72. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@short),
  73. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@byte),
  74. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@double),
  75. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@long),
  76. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@bool),
  77. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@decimal),
  78. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.Single),
  79. new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
  80. new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.Single),
  81. new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
  82. new KeyValuePair<string, CSharpDataType>("varchar2",CSharpDataType.@string),
  83. new KeyValuePair<string, CSharpDataType>("nvarchar2",CSharpDataType.@string),
  84. new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
  85. new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string),
  86. new KeyValuePair<string, CSharpDataType>("clob",CSharpDataType.@string),
  87. new KeyValuePair<string, CSharpDataType>("long",CSharpDataType.@string),
  88. new KeyValuePair<string, CSharpDataType>("nclob",CSharpDataType.@string),
  89. new KeyValuePair<string, CSharpDataType>("rowid",CSharpDataType.@string),
  90. new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
  91. new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
  92. new KeyValuePair<string, CSharpDataType>("timestamp with local time zone",CSharpDataType.DateTime),
  93. new KeyValuePair<string, CSharpDataType>("timestamp with time zone",CSharpDataType.DateTime),
  94. new KeyValuePair<string, CSharpDataType>("timestamp with time zone",CSharpDataType.DateTime),
  95. new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@decimal),
  96. new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
  97. new KeyValuePair<string, CSharpDataType>("long raw",CSharpDataType.byteArray),
  98. new KeyValuePair<string, CSharpDataType>("raw",CSharpDataType.byteArray),
  99. new KeyValuePair<string, CSharpDataType>("bfile",CSharpDataType.byteArray),
  100. new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray) };
  101. public override List<string> StringThrow
  102. {
  103. get
  104. {
  105. return new List<string> { "int32", "datetime", "decimal", "double", "byte" };
  106. }
  107. }
  108. }
  109. }