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.

92 lines
5.1 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace SqlSugar
  5. {
  6. public class MySqlDbBind : DbBindProvider
  7. {
  8. public override string GetDbTypeName(string csharpTypeName)
  9. {
  10. if (csharpTypeName == UtilConstants.ByteArrayType.Name)
  11. {
  12. return "blob";
  13. }
  14. if (csharpTypeName == "Int32")
  15. csharpTypeName = "int";
  16. if (csharpTypeName == "Int16")
  17. csharpTypeName = "short";
  18. if (csharpTypeName == "Int64")
  19. csharpTypeName = "long";
  20. if (csharpTypeName == "Boolean")
  21. csharpTypeName = "bool";
  22. var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
  23. return mappings.HasValue() ? mappings.First().Key : "varchar";
  24. }
  25. public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
  26. {
  27. get
  28. {
  29. var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
  30. if (extService != null && extService.AppendDataReaderTypeMappings.HasValue())
  31. {
  32. return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
  33. }
  34. else
  35. {
  36. return MappingTypesConst;
  37. }
  38. }
  39. }
  40. public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>{
  41. new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
  42. new KeyValuePair<string, CSharpDataType>("mediumint",CSharpDataType.@int),
  43. new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
  44. new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
  45. new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
  46. new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
  47. new KeyValuePair<string, CSharpDataType>("enum",CSharpDataType.@string),
  48. new KeyValuePair<string, CSharpDataType>("mediumtext",CSharpDataType.@string),
  49. new KeyValuePair<string, CSharpDataType>("tinytext",CSharpDataType.@string),
  50. new KeyValuePair<string, CSharpDataType>("longtext",CSharpDataType.@string),
  51. new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
  52. new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
  53. new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
  54. new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
  55. new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@double),
  56. new KeyValuePair<string, CSharpDataType>("double",CSharpDataType.@double),
  57. new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float),
  58. new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.Single),
  59. new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
  60. new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
  61. new KeyValuePair<string, CSharpDataType>("year",CSharpDataType.@int),
  62. new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
  63. new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
  64. new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
  65. new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
  66. new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
  67. new KeyValuePair<string, CSharpDataType>("tinyblob",CSharpDataType.byteArray),
  68. new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
  69. new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
  70. new KeyValuePair<string, CSharpDataType>("multipoint",CSharpDataType.byteArray),
  71. new KeyValuePair<string, CSharpDataType>("geometry",CSharpDataType.byteArray),
  72. new KeyValuePair<string, CSharpDataType>("multilinestring",CSharpDataType.byteArray),
  73. new KeyValuePair<string, CSharpDataType>("polygon",CSharpDataType.byteArray),
  74. new KeyValuePair<string, CSharpDataType>("mediumblob",CSharpDataType.byteArray),
  75. new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid),
  76. };
  77. public override List<string> StringThrow
  78. {
  79. get
  80. {
  81. return new List<string> { "int32", "datetime", "decimal", "double", "byte" };
  82. }
  83. }
  84. }
  85. }